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/openai_compatible.rs | |
| parent | 580ed6bea370345f76ca69ecb4c1cc30afa689c5 (diff) | |
| download | aichat-669f2c602c4631db1c91fd7a27098b7685027f9a.tar.gz | |
feat: enable custom `api_base` for most clients (#793)
Diffstat (limited to 'src/client/openai_compatible.rs')
| -rw-r--r-- | src/client/openai_compatible.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/client/openai_compatible.rs b/src/client/openai_compatible.rs index 8acac58..2bde884 100644 --- a/src/client/openai_compatible.rs +++ b/src/client/openai_compatible.rs @@ -36,7 +36,6 @@ impl OpenAICompatibleClient { ]; } - impl_client_trait!( OpenAICompatibleClient, ( @@ -55,11 +54,16 @@ fn prepare_chat_completions( let api_key = self_.get_api_key().ok(); let api_base = get_api_base_ext(self_)?; - let chat_endpoint = self_ - .config - .chat_endpoint - .as_deref() - .unwrap_or("/chat/completions"); + let chat_endpoint = match self_.config.chat_endpoint.clone() { + Some(v) => { + if v.starts_with('/') { + v + } else { + format!("/{}", v) + } + } + None => "/chat/completions".into(), + }; let url = format!("{api_base}{chat_endpoint}"); @@ -126,7 +130,7 @@ fn get_api_base_ext(self_: &OpenAICompatibleClient) -> Result<String> { } } }; - Ok(api_base) + Ok(api_base.trim_end_matches('/').to_string()) } pub async fn generic_rerank(builder: RequestBuilder, _model: &Model) -> Result<RerankOutput> { @@ -171,4 +175,4 @@ pub fn generic_build_rerank_body(data: RerankData, model: &Model) -> Value { body["top_n"] = top_n.into() } body -}
\ No newline at end of file +} |
