fix: handle undefined openai client in getModel

Co-Authored-By: Han Xiao <han.xiao@jina.ai>
This commit is contained in:
Devin AI 2025-02-05 10:33:28 +00:00
parent fabea4de3b
commit dc2c0cae5f

View File

@ -55,13 +55,14 @@ export class LLMClient {
if (llmConfig.provider === 'gemini') {
return this.geminiClient.getGenerativeModel(options);
} else if (this.openaiClient) {
if (!this.openaiClient) {
const client = this.openaiClient;
if (!client) {
throw new Error('OpenAI client not initialized. Set OPENAI_API_KEY and provider="openai" to use OpenAI.');
}
return {
...this.openaiClient.chat.completions,
...client.chat.completions,
temperature: options.temperature,
generateContent: (prompt: string) => this.generateContent(this.openaiClient.chat.completions, prompt)
generateContent: (prompt: string) => this.generateContent(client.chat.completions, prompt)
};
}
throw new Error('OpenAI client not initialized. Set OPENAI_API_KEY and provider="openai" to use OpenAI.');