gemini.ts
This commit is contained in:
parent
8a76f92e23
commit
72339ba559
1 changed files with 45 additions and 0 deletions
45
src/lib/providers/gemini.ts
Normal file
45
src/lib/providers/gemini.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
|
||||
import { GoogleGenerativeAIEmbeddings } from '@langchain/google-genai';
|
||||
import { getGeminiApiKey } from '../../config';
|
||||
import logger from '../../utils/logger';
|
||||
|
||||
export const loadGeminiChatModels = async () => {
|
||||
const geminiApiKey = getGeminiApiKey();
|
||||
|
||||
if (!geminiApiKey) return {};
|
||||
|
||||
try {
|
||||
const chatModels = {
|
||||
'Gemini Pro': new ChatGoogleGenerativeAI({
|
||||
temperature: 0.7,
|
||||
apiKey: geminiApiKey,
|
||||
modelName: 'gemini-pro',
|
||||
}),
|
||||
};
|
||||
|
||||
return chatModels;
|
||||
} catch (err) {
|
||||
logger.error(`Error loading Gemini chat models: ${err}`);
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
export const loadGeminiEmbeddingsModels = async () => {
|
||||
const geminiApiKey = getGeminiApiKey();
|
||||
|
||||
if (!geminiApiKey) return {};
|
||||
|
||||
try {
|
||||
const embeddingsModels = {
|
||||
'Gemini Embedding': new GoogleGenerativeAIEmbeddings({
|
||||
apiKey: geminiApiKey,
|
||||
modelName: 'embedding-001',
|
||||
}),
|
||||
};
|
||||
|
||||
return embeddingsModels;
|
||||
} catch (err) {
|
||||
logger.error(`Error loading Gemini embeddings model: ${err}`);
|
||||
return {};
|
||||
}
|
||||
};
|
Loading…
Add table
Reference in a new issue