-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix: gemini models via databricks #8042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
49f99c3
852929d
71a7300
e5fbf1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,9 +48,25 @@ struct DeltaToolCall { | |
| extra: Option<serde_json::Map<String, Value>>, | ||
| } | ||
|
|
||
| #[derive(Serialize, Deserialize, Debug)] | ||
| #[serde(untagged)] | ||
| enum DeltaContent { | ||
| String(String), | ||
| Array(Vec<ContentPart>), | ||
| } | ||
|
|
||
| #[derive(Serialize, Deserialize, Debug)] | ||
| struct ContentPart { | ||
| r#type: String, | ||
| text: String, | ||
| #[serde(rename = "thoughtSignature")] | ||
| thought_signature: Option<String>, | ||
| } | ||
|
|
||
| #[derive(Serialize, Deserialize, Debug)] | ||
| struct Delta { | ||
| content: Option<String>, | ||
| #[serde(default)] | ||
| content: Option<DeltaContent>, | ||
| role: Option<String>, | ||
| tool_calls: Option<Vec<DeltaToolCall>>, | ||
| reasoning_details: Option<Vec<Value>>, | ||
|
|
@@ -74,6 +90,32 @@ struct StreamingChunk { | |
| model: Option<String>, | ||
| } | ||
|
|
||
| fn extract_content_and_signature( | ||
| delta_content: Option<&DeltaContent>, | ||
| ) -> (Option<String>, Option<String>) { | ||
| match delta_content { | ||
| Some(DeltaContent::String(s)) => (Some(s.clone()), None), | ||
| Some(DeltaContent::Array(parts)) => { | ||
| let text_parts: Vec<_> = parts.iter().filter(|p| p.r#type == "text").collect(); | ||
|
|
||
| let text = text_parts | ||
| .iter() | ||
| .map(|p| p.text.as_str()) | ||
| .collect::<String>(); | ||
|
Comment on lines
+99
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Gemini's OpenAI-compatible chat completions support Useful? React with πΒ / π. |
||
|
|
||
| let signature = text_parts | ||
| .iter() | ||
| .find_map(|p| p.thought_signature.as_ref()) | ||
|
Comment on lines
+106
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Gemini 3 places the continuation signature on the last part of a non-function response, but Useful? React with πΒ / π. |
||
| .cloned(); | ||
|
|
||
| let text = if text.is_empty() { None } else { Some(text) }; | ||
|
|
||
| (text, signature) | ||
| } | ||
| None => (None, None), | ||
| } | ||
| } | ||
|
|
||
| pub fn format_messages(messages: &[Message], image_format: &ImageFormat) -> Vec<Value> { | ||
| let mut messages_spec = Vec::new(); | ||
| for message in messages { | ||
|
|
@@ -735,9 +777,11 @@ where | |
| } | ||
| } | ||
|
|
||
| if let Some(text) = &chunk.choices[0].delta.content { | ||
| let (text_content, _thought_signature) = extract_content_and_signature(chunk.choices[0].delta.content.as_ref()); | ||
|
||
|
|
||
| if let Some(text) = text_content { | ||
| if !text.is_empty() { | ||
| content.push(MessageContent::text(text)); | ||
| content.push(MessageContent::text(&text)); | ||
|
Comment on lines
+791
to
+799
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Databricks/Gemini chunks on this new Useful? React with πΒ / π. |
||
| } | ||
|
Comment on lines
+797
to
800
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This branch updates Useful? React with πΒ / π. |
||
| } | ||
|
|
||
|
|
@@ -748,7 +792,6 @@ where | |
| content, | ||
| ); | ||
|
|
||
| // Add ID if present | ||
| if let Some(id) = chunk.id { | ||
| msg = msg.with_id(id); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
supports_stream_options()keys offmodel_config.model_name, but in this provider that value is the Databricks serving endpoint name:get_endpoint_path()interpolates it directly into/serving-endpoints/{name}/invocations, andfetch_supported_models()returnsendpoint.name. In deployments where a Gemini-backed endpoint is aliased to something likeprod-chatorassistant-v1, this predicate staystrue, Goose still sendsstream_options, and the request reproduces the same 400INVALID_ARGUMENTthis patch is meant to eliminate.Useful? React with πΒ / π.