openai: Don't append tool calls to prior assistant messages (#29969)

Closes https://github.com/zed-industries/zed/issues/29821

Release Notes:

- Fixed an issue in the agent panel where OpenAI requests would fail if
the assistant begins its response with a tool call.
This commit is contained in:
Max Brunsfeld 2025-05-05 22:04:56 -07:00 committed by GitHub
parent 55fd8352e4
commit 2eb10ab9fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -372,14 +372,10 @@ pub fn into_open_ai(
},
};
if let Some(last_assistant_message) = messages.iter_mut().rfind(|message| {
matches!(message, open_ai::RequestMessage::Assistant { .. })
}) {
if let open_ai::RequestMessage::Assistant { tool_calls, .. } =
last_assistant_message
{
tool_calls.push(tool_call);
}
if let Some(open_ai::RequestMessage::Assistant { tool_calls, .. }) =
messages.last_mut()
{
tool_calls.push(tool_call);
} else {
messages.push(open_ai::RequestMessage::Assistant {
content: None,