Skip to content

Commit 7191b51

Browse files
committed
Add support for Ollama provider
The OpenAI compatible model doesn't work with Ollama. Add another provider for it. The code there was generated from a prompt to modify src/ai/openai.rs to use an Ollama-compatible API. Assisted-by: qwen2.6_claude_27B Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent 00d4a11 commit 7191b51

5 files changed

Lines changed: 804 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ tracing = "0.1.44"
6464
tracing-subscriber = { version = "0.3.22", features = ["env-filter"] }
6565
tree-sitter = "0.26.9"
6666
tree-sitter-c = "0.24.2"
67+
uuid = "1.23.4"

src/ai/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ pub fn classify_ai_error(error: &anyhow::Error) -> AiErrorClass {
289289
if let Some(e) = error.downcast_ref::<crate::worker::prompts::ReviewError>() {
290290
return e.ai_error_class();
291291
}
292+
if let Some(e) = error.downcast_ref::<ollama::OllamaError>() {
293+
return e.ai_error_class();
294+
}
292295
AiErrorClass::Fatal
293296
}
294297

@@ -472,6 +475,19 @@ pub fn create_provider_from_ai(ai: &AiSettings) -> Result<Arc<dyn AiProvider>> {
472475

473476
Ok(Arc::new(provider))
474477
}
478+
"ollama" => {
479+
let model = ai.model.clone();
480+
let base_url = ai
481+
.ollama
482+
.as_ref()
483+
.and_then(|c| c.base_url.clone())
484+
.unwrap_or_else(ollama::OllamaClient::default_base_url);
485+
let context_window = ai.ollama.as_ref().and_then(|c| c.context_window_size).unwrap_or_else(|| ollama::OllamaClient::default_context_window_for_model(&model));
486+
let max_tokens = ai.ollama.as_ref().and_then(|c| c.max_tokens).unwrap_or(4096);
487+
Ok(Arc::new(ollama::OllamaClient::new(
488+
base_url, model, context_window, max_tokens, ai.api_timeout_secs,
489+
)?))
490+
}
475491
"claude-cli" => {
476492
let cfg = ai.claude_cli.as_ref();
477493
Ok(Arc::new(claude_cli::ClaudeCliProvider {
@@ -556,6 +572,7 @@ pub mod devin_cli;
556572
pub mod gemini;
557573
pub mod kiro_cli;
558574
pub mod openai;
575+
pub mod ollama;
559576
pub mod proxy;
560577
pub mod quota;
561578
pub mod session;

0 commit comments

Comments
 (0)