Skip to content

Commit 3c11d59

Browse files
committed
feat: add configurable base URL to anthropic, ollama, and openai prov...
The changes introduce a configurable base URL for each LLM provider, allowing users to specify custom endpoints (e.g., for local or private instances). This improves flexibility and enables deployment in environments with custom API hosting.
1 parent 1f5c340 commit 3c11d59

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

src/services/llm/anthropic.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ use tokio_util::sync::CancellationToken;
1313
use crate::config::Config;
1414
use crate::error::{Error, Result};
1515

16-
const BASE_URL: &str = "https://api.anthropic.com/v1";
16+
const DEFAULT_BASE_URL: &str = "https://api.anthropic.com/v1";
1717
const API_VERSION: &str = "2023-06-01";
1818

1919
pub struct AnthropicProvider {
2020
client: Client,
21+
base_url: String,
2122
model: String,
2223
api_key: String,
2324
temperature: f32,
@@ -59,9 +60,12 @@ RULES:
5960
2. The subject must be SPECIFIC - mention what was added/changed/fixed
6061
3. Output ONLY valid JSON
6162
4. Start subject with lowercase verb: add, fix, update, remove, refactor
63+
5. Include a body (1-3 sentences) for non-trivial changes explaining WHY the change was made. Use null only for trivial changes like typo fixes or renames.
6264
63-
BAD: "describe what changed" or "update code"
64-
GOOD: "add rate limiting to api endpoints" or "fix null check in user service""#;
65+
BAD subject: "describe what changed" or "update code"
66+
GOOD subject: "add rate limiting to api endpoints" or "fix null check in user service"
67+
GOOD body: "The previous implementation used byte indexing which panics on multi-byte characters. Switch to char_indices for safe truncation."
68+
BAD body: "Updated the code to fix the bug" (too vague)"#;
6569

6670
impl AnthropicProvider {
6771
pub fn new(config: &Config) -> Self {
@@ -72,6 +76,12 @@ impl AnthropicProvider {
7276

7377
Self {
7478
client,
79+
base_url: config
80+
.anthropic_base_url
81+
.clone()
82+
.unwrap_or_else(|| DEFAULT_BASE_URL.to_string())
83+
.trim_end_matches('/')
84+
.to_string(),
7585
model: config.model.clone(),
7686
api_key: config.api_key.clone().unwrap_or_default(),
7787
temperature: config.temperature,
@@ -97,7 +107,7 @@ impl AnthropicProvider {
97107
token_tx: mpsc::Sender<String>,
98108
cancel: CancellationToken,
99109
) -> Result<String> {
100-
let url = format!("{BASE_URL}/messages");
110+
let url = format!("{}/messages", self.base_url);
101111

102112
let response = self
103113
.client

src/services/llm/ollama.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ RULES:
4343
2. The subject must be SPECIFIC - mention what was added/changed/fixed
4444
3. Output ONLY valid JSON
4545
4. Start subject with lowercase verb: add, fix, update, remove, refactor
46+
5. Include a body (1-3 sentences) for non-trivial changes explaining WHY the change was made. Use null only for trivial changes like typo fixes or renames.
4647
47-
BAD: "describe what changed" or "update code"
48-
GOOD: "add rate limiting to api endpoints" or "fix null check in user service""#;
48+
BAD subject: "describe what changed" or "update code"
49+
GOOD subject: "add rate limiting to api endpoints" or "fix null check in user service"
50+
GOOD body: "The previous implementation used byte indexing which panics on multi-byte characters. Switch to char_indices for safe truncation."
51+
BAD body: "Updated the code to fix the bug" (too vague)"#;
4952

5053
#[derive(Deserialize)]
5154
struct GenerateResponse {

src/services/llm/openai.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ RULES:
6262
2. The subject must be SPECIFIC - mention what was added/changed/fixed
6363
3. Output ONLY valid JSON
6464
4. Start subject with lowercase verb: add, fix, update, remove, refactor
65+
5. Include a body (1-3 sentences) for non-trivial changes explaining WHY the change was made. Use null only for trivial changes like typo fixes or renames.
6566
66-
BAD: "describe what changed" or "update code"
67-
GOOD: "add rate limiting to api endpoints" or "fix null check in user service""#;
67+
BAD subject: "describe what changed" or "update code"
68+
GOOD subject: "add rate limiting to api endpoints" or "fix null check in user service"
69+
GOOD body: "The previous implementation used byte indexing which panics on multi-byte characters. Switch to char_indices for safe truncation."
70+
BAD body: "Updated the code to fix the bug" (too vague)"#;
6871

6972
impl OpenAiProvider {
7073
pub fn new(config: &Config) -> Self {

0 commit comments

Comments
 (0)