diff options
| author | sigoden <sigoden@gmail.com> | 2024-07-28 06:04:36 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-28 06:04:36 +0800 |
| commit | 0e740d81e94505bd57036755abaaecb12c3b26e3 (patch) | |
| tree | 49000370fb12e4e5e1f1bd4d145104f2f502aa16 /src/client/claude.rs | |
| parent | f5e8e872b08d2aa9b3c063b0a98c59f842f94ecc (diff) | |
| download | aichat-0e740d81e94505bd57036755abaaecb12c3b26e3.tar.gz | |
feat: abandon rag_dedicated client and improve (#757)
Diffstat (limited to 'src/client/claude.rs')
| -rw-r--r-- | src/client/claude.rs | 44 |
1 files changed, 28 insertions, 16 deletions
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<RequestData> { - 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<RequestData> { + 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<ChatCompletionsOutput> { +pub async fn claude_chat_completions( + builder: RequestBuilder, + _model: &Model, +) -> Result<ChatCompletionsOutput> { 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<ChatComp pub async fn claude_chat_completions_streaming( builder: RequestBuilder, handler: &mut SseHandler, + _model: &Model, ) -> Result<()> { let mut function_name = String::new(); let mut function_arguments = String::new(); |
