From 0e740d81e94505bd57036755abaaecb12c3b26e3 Mon Sep 17 00:00:00 2001 From: sigoden Date: Sun, 28 Jul 2024 06:04:36 +0800 Subject: feat: abandon rag_dedicated client and improve (#757) --- src/client/claude.rs | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'src/client/claude.rs') diff --git a/src/client/claude.rs b/src/client/claude.rs index 8a7b14c..d8046a9 100644 --- a/src/client/claude.rs +++ b/src/client/claude.rs @@ -22,30 +22,41 @@ impl ClaudeClient { pub const PROMPTS: [PromptAction<'static>; 1] = [("api_key", "API Key:", true, PromptKind::String)]; +} - fn prepare_chat_completions(&self, data: ChatCompletionsData) -> Result { - let api_key = self.get_api_key().ok(); +impl_client_trait!( + ClaudeClient, + ( + prepare_chat_completions, + claude_chat_completions, + claude_chat_completions_streaming + ), + (noop_prepare_embeddings, noop_embeddings), + (noop_prepare_rerank, noop_rerank), +); - let body = claude_build_chat_completions_body(data, &self.model)?; +fn prepare_chat_completions( + self_: &ClaudeClient, + data: ChatCompletionsData, +) -> Result { + let api_key = self_.get_api_key().ok(); - let mut request_data = RequestData::new(API_BASE, body); + let body = claude_build_chat_completions_body(data, &self_.model)?; - request_data.header("anthropic-version", "2023-06-01"); - if let Some(api_key) = api_key { - request_data.header("x-api-key", api_key) - } + let mut request_data = RequestData::new(API_BASE, body); - Ok(request_data) + request_data.header("anthropic-version", "2023-06-01"); + if let Some(api_key) = api_key { + request_data.header("x-api-key", api_key) } -} -impl_client_trait!( - ClaudeClient, - claude_chat_completions, - claude_chat_completions_streaming -); + Ok(request_data) +} -pub async fn claude_chat_completions(builder: RequestBuilder) -> Result { +pub async fn claude_chat_completions( + builder: RequestBuilder, + _model: &Model, +) -> Result { let res = builder.send().await?; let status = res.status(); let data: Value = res.json().await?; @@ -59,6 +70,7 @@ pub async fn claude_chat_completions(builder: RequestBuilder) -> Result Result<()> { let mut function_name = String::new(); let mut function_arguments = String::new(); -- cgit v1.2.3