-
Notifications
You must be signed in to change notification settings - Fork 7.6k
ollama_oss: default WireApi to Responses, fall back to Chat #8227
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 all commits
c4bcc53
d6d0347
3f183b6
18807ce
013c289
1473fa4
f0ea623
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -273,7 +273,7 @@ pub fn built_in_model_providers() -> HashMap<String, ModelProviderInfo> { | |
| ("openai", P::create_openai_provider()), | ||
| ( | ||
| OLLAMA_OSS_PROVIDER_ID, | ||
| create_oss_provider(DEFAULT_OLLAMA_PORT, WireApi::Chat), | ||
| create_oss_provider(DEFAULT_OLLAMA_PORT, WireApi::Responses), | ||
| ), | ||
|
Comment on lines
273
to
277
Contributor
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.
Switching the built‑in Ollama provider default to Useful? React with 👍 / 👎. |
||
| ( | ||
| LMSTUDIO_OSS_PROVIDER_ID, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,15 +4,23 @@ mod pull; | |||||||||||||||
| mod url; | ||||||||||||||||
|
|
||||||||||||||||
| pub use client::OllamaClient; | ||||||||||||||||
| use codex_core::ModelProviderInfo; | ||||||||||||||||
| use codex_core::WireApi; | ||||||||||||||||
| use codex_core::config::Config; | ||||||||||||||||
| pub use pull::CliProgressReporter; | ||||||||||||||||
| pub use pull::PullEvent; | ||||||||||||||||
| pub use pull::PullProgressReporter; | ||||||||||||||||
| pub use pull::TuiProgressReporter; | ||||||||||||||||
| use semver::Version; | ||||||||||||||||
|
|
||||||||||||||||
| /// Default OSS model to use when `--oss` is passed without an explicit `-m`. | ||||||||||||||||
| pub const DEFAULT_OSS_MODEL: &str = "gpt-oss:20b"; | ||||||||||||||||
|
|
||||||||||||||||
| pub struct WireApiDetection { | ||||||||||||||||
| pub wire_api: WireApi, | ||||||||||||||||
| pub version: Option<Version>, | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /// Prepare the local OSS environment when `--oss` is selected. | ||||||||||||||||
| /// | ||||||||||||||||
| /// - Ensures a local Ollama server is reachable. | ||||||||||||||||
|
|
@@ -45,3 +53,67 @@ pub async fn ensure_oss_ready(config: &Config) -> std::io::Result<()> { | |||||||||||||||
|
|
||||||||||||||||
| Ok(()) | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| fn min_responses_version() -> Version { | ||||||||||||||||
| Version::new(0, 13, 4) | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| fn wire_api_for_version(version: &Version) -> WireApi { | ||||||||||||||||
| if *version == Version::new(0, 0, 0) { | ||||||||||||||||
| return WireApi::Responses; | ||||||||||||||||
| } | ||||||||||||||||
| if *version >= min_responses_version() { | ||||||||||||||||
|
Comment on lines
+62
to
+65
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.
Suggested change
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. Though this should probably be combined with |
||||||||||||||||
| WireApi::Responses | ||||||||||||||||
| } else { | ||||||||||||||||
| WireApi::Chat | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /// Detect which wire API the running Ollama server supports based on its version. | ||||||||||||||||
| /// Returns `Ok(None)` when the version endpoint is missing or unparsable; callers | ||||||||||||||||
| /// should keep the configured default in that case. | ||||||||||||||||
| pub async fn detect_wire_api( | ||||||||||||||||
| provider: &ModelProviderInfo, | ||||||||||||||||
| ) -> std::io::Result<Option<WireApiDetection>> { | ||||||||||||||||
| let client = crate::OllamaClient::try_from_provider(provider).await?; | ||||||||||||||||
| let Some(version) = client.fetch_version().await? else { | ||||||||||||||||
| return Ok(None); | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| let wire_api = wire_api_for_version(&version); | ||||||||||||||||
|
|
||||||||||||||||
| Ok(Some(WireApiDetection { | ||||||||||||||||
| wire_api, | ||||||||||||||||
| version: Some(version), | ||||||||||||||||
| })) | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| #[cfg(test)] | ||||||||||||||||
| mod tests { | ||||||||||||||||
| use super::*; | ||||||||||||||||
|
|
||||||||||||||||
| #[test] | ||||||||||||||||
| fn test_wire_api_for_version_dev_zero_keeps_responses() { | ||||||||||||||||
| assert_eq!( | ||||||||||||||||
| wire_api_for_version(&Version::new(0, 0, 0)), | ||||||||||||||||
| WireApi::Responses | ||||||||||||||||
| ); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| #[test] | ||||||||||||||||
| fn test_wire_api_for_version_before_cutoff_is_chat() { | ||||||||||||||||
| assert_eq!(wire_api_for_version(&Version::new(0, 13, 3)), WireApi::Chat); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| #[test] | ||||||||||||||||
| fn test_wire_api_for_version_at_or_after_cutoff_is_responses() { | ||||||||||||||||
| assert_eq!( | ||||||||||||||||
| wire_api_for_version(&Version::new(0, 13, 4)), | ||||||||||||||||
| WireApi::Responses | ||||||||||||||||
| ); | ||||||||||||||||
| assert_eq!( | ||||||||||||||||
| wire_api_for_version(&Version::new(0, 14, 0)), | ||||||||||||||||
| WireApi::Responses | ||||||||||||||||
| ); | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.