diff options
| author | sigoden <sigoden@gmail.com> | 2024-08-17 16:01:39 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-17 16:01:39 +0800 |
| commit | 669f2c602c4631db1c91fd7a27098b7685027f9a (patch) | |
| tree | 3f743d4c2fa6e4eb847c6f9f2618b140f75b95b4 /src/client/claude.rs | |
| parent | 580ed6bea370345f76ca69ecb4c1cc30afa689c5 (diff) | |
| download | aichat-669f2c602c4631db1c91fd7a27098b7685027f9a.tar.gz | |
feat: enable custom `api_base` for most clients (#793)
Diffstat (limited to 'src/client/claude.rs')
| -rw-r--r-- | src/client/claude.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/client/claude.rs b/src/client/claude.rs index 8811476..7b472a7 100644 --- a/src/client/claude.rs +++ b/src/client/claude.rs @@ -5,12 +5,13 @@ use reqwest::RequestBuilder; use serde::Deserialize; use serde_json::{json, Value}; -const API_BASE: &str = "https://api.anthropic.com/v1/messages"; +const API_BASE: &str = "https://api.anthropic.com/v1"; #[derive(Debug, Clone, Deserialize)] pub struct ClaudeConfig { pub name: Option<String>, pub api_key: Option<String>, + pub api_base: Option<String>, #[serde(default)] pub models: Vec<ModelData>, pub patch: Option<RequestPatch>, @@ -19,6 +20,7 @@ pub struct ClaudeConfig { impl ClaudeClient { config_get_fn!(api_key, get_api_key); + config_get_fn!(api_base, get_api_base); pub const PROMPTS: [PromptAction<'static>; 1] = [("api_key", "API Key:", true, PromptKind::String)]; @@ -40,10 +42,14 @@ fn prepare_chat_completions( data: ChatCompletionsData, ) -> Result<RequestData> { let api_key = self_.get_api_key().ok(); + let api_base = self_ + .get_api_base() + .unwrap_or_else(|_| API_BASE.to_string()); + let url = format!("{}/messages", api_base.trim_end_matches('/')); let body = claude_build_chat_completions_body(data, &self_.model)?; - let mut request_data = RequestData::new(API_BASE, body); + let mut request_data = RequestData::new(url, body); request_data.header("anthropic-version", "2023-06-01"); if let Some(api_key) = api_key { |
