Skip to content

Commit

Permalink
feat: Working JSON reponses!
Browse files Browse the repository at this point in the history
  • Loading branch information
Butch78 committed Dec 12, 2023
1 parent ed4297c commit 3f3a4dd
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions orca-core/src/llm/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct Payload {
stop: Option<Vec<String>>,
messages: Vec<Message>,
stream: bool,
response_format: ResponseFormat,
response_format: ResponseFormatWrapper,
}

#[derive(Serialize, Deserialize, Debug)]
Expand All @@ -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,
Expand Down Expand Up @@ -105,6 +111,12 @@ pub enum ResponseFormat {
JsonObject,
}

impl From<ResponseFormat> for ResponseFormatWrapper {
fn from(format: ResponseFormat) -> Self {
ResponseFormatWrapper { format }
}
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Choice {
index: i32,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}}
"#
Expand Down

0 comments on commit 3f3a4dd

Please sign in to comment.