mirror of
https://github.com/jina-ai/node-DeepResearch.git
synced 2025-12-26 06:28:56 +08:00
fix: make openai client initialization conditional
Co-Authored-By: Han Xiao <han.xiao@jina.ai>
This commit is contained in:
parent
8293464127
commit
c81eb0e32a
@ -17,17 +17,19 @@ export class LLMClient {
|
||||
|
||||
constructor() {
|
||||
this.geminiClient = new GoogleGenerativeAI(GEMINI_API_KEY);
|
||||
this.openaiClient = new OpenAI({
|
||||
apiKey: OPENAI_API_KEY,
|
||||
baseURL: llmConfig.baseURL
|
||||
});
|
||||
if (llmConfig.provider === 'openai') {
|
||||
this.openaiClient = new OpenAI({
|
||||
apiKey: OPENAI_API_KEY,
|
||||
baseURL: llmConfig.baseURL
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async generateContent(model: any, prompt: string) {
|
||||
if (llmConfig.provider === 'gemini') {
|
||||
const result = await model.generateContent(prompt);
|
||||
return result;
|
||||
} else {
|
||||
} else if (this.openaiClient) {
|
||||
const completion = await model.create({
|
||||
model: "gpt-3.5-turbo",
|
||||
messages: [{ role: "user", content: prompt }],
|
||||
@ -43,18 +45,20 @@ export class LLMClient {
|
||||
}
|
||||
};
|
||||
}
|
||||
throw new Error('OpenAI client not initialized. Set OPENAI_API_KEY and provider="openai" to use OpenAI.');
|
||||
}
|
||||
|
||||
getModel(options: LLMClientOptions) {
|
||||
if (llmConfig.provider === 'gemini') {
|
||||
return this.geminiClient.getGenerativeModel(options);
|
||||
} else {
|
||||
} else if (this.openaiClient) {
|
||||
return {
|
||||
...this.openaiClient.chat.completions,
|
||||
temperature: options.temperature,
|
||||
generateContent: (prompt: string) => this.generateContent(this.openaiClient.chat.completions, prompt)
|
||||
};
|
||||
}
|
||||
throw new Error('OpenAI client not initialized. Set OPENAI_API_KEY and provider="openai" to use OpenAI.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user