From 3f3a4dd4713a7dc1c0c7107943dc266334a797c8 Mon Sep 17 00:00:00 2001 From: Butch78 Date: Tue, 12 Dec 2023 21:14:49 +0000 Subject: [PATCH] feat: Working JSON reponses! --- orca-core/src/llm/openai.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/orca-core/src/llm/openai.rs b/orca-core/src/llm/openai.rs index 4134317..96ac396 100644 --- a/orca-core/src/llm/openai.rs +++ b/orca-core/src/llm/openai.rs @@ -21,7 +21,7 @@ pub struct Payload { stop: Option>, messages: Vec, stream: bool, - response_format: ResponseFormat, + response_format: ResponseFormatWrapper, } #[derive(Serialize, Deserialize, Debug)] @@ -30,6 +30,12 @@ pub struct EmbeddingPayload { model: String, } +#[derive(Debug, Serialize, Deserialize)] +pub struct ResponseFormatWrapper { + #[serde(rename = "type")] + pub format: ResponseFormat, +} + #[derive(Serialize, Deserialize, Debug)] pub struct Response { id: String, @@ -105,6 +111,12 @@ pub enum ResponseFormat { JsonObject, } +impl From for ResponseFormatWrapper { + fn from(format: ResponseFormat) -> Self { + ResponseFormatWrapper { format } + } +} + #[derive(Serialize, Deserialize, Debug)] pub struct Choice { index: i32, @@ -243,7 +255,7 @@ impl OpenAI { stop: None, messages: messages.to_vec(), stream: self.stream, - response_format: self.response_format.clone(), + response_format: self.response_format.clone().into(), }; let req = self .client @@ -420,7 +432,7 @@ mod test { Paris {{/assistant}} {{#user}} - What is the capital of {{country2}}? + What is the capital of {{country2}} in a JSON format? {{/user}} {{/chat}} "#