From 669f2c602c4631db1c91fd7a27098b7685027f9a Mon Sep 17 00:00:00 2001 From: sigoden Date: Sat, 17 Aug 2024 16:01:39 +0800 Subject: feat: enable custom `api_base` for most clients (#793) --- src/client/cloudflare.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/client/cloudflare.rs') diff --git a/src/client/cloudflare.rs b/src/client/cloudflare.rs index a24a1c6..3626c73 100644 --- a/src/client/cloudflare.rs +++ b/src/client/cloudflare.rs @@ -11,6 +11,7 @@ const API_BASE: &str = "https://api.cloudflare.com/client/v4"; pub struct CloudflareConfig { pub name: Option, pub account_id: Option, + pub api_base: Option, pub api_key: Option, #[serde(default)] pub models: Vec, @@ -21,6 +22,7 @@ pub struct CloudflareConfig { impl CloudflareClient { config_get_fn!(account_id, get_account_id); config_get_fn!(api_key, get_api_key); + config_get_fn!(api_base, get_api_base); pub const PROMPTS: [PromptAction<'static>; 2] = [ ("account_id", "Account ID:", true, PromptKind::String), @@ -45,9 +47,13 @@ fn prepare_chat_completions( ) -> Result { let account_id = self_.get_account_id()?; let api_key = self_.get_api_key()?; + let api_base = self_ + .get_api_base() + .unwrap_or_else(|_| API_BASE.to_string()); let url = format!( - "{API_BASE}/accounts/{account_id}/ai/run/{}", + "{}/accounts/{account_id}/ai/run/{}", + api_base.trim_end_matches('/'), self_.model.name() ); -- cgit v1.2.3