pub struct StructuredOutputChatModel<T> { /* private fields */ }Expand description
Wraps a ChatModel to produce structured JSON output.
Injects a system prompt instructing the model to respond with valid JSON matching a given schema description, then parses the response.
Implementations§
Source§impl<T: DeserializeOwned + Send + Sync + 'static> StructuredOutputChatModel<T>
impl<T: DeserializeOwned + Send + Sync + 'static> StructuredOutputChatModel<T>
Sourcepub fn new(
inner: Arc<dyn ChatModel>,
schema_description: impl Into<String>,
) -> Self
pub fn new( inner: Arc<dyn ChatModel>, schema_description: impl Into<String>, ) -> Self
Create a new StructuredOutputChatModel.
schema_description should describe the expected JSON shape, e.g.:
{"name": "string", "age": "number", "tags": ["string"]}
Sourcepub fn parse_response(
&self,
response: &ChatResponse,
) -> Result<T, SynapticError>
pub fn parse_response( &self, response: &ChatResponse, ) -> Result<T, SynapticError>
Parse the model’s text response as JSON into type T.
Sourcepub async fn generate(
&self,
request: ChatRequest,
) -> Result<(T, ChatResponse), SynapticError>
pub async fn generate( &self, request: ChatRequest, ) -> Result<(T, ChatResponse), SynapticError>
Call the model and parse the response as T.
Trait Implementations§
Source§impl<T: DeserializeOwned + Send + Sync + 'static> ChatModel for StructuredOutputChatModel<T>
impl<T: DeserializeOwned + Send + Sync + 'static> ChatModel for StructuredOutputChatModel<T>
fn chat<'life0, 'async_trait>(
&'life0 self,
request: ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse, SynapticError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stream_chat(&self, request: ChatRequest) -> ChatStream<'_>
Source§fn profile(&self) -> Option<ModelProfile>
fn profile(&self) -> Option<ModelProfile>
Return the model’s capability profile, if known.
Auto Trait Implementations§
impl<T> Freeze for StructuredOutputChatModel<T>
impl<T> !RefUnwindSafe for StructuredOutputChatModel<T>
impl<T> Send for StructuredOutputChatModel<T>where
T: Send,
impl<T> Sync for StructuredOutputChatModel<T>where
T: Sync,
impl<T> Unpin for StructuredOutputChatModel<T>where
T: Unpin,
impl<T> UnsafeUnpin for StructuredOutputChatModel<T>
impl<T> !UnwindSafe for StructuredOutputChatModel<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more