mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
ollama: default to Responses API for built-ins (#8798)
This is an alternate PR to solving the same problem as <https://github.com/openai/codex/pull/8227>. In this PR, when Ollama is used via `--oss` (or via `model_provider = "ollama"`), we default it to use the Responses format. At runtime, we do an Ollama version check, and if the version is older than when Responses support was added to Ollama, we print out a warning. Because there's no way of configuring the wire api for a built-in provider, we temporarily add a new `oss_provider`/`model_provider` called `"ollama-chat"` that will force the chat format. Once the `"chat"` format is fully removed (see <https://github.com/openai/codex/discussions/7782>), `ollama-chat` can be removed as well --------- Co-authored-by: Eric Traut <etraut@openai.com> Co-authored-by: Michael Bolin <mbolin@openai.com>
This commit is contained in:
co-authored by
Eric Traut
Michael Bolin
parent
2d56519ecd
commit
fe03320791
@@ -35,6 +35,7 @@ use codex_core::features::Feature;
|
||||
use codex_core::models_manager::manager::ModelsManager;
|
||||
use codex_core::models_manager::model_presets::HIDE_GPT_5_1_CODEX_MAX_MIGRATION_PROMPT_CONFIG;
|
||||
use codex_core::models_manager::model_presets::HIDE_GPT5_1_MIGRATION_PROMPT_CONFIG;
|
||||
use codex_core::protocol::DeprecationNoticeEvent;
|
||||
use codex_core::protocol::EventMsg;
|
||||
use codex_core::protocol::FinalOutput;
|
||||
use codex_core::protocol::ListSkillsResponseEvent;
|
||||
@@ -121,6 +122,15 @@ fn emit_skill_load_warnings(app_event_tx: &AppEventSender, errors: &[SkillErrorI
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_deprecation_notice(app_event_tx: &AppEventSender, notice: Option<DeprecationNoticeEvent>) {
|
||||
let Some(DeprecationNoticeEvent { summary, details }) = notice else {
|
||||
return;
|
||||
};
|
||||
app_event_tx.send(AppEvent::InsertHistoryCell(Box::new(
|
||||
crate::history_cell::new_deprecation_notice(summary, details),
|
||||
)));
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
struct SessionSummary {
|
||||
usage_line: String,
|
||||
@@ -345,10 +355,12 @@ impl App {
|
||||
session_selection: SessionSelection,
|
||||
feedback: codex_feedback::CodexFeedback,
|
||||
is_first_run: bool,
|
||||
ollama_chat_support_notice: Option<DeprecationNoticeEvent>,
|
||||
) -> Result<AppExitInfo> {
|
||||
use tokio_stream::StreamExt;
|
||||
let (app_event_tx, mut app_event_rx) = unbounded_channel();
|
||||
let app_event_tx = AppEventSender::new(app_event_tx);
|
||||
emit_deprecation_notice(&app_event_tx, ollama_chat_support_notice);
|
||||
|
||||
let thread_manager = Arc::new(ThreadManager::new(
|
||||
config.codex_home.clone(),
|
||||
|
||||
@@ -58,7 +58,7 @@ pub struct Cli {
|
||||
#[arg(long = "oss", default_value_t = false)]
|
||||
pub oss: bool,
|
||||
|
||||
/// Specify which local provider to use (lmstudio or ollama).
|
||||
/// Specify which local provider to use (lmstudio, ollama, or ollama-chat).
|
||||
/// If not specified with --oss, will use config default or show selection.
|
||||
#[arg(long = "local-provider")]
|
||||
pub oss_provider: Option<String>,
|
||||
|
||||
@@ -9,6 +9,7 @@ pub use app::AppExitInfo;
|
||||
use codex_app_server_protocol::AuthMode;
|
||||
use codex_common::oss::ensure_oss_provider_ready;
|
||||
use codex_common::oss::get_default_model_for_oss_provider;
|
||||
use codex_common::oss::ollama_chat_deprecation_notice;
|
||||
use codex_core::AuthManager;
|
||||
use codex_core::CodexAuth;
|
||||
use codex_core::INTERACTIVE_SESSION_SOURCES;
|
||||
@@ -431,6 +432,13 @@ async fn run_ratatui_app(
|
||||
initial_config
|
||||
};
|
||||
|
||||
let ollama_chat_support_notice = match ollama_chat_deprecation_notice(&config).await {
|
||||
Ok(notice) => notice,
|
||||
Err(err) => {
|
||||
tracing::warn!(?err, "Failed to detect Ollama wire API");
|
||||
None
|
||||
}
|
||||
};
|
||||
let mut missing_session_exit = |id_str: &str, action: &str| {
|
||||
error!("Error finding conversation path: {id_str}");
|
||||
restore();
|
||||
@@ -566,6 +574,7 @@ async fn run_ratatui_app(
|
||||
session_selection,
|
||||
feedback,
|
||||
should_show_trust_screen, // Proxy to: is it a first run in this directory?
|
||||
ollama_chat_support_notice,
|
||||
)
|
||||
.await;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ use std::sync::LazyLock;
|
||||
use codex_core::DEFAULT_LMSTUDIO_PORT;
|
||||
use codex_core::DEFAULT_OLLAMA_PORT;
|
||||
use codex_core::LMSTUDIO_OSS_PROVIDER_ID;
|
||||
use codex_core::OLLAMA_CHAT_PROVIDER_ID;
|
||||
use codex_core::OLLAMA_OSS_PROVIDER_ID;
|
||||
use codex_core::config::set_default_oss_provider;
|
||||
use crossterm::event::Event;
|
||||
@@ -70,10 +71,16 @@ static OSS_SELECT_OPTIONS: LazyLock<Vec<SelectOption>> = LazyLock::new(|| {
|
||||
},
|
||||
SelectOption {
|
||||
label: Line::from(vec!["O".underlined(), "llama".into()]),
|
||||
description: "Local Ollama server (default port 11434)",
|
||||
description: "Local Ollama server (Responses API, default port 11434)",
|
||||
key: KeyCode::Char('o'),
|
||||
provider_id: OLLAMA_OSS_PROVIDER_ID,
|
||||
},
|
||||
SelectOption {
|
||||
label: Line::from(vec!["Ollama (".into(), "c".underlined(), "hat)".into()]),
|
||||
description: "Local Ollama server (chat wire API, default port 11434)",
|
||||
key: KeyCode::Char('c'),
|
||||
provider_id: OLLAMA_CHAT_PROVIDER_ID,
|
||||
},
|
||||
]
|
||||
});
|
||||
|
||||
@@ -99,7 +106,11 @@ impl OssSelectionWidget<'_> {
|
||||
status: lmstudio_status,
|
||||
},
|
||||
ProviderOption {
|
||||
name: "Ollama".to_string(),
|
||||
name: "Ollama (Responses)".to_string(),
|
||||
status: ollama_status.clone(),
|
||||
},
|
||||
ProviderOption {
|
||||
name: "Ollama (Chat)".to_string(),
|
||||
status: ollama_status,
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user