@@ -4462,6 +4462,7 @@ async fn complete_with_open_ai(
tool_calls: choice
.delta
.tool_calls
+ .unwrap_or_default()
.into_iter()
.map(|delta| proto::ToolCallDelta {
index: delta.index as u32,
@@ -9,6 +9,10 @@ use strum::EnumIter;
pub const OPEN_AI_API_URL: &str = "https://api.openai.com/v1";
+fn is_none_or_empty<T: AsRef<[U]>, U>(opt: &Option<T>) -> bool {
+ opt.as_ref().map_or(true, |v| v.as_ref().is_empty())
+}
+
#[derive(Clone, Copy, Serialize, Deserialize, Debug, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum Role {
@@ -182,8 +186,8 @@ pub struct FunctionContent {
pub struct ResponseMessageDelta {
pub role: Option<Role>,
pub content: Option<String>,
- #[serde(default, skip_serializing_if = "Vec::is_empty")]
- pub tool_calls: Vec<ToolCallChunk>,
+ #[serde(default, skip_serializing_if = "is_none_or_empty")]
+ pub tool_calls: Option<Vec<ToolCallChunk>>,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]