starweaver_model/providers/client/
factory.rs1use std::sync::Arc;
2
3use crate::{
4 ModelError,
5 presets::{
6 anthropic_http_config, gemini_http_config, openai_chat_http_config,
7 openai_responses_http_config,
8 },
9 profile::{ModelProfile, ProtocolFamily},
10 transport::{DynHttpClient, HttpModelConfig, ReqwestHttpClient},
11};
12
13use super::ProtocolModelClient;
14
15impl ProtocolModelClient {
16 pub fn openai_chat(
22 model_name: impl Into<String>,
23 token: impl Into<String>,
24 ) -> Result<Self, ModelError> {
25 let config = openai_chat_http_config(token);
26 Ok(Self::new(
27 "openai",
28 model_name,
29 ModelProfile::for_protocol(ProtocolFamily::OpenAiChatCompletions),
30 config,
31 Arc::new(ReqwestHttpClient::new()?),
32 ))
33 }
34
35 pub fn openai_responses(
41 model_name: impl Into<String>,
42 token: impl Into<String>,
43 ) -> Result<Self, ModelError> {
44 let config = openai_responses_http_config(token);
45 Ok(Self::new(
46 "openai",
47 model_name,
48 ModelProfile::for_protocol(ProtocolFamily::OpenAiResponses),
49 config,
50 Arc::new(ReqwestHttpClient::new()?),
51 ))
52 }
53
54 pub fn anthropic_messages(
60 model_name: impl Into<String>,
61 api_key: impl Into<String>,
62 ) -> Result<Self, ModelError> {
63 let config = anthropic_http_config(api_key);
64 Ok(Self::new(
65 "anthropic",
66 model_name,
67 ModelProfile::for_protocol(ProtocolFamily::AnthropicMessages),
68 config,
69 Arc::new(ReqwestHttpClient::new()?),
70 ))
71 }
72
73 pub fn gemini_generate_content(
79 model_name: impl Into<String>,
80 api_key: impl Into<String>,
81 ) -> Result<Self, ModelError> {
82 let model_name = model_name.into();
83 let config = gemini_http_config(api_key, model_name.clone());
84 Ok(Self::new(
85 "gemini",
86 model_name,
87 ModelProfile::for_protocol(ProtocolFamily::GeminiGenerateContent),
88 config,
89 Arc::new(ReqwestHttpClient::new()?),
90 ))
91 }
92
93 #[must_use]
98 pub fn bedrock_converse_gateway(
99 model_name: impl Into<String>,
100 http_config: HttpModelConfig,
101 http_client: DynHttpClient,
102 ) -> Self {
103 Self::new(
104 "bedrock",
105 model_name,
106 ModelProfile::for_protocol(ProtocolFamily::BedrockConverse),
107 http_config,
108 http_client,
109 )
110 }
111}