summaryrefslogtreecommitdiffstats
path: root/src/client/cloudflare.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-08-17 16:01:39 +0800
committerGitHub <noreply@github.com>2024-08-17 16:01:39 +0800
commit669f2c602c4631db1c91fd7a27098b7685027f9a (patch)
tree3f743d4c2fa6e4eb847c6f9f2618b140f75b95b4 /src/client/cloudflare.rs
parent580ed6bea370345f76ca69ecb4c1cc30afa689c5 (diff)
downloadaichat-669f2c602c4631db1c91fd7a27098b7685027f9a.tar.gz
feat: enable custom `api_base` for most clients (#793)
Diffstat (limited to 'src/client/cloudflare.rs')
-rw-r--r--src/client/cloudflare.rs8
1 files changed, 7 insertions, 1 deletions
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<String>,
pub account_id: Option<String>,
+ pub api_base: Option<String>,
pub api_key: Option<String>,
#[serde(default)]
pub models: Vec<ModelData>,
@@ -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<RequestData> {
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()
);