From f5e8e872b08d2aa9b3c063b0a98c59f842f94ecc Mon Sep 17 00:00:00 2001 From: sigoden Date: Sat, 27 Jul 2024 21:33:04 +0800 Subject: feat: support patching request url, headers and body (#756) --- src/client/claude.rs | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'src/client/claude.rs') diff --git a/src/client/claude.rs b/src/client/claude.rs index df0c034..8a7b14c 100644 --- a/src/client/claude.rs +++ b/src/client/claude.rs @@ -1,7 +1,7 @@ use super::*; use anyhow::{bail, Context, Result}; -use reqwest::{Client as ReqwestClient, RequestBuilder}; +use reqwest::RequestBuilder; use serde::Deserialize; use serde_json::{json, Value}; @@ -13,7 +13,7 @@ pub struct ClaudeConfig { pub api_key: Option, #[serde(default)] pub models: Vec, - pub patch: Option, + pub patch: Option, pub extra: Option, } @@ -23,27 +23,19 @@ impl ClaudeClient { pub const PROMPTS: [PromptAction<'static>; 1] = [("api_key", "API Key:", true, PromptKind::String)]; - fn chat_completions_builder( - &self, - client: &ReqwestClient, - data: ChatCompletionsData, - ) -> Result { + fn prepare_chat_completions(&self, data: ChatCompletionsData) -> Result { let api_key = self.get_api_key().ok(); - let mut body = claude_build_chat_completions_body(data, &self.model)?; - self.patch_chat_completions_body(&mut body); + let body = claude_build_chat_completions_body(data, &self.model)?; - let url = API_BASE; + let mut request_data = RequestData::new(API_BASE, body); - debug!("Claude Request: {url} {body}"); - - let mut builder = client.post(url).json(&body); - builder = builder.header("anthropic-version", "2023-06-01"); + request_data.header("anthropic-version", "2023-06-01"); if let Some(api_key) = api_key { - builder = builder.header("x-api-key", api_key) + request_data.header("x-api-key", api_key) } - Ok(builder) + Ok(request_data) } } -- cgit v1.2.3