use crate::ChatMessage;
use crate::chat::ToolDef;
use serde::Serialize;
#[derive(Debug, Serialize)]
pub(super) struct OpenAiToolWire<'a> {
#[serde(rename = "type")]
pub(super) kind: &'static str,
pub(super) function: OpenAiFunctionWire<'a>,
}
#[derive(Debug, Serialize)]
pub(super) struct OpenAiFunctionWire<'a> {
pub(super) name: &'a str,
pub(super) description: &'a str,
pub(super) parameters: &'a serde_json::Value,
}
#[derive(Debug, Serialize)]
pub(super) struct ChatRequestWire<'a> {
pub(super) model: &'a str,
pub(super) messages: &'a [ChatMessage],
pub(super) stream: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub(super) tools: Option<Vec<OpenAiToolWire<'a>>>,
}
pub(super) fn tools_wire(tools: &[ToolDef]) -> Option<Vec<OpenAiToolWire<'_>>> {
if tools.is_empty() {
None
} else {
Some(
tools
.iter()
.map(|t| OpenAiToolWire {
kind: "function",
function: OpenAiFunctionWire {
name: &t.name,
description: &t.description,
parameters: &t.parameters,
},
})
.collect(),
)
}
}