@@ -30,38 +30,25 @@ pub struct VertexAiConfig {
3030pub struct OpenAiConfig {
3131 pub org_id : Option < String > ,
3232 pub project_id : Option < String > ,
33- pub api_key : Option < String > ,
3433}
3534
3635#[ derive( Debug , Clone , Serialize , Deserialize ) ]
37- pub struct AnthropicConfig {
38- pub api_key : Option < String > ,
39- }
36+ pub struct AnthropicConfig { }
4037
4138#[ derive( Debug , Clone , Serialize , Deserialize ) ]
42- pub struct GeminiConfig {
43- pub api_key : Option < String > ,
44- }
39+ pub struct GeminiConfig { }
4540
4641#[ derive( Debug , Clone , Serialize , Deserialize ) ]
47- pub struct VoyageConfig {
48- pub api_key : Option < String > ,
49- }
42+ pub struct VoyageConfig { }
5043
5144#[ derive( Debug , Clone , Serialize , Deserialize ) ]
52- pub struct LiteLlmConfig {
53- pub api_key : Option < String > ,
54- }
45+ pub struct LiteLlmConfig { }
5546
5647#[ derive( Debug , Clone , Serialize , Deserialize ) ]
57- pub struct OpenRouterConfig {
58- pub api_key : Option < String > ,
59- }
48+ pub struct OpenRouterConfig { }
6049
6150#[ derive( Debug , Clone , Serialize , Deserialize ) ]
62- pub struct VllmConfig {
63- pub api_key : Option < String > ,
64- }
51+ pub struct VllmConfig { }
6552
6653#[ derive( Debug , Clone , Serialize , Deserialize ) ]
6754#[ serde( tag = "kind" ) ]
@@ -81,6 +68,7 @@ pub struct LlmSpec {
8168 pub api_type : LlmApiType ,
8269 pub address : Option < String > ,
8370 pub model : String ,
71+ pub api_key : Option < String > ,
8472 pub api_config : Option < LlmApiConfig > ,
8573}
8674
@@ -154,31 +142,37 @@ mod voyage;
154142pub async fn new_llm_generation_client (
155143 api_type : LlmApiType ,
156144 address : Option < String > ,
145+ api_key : Option < String > ,
157146 api_config : Option < LlmApiConfig > ,
158147) -> Result < Box < dyn LlmGenerationClient > > {
159148 let client = match api_type {
160149 LlmApiType :: Ollama => {
161150 Box :: new ( ollama:: Client :: new ( address) . await ?) as Box < dyn LlmGenerationClient >
162151 }
163- LlmApiType :: OpenAi => {
164- Box :: new ( openai:: Client :: new ( address, api_config) ?) as Box < dyn LlmGenerationClient >
165- }
166- LlmApiType :: Gemini => Box :: new ( gemini:: AiStudioClient :: new ( address, api_config) ?)
167- as Box < dyn LlmGenerationClient > ,
168- LlmApiType :: VertexAi => Box :: new ( gemini:: VertexAiClient :: new ( address, api_config) . await ?)
152+ LlmApiType :: OpenAi => Box :: new ( openai:: Client :: new ( address, api_key, api_config) ?)
169153 as Box < dyn LlmGenerationClient > ,
170- LlmApiType :: Anthropic => Box :: new ( anthropic:: Client :: new ( address, api_config) . await ?)
171- as Box < dyn LlmGenerationClient > ,
172- LlmApiType :: LiteLlm => Box :: new ( litellm:: Client :: new_litellm ( address, api_config) . await ?)
154+ LlmApiType :: Gemini => Box :: new ( gemini:: AiStudioClient :: new ( address, api_key, api_config) ?)
173155 as Box < dyn LlmGenerationClient > ,
156+ LlmApiType :: VertexAi => {
157+ Box :: new ( gemini:: VertexAiClient :: new ( address, api_key, api_config) . await ?)
158+ as Box < dyn LlmGenerationClient >
159+ }
160+ LlmApiType :: Anthropic => {
161+ Box :: new ( anthropic:: Client :: new ( address, api_key, api_config) . await ?)
162+ as Box < dyn LlmGenerationClient >
163+ }
164+ LlmApiType :: LiteLlm => {
165+ Box :: new ( litellm:: Client :: new_litellm ( address, api_key, api_config) . await ?)
166+ as Box < dyn LlmGenerationClient >
167+ }
174168 LlmApiType :: OpenRouter => {
175- Box :: new ( openrouter:: Client :: new_openrouter ( address, api_config) . await ?)
169+ Box :: new ( openrouter:: Client :: new_openrouter ( address, api_key , api_config) . await ?)
176170 as Box < dyn LlmGenerationClient >
177171 }
178172 LlmApiType :: Voyage => {
179173 api_bail ! ( "Voyage is not supported for generation" )
180174 }
181- LlmApiType :: Vllm => Box :: new ( vllm:: Client :: new_vllm ( address, api_config) . await ?)
175+ LlmApiType :: Vllm => Box :: new ( vllm:: Client :: new_vllm ( address, api_key , api_config) . await ?)
182176 as Box < dyn LlmGenerationClient > ,
183177 } ;
184178 Ok ( client)
@@ -187,22 +181,23 @@ pub async fn new_llm_generation_client(
187181pub async fn new_llm_embedding_client (
188182 api_type : LlmApiType ,
189183 address : Option < String > ,
184+ api_key : Option < String > ,
190185 api_config : Option < LlmApiConfig > ,
191186) -> Result < Box < dyn LlmEmbeddingClient > > {
192187 let client = match api_type {
193188 LlmApiType :: Ollama => {
194189 Box :: new ( ollama:: Client :: new ( address) . await ?) as Box < dyn LlmEmbeddingClient >
195190 }
196- LlmApiType :: Gemini => Box :: new ( gemini:: AiStudioClient :: new ( address, api_config) ?)
191+ LlmApiType :: Gemini => Box :: new ( gemini:: AiStudioClient :: new ( address, api_key , api_config) ?)
197192 as Box < dyn LlmEmbeddingClient > ,
198- LlmApiType :: OpenAi => {
199- Box :: new ( openai:: Client :: new ( address, api_config) ?) as Box < dyn LlmEmbeddingClient >
200- }
201- LlmApiType :: Voyage => {
202- Box :: new ( voyage:: Client :: new ( address, api_config) ?) as Box < dyn LlmEmbeddingClient >
203- }
204- LlmApiType :: VertexAi => Box :: new ( gemini:: VertexAiClient :: new ( address, api_config) . await ?)
193+ LlmApiType :: OpenAi => Box :: new ( openai:: Client :: new ( address, api_key, api_config) ?)
194+ as Box < dyn LlmEmbeddingClient > ,
195+ LlmApiType :: Voyage => Box :: new ( voyage:: Client :: new ( address, api_key, api_config) ?)
205196 as Box < dyn LlmEmbeddingClient > ,
197+ LlmApiType :: VertexAi => {
198+ Box :: new ( gemini:: VertexAiClient :: new ( address, api_key, api_config) . await ?)
199+ as Box < dyn LlmEmbeddingClient >
200+ }
206201 LlmApiType :: OpenRouter | LlmApiType :: LiteLlm | LlmApiType :: Vllm | LlmApiType :: Anthropic => {
207202 api_bail ! ( "Embedding is not supported for API type {:?}" , api_type)
208203 }
0 commit comments