fix(openai): deserialize native tool specs with owned fields
This commit is contained in:
parent
4c249c579f
commit
6d745e9cb3
1 changed files with 16 additions and 16 deletions
|
|
@ -54,12 +54,12 @@ impl ResponseMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
struct NativeChatRequest<'a> {
|
struct NativeChatRequest {
|
||||||
model: String,
|
model: String,
|
||||||
messages: Vec<NativeMessage>,
|
messages: Vec<NativeMessage>,
|
||||||
temperature: f64,
|
temperature: f64,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
tools: Option<Vec<NativeToolSpec<'a>>>,
|
tools: Option<Vec<NativeToolSpec>>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
tool_choice: Option<String>,
|
tool_choice: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
@ -75,18 +75,18 @@ struct NativeMessage {
|
||||||
tool_calls: Option<Vec<NativeToolCall>>,
|
tool_calls: Option<Vec<NativeToolCall>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
struct NativeToolSpec<'a> {
|
struct NativeToolSpec {
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
kind: &'static str,
|
kind: String,
|
||||||
function: NativeToolFunctionSpec<'a>,
|
function: NativeToolFunctionSpec,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
struct NativeToolFunctionSpec<'a> {
|
struct NativeToolFunctionSpec {
|
||||||
name: &'a str,
|
name: String,
|
||||||
description: &'a str,
|
description: String,
|
||||||
parameters: &'a serde_json::Value,
|
parameters: serde_json::Value,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
|
@ -150,16 +150,16 @@ impl OpenAiProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_tools<'a>(tools: Option<&'a [ToolSpec]>) -> Option<Vec<NativeToolSpec<'a>>> {
|
fn convert_tools(tools: Option<&[ToolSpec]>) -> Option<Vec<NativeToolSpec>> {
|
||||||
tools.map(|items| {
|
tools.map(|items| {
|
||||||
items
|
items
|
||||||
.iter()
|
.iter()
|
||||||
.map(|tool| NativeToolSpec {
|
.map(|tool| NativeToolSpec {
|
||||||
kind: "function",
|
kind: "function".to_string(),
|
||||||
function: NativeToolFunctionSpec {
|
function: NativeToolFunctionSpec {
|
||||||
name: &tool.name,
|
name: tool.name.clone(),
|
||||||
description: &tool.description,
|
description: tool.description.clone(),
|
||||||
parameters: &tool.parameters,
|
parameters: tool.parameters.clone(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue