Skip to content

Commit ccb1b0f

Browse files
committed
Feature: Enable programmatically pass in api_key besides reading from env
1 parent 26b5788 commit ccb1b0f

File tree

2 files changed

+17
-28
lines changed

2 files changed

+17
-28
lines changed

python/cocoindex/llm.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,4 @@ class LlmSpec:
4444
model: str
4545
address: str | None = None
4646
api_key: str | None = None
47-
api_config: (
48-
VertexAiConfig
49-
| OpenAiConfig
50-
| None
51-
) = None
47+
api_config: VertexAiConfig | OpenAiConfig | None = None

src/ops/functions/embed_text.rs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,41 +94,34 @@ impl SimpleFunctionFactoryBase for Factory {
9494
.required()?;
9595

9696
// Create API config based on api_key parameter if provided
97-
let api_config = if let Some(api_key) = &spec.api_key {
98-
Some(match spec.api_type {
99-
LlmApiType::OpenAi => {
100-
LlmApiConfig::OpenAi(super::super::super::llm::OpenAiConfig {
97+
let api_config = if let Some(_api_key) = &spec.api_key {
98+
match spec.api_type {
99+
LlmApiType::OpenAi => Some(LlmApiConfig::OpenAi(
100+
super::super::super::llm::OpenAiConfig {
101101
org_id: None,
102102
project_id: None,
103-
})
103+
},
104+
)),
105+
LlmApiType::Anthropic
106+
| LlmApiType::Gemini
107+
| LlmApiType::Voyage
108+
| LlmApiType::LiteLlm
109+
| LlmApiType::OpenRouter
110+
| LlmApiType::Vllm => {
111+
// These API types don't require a config, just an API key
112+
None
104113
}
105-
LlmApiType::Anthropic => {
106-
LlmApiConfig::Anthropic(super::super::super::llm::AnthropicConfig {})
107-
}
108-
LlmApiType::Gemini => {
109-
LlmApiConfig::Gemini(super::super::super::llm::GeminiConfig {})
110-
}
111-
LlmApiType::Voyage => {
112-
LlmApiConfig::Voyage(super::super::super::llm::VoyageConfig {})
113-
}
114-
LlmApiType::LiteLlm => {
115-
LlmApiConfig::LiteLlm(super::super::super::llm::LiteLlmConfig {})
116-
}
117-
LlmApiType::OpenRouter => {
118-
LlmApiConfig::OpenRouter(super::super::super::llm::OpenRouterConfig {})
119-
}
120-
LlmApiType::Vllm => LlmApiConfig::Vllm(super::super::super::llm::VllmConfig {}),
121114
_ => {
122115
if let Some(config) = spec.api_config.clone() {
123-
config
116+
Some(config)
124117
} else {
125118
api_bail!(
126119
"API key parameter is not supported for API type {:?}",
127120
spec.api_type
128121
)
129122
}
130123
}
131-
})
124+
}
132125
} else {
133126
spec.api_config.clone()
134127
};

0 commit comments

Comments
 (0)