mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-25 00:32:26 +00:00
Change tool_calls
to be an Option in response (#13778)
Here is an image of my now getting assistance responses! ![2024-07-03_08-45-37_swappy](https://github.com/zed-industries/zed/assets/20910163/904adc51-cb40-4622-878e-f679e0212426) I ended up adding a function to handle the use case of not serializing the tool_calls response if it is either null or empty to keep the functionality of the existing implementation (not deserializing if vec is empty). I'm sorta a noob, so happy to make changes if this isn't done correctly, although it does work and it does pass tests! Thanks a bunch to [amtoaer](https://github.com/amtoaer) for pointing me in the direction on how to fix it. Release Notes: - Fixed some responses being dropped from OpenAI-compatible providers ([#13741](https://github.com/zed-industries/zed/issues/13741)).
This commit is contained in:
parent
64755a7aea
commit
995b082c64
2 changed files with 7 additions and 2 deletions
|
@ -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)]
|
||||
|
|
Loading…
Reference in a new issue