-
Notifications
You must be signed in to change notification settings - Fork 6k
Feat: Let providers configure a fast model for summarization #4228
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 2 commits
e501e3b
060bbdd
8b34e02
966e391
f95b13d
32256b0
e8cd8fc
3c3c376
bdb5583
352e0c5
ee5f40b
0c85d4d
3637a1a
5528a29
0447587
51bfa48
d3a5307
55aeedf
b666551
f6c2550
8cc66f1
4ec0d9b
bdbfcf4
7a5f390
1e6f164
395f434
a60b0fd
f996262
9e43de9
2f232f8
0cd4189
74a8359
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 |
|---|---|---|
|
|
@@ -28,6 +28,8 @@ use crate::providers::base::MessageStream; | |
| use crate::providers::formats::openai::response_to_streaming_message; | ||
| use rmcp::model::Tool; | ||
|
|
||
| const OPEN_AI_FAST_MODEL: &str = "gpt-4o-mini"; | ||
|
|
||
| pub const OPEN_AI_DEFAULT_MODEL: &str = "gpt-4o"; | ||
| pub const OPEN_AI_KNOWN_MODELS: &[(&str, usize)] = &[ | ||
| ("gpt-4o", 128_000), | ||
|
|
@@ -160,6 +162,31 @@ impl OpenAiProvider { | |
| .await?; | ||
| handle_response_openai_compat(response).await | ||
| } | ||
|
|
||
| // Core completion logic that takes a model config | ||
|
katzdave marked this conversation as resolved.
Outdated
|
||
| async fn complete_with_model( | ||
| &self, | ||
| model_config: &ModelConfig, | ||
| system: &str, | ||
| messages: &[Message], | ||
| tools: &[Tool], | ||
| ) -> Result<(Message, ProviderUsage), ProviderError> { | ||
| let payload = create_request(model_config, system, messages, tools, &ImageFormat::OpenAi)?; | ||
|
|
||
| let json_response = self.post(&payload).await?; | ||
|
|
||
| let message = response_to_message(&json_response)?; | ||
| let usage = json_response | ||
| .get("usage") | ||
| .map(get_usage) | ||
| .unwrap_or_else(|| { | ||
| tracing::debug!("Failed to get usage data"); | ||
| Usage::default() | ||
| }); | ||
| let model = get_model(&json_response); | ||
| emit_debug_trace(model_config, &payload, &json_response, &usage); | ||
| Ok((message, ProviderUsage::new(model, usage))) | ||
| } | ||
|
Collaborator
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 was previously existing, but now that we pass in the model, no need to fish it out of the json response
Contributor
Author
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. Got rid of it, but confused by this one since we already had the model name from before the request? |
||
| } | ||
|
|
||
| #[async_trait] | ||
|
|
@@ -202,21 +229,23 @@ impl Provider for OpenAiProvider { | |
| messages: &[Message], | ||
| tools: &[Tool], | ||
| ) -> Result<(Message, ProviderUsage), ProviderError> { | ||
| let payload = create_request(&self.model, system, messages, tools, &ImageFormat::OpenAi)?; | ||
| // Thin wrapper that calls complete_with_model with the configured model | ||
|
katzdave marked this conversation as resolved.
Outdated
|
||
| self.complete_with_model(&self.model, system, messages, tools) | ||
| .await | ||
| } | ||
|
|
||
| let json_response = self.post(&payload).await?; | ||
| async fn complete_fast( | ||
| &self, | ||
|
katzdave marked this conversation as resolved.
Outdated
|
||
| system: &str, | ||
| messages: &[Message], | ||
| tools: &[Tool], | ||
| ) -> Result<(Message, ProviderUsage), ProviderError> { | ||
| // Use the fast model (gpt-4o-mini) for fast completions | ||
| let mut fast_config = self.model.clone(); | ||
| fast_config.model_name = OPEN_AI_FAST_MODEL.to_string(); | ||
|
Collaborator
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. make this a method on config - config.for_fast_model() should return a copy of itself with the model_name swapped out for the smart model if that is available
Contributor
Author
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. done |
||
|
|
||
| let message = response_to_message(&json_response)?; | ||
| let usage = json_response | ||
| .get("usage") | ||
| .map(get_usage) | ||
| .unwrap_or_else(|| { | ||
| tracing::debug!("Failed to get usage data"); | ||
| Usage::default() | ||
| }); | ||
| let model = get_model(&json_response); | ||
| emit_debug_trace(&self.model, &payload, &json_response, &usage); | ||
| Ok((message, ProviderUsage::new(model, usage))) | ||
| self.complete_with_model(&fast_config, system, messages, tools) | ||
| .await | ||
| } | ||
|
|
||
| async fn fetch_supported_models(&self) -> Result<Option<Vec<String>>, ProviderError> { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.