Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/backends/openai/responses/request/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ fn sample_tool() -> Tool {
description: "Get weather".to_string(),
parameters: json!({"type": "object"}),
},
cache_control: None,
}
}

Expand Down
25 changes: 19 additions & 6 deletions src/providers/openai_compatible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ pub struct OpenAIResponseFormat {
pub response_type: OpenAIResponseType,
#[serde(skip_serializing_if = "Option::is_none")]
pub json_schema: Option<StructuredOutputFormat>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub schema: Option<serde_json::Value>,
}

#[derive(Deserialize, Debug, Serialize)]
Expand Down Expand Up @@ -260,25 +264,34 @@ pub struct StreamFunctionCall {
impl From<StructuredOutputFormat> for OpenAIResponseFormat {
fn from(structured_response_format: StructuredOutputFormat) -> Self {
match structured_response_format.schema {
None => OpenAIResponseFormat {
response_type: OpenAIResponseType::JsonSchema,
json_schema: Some(structured_response_format),
},
None => {
let name = structured_response_format.name.clone();
let schema = structured_response_format.schema.clone();
OpenAIResponseFormat {
response_type: OpenAIResponseType::JsonSchema,
json_schema: Some(structured_response_format),
schema: schema,
name: Some(name),
}
}
Some(mut schema) => {
schema = if schema.get("additionalProperties").is_none() {
schema["additionalProperties"] = serde_json::json!(false);
schema
} else {
schema
};
let name = structured_response_format.name;
OpenAIResponseFormat {
response_type: OpenAIResponseType::JsonSchema,
schema: Some(schema.clone()),
json_schema: Some(StructuredOutputFormat {
name: structured_response_format.name,
description: structured_response_format.description,
name: name.clone(),
schema: Some(schema),
strict: structured_response_format.strict,
description: structured_response_format.description,
}),
name: Some(name),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ mod bedrock_tests {
},
"required": ["location"]
}),
cache_control: None,
}];

let messages = vec![ChatMessage::user("What's the weather in San Francisco?")];
Expand Down Expand Up @@ -330,6 +331,7 @@ mod bedrock_tests {
},
"required": ["expression"]
}),
cache_control: None,
}];

// First request to get tool use
Expand Down Expand Up @@ -664,6 +666,7 @@ mod bedrock_tests {
name: "test_tool".to_string(),
description: "A test tool".to_string(),
input_schema: json!({"type": "object"}),
cache_control: None,
}];

let messages = vec![ChatMessage::user("Use the tool")];
Expand Down