diff --git a/rust/crates/api/src/client.rs b/rust/crates/api/src/client.rs index 2adaca4..d337c38 100644 --- a/rust/crates/api/src/client.rs +++ b/rust/crates/api/src/client.rs @@ -21,7 +21,7 @@ async fn stream_via_provider( #[derive(Debug, Clone)] pub enum ProviderClient { - Anthropic(AnthropicClient), + Anthropic(Box), Xai(OpenAiCompatClient), OpenAi(OpenAiCompatClient), } @@ -37,10 +37,10 @@ impl ProviderClient { ) -> Result { let resolved_model = providers::resolve_model_alias(model); match providers::detect_provider_kind(&resolved_model) { - ProviderKind::Anthropic => Ok(Self::Anthropic(match anthropic_auth { + ProviderKind::Anthropic => Ok(Self::Anthropic(Box::new(match anthropic_auth { Some(auth) => AnthropicClient::from_auth(auth), None => AnthropicClient::from_env()?, - })), + }))), ProviderKind::Xai => Ok(Self::Xai(OpenAiCompatClient::from_env( OpenAiCompatConfig::xai(), )?)), @@ -62,7 +62,9 @@ impl ProviderClient { #[must_use] pub fn with_prompt_cache(self, prompt_cache: PromptCache) -> Self { match self { - Self::Anthropic(client) => Self::Anthropic(client.with_prompt_cache(prompt_cache)), + Self::Anthropic(client) => { + Self::Anthropic(Box::new((*client).with_prompt_cache(prompt_cache))) + } other => other, } } @@ -88,7 +90,7 @@ impl ProviderClient { request: &MessageRequest, ) -> Result { match self { - Self::Anthropic(client) => send_via_provider(client, request).await, + Self::Anthropic(client) => send_via_provider(client.as_ref(), request).await, Self::Xai(client) | Self::OpenAi(client) => send_via_provider(client, request).await, } } @@ -98,7 +100,7 @@ impl ProviderClient { request: &MessageRequest, ) -> Result { match self { - Self::Anthropic(client) => stream_via_provider(client, request) + Self::Anthropic(client) => stream_via_provider(client.as_ref(), request) .await .map(MessageStream::Anthropic), Self::Xai(client) | Self::OpenAi(client) => stream_via_provider(client, request) diff --git a/rust/crates/api/tests/client_integration.rs b/rust/crates/api/tests/client_integration.rs index 01addef..d1de029 100644 --- a/rust/crates/api/tests/client_integration.rs +++ b/rust/crates/api/tests/client_integration.rs @@ -407,7 +407,7 @@ async fn provider_client_dispatches_anthropic_requests() { .expect("anthropic provider client should be constructed"); let client = match client { ProviderClient::Anthropic(client) => { - ProviderClient::Anthropic(client.with_base_url(server.base_url())) + ProviderClient::Anthropic(Box::new((*client).with_base_url(server.base_url()))) } other => panic!("expected anthropic provider, got {other:?}"), };