Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Gemini 1.0 Pro Chat Model and Google Embedding -001 Model for Enhanced Perplexica Capabilities #284

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@langchain/anthropic": "^0.2.3",
"@langchain/community": "^0.2.16",
"@langchain/openai": "^0.0.25",
"@langchain/google-genai": "^0.0.23",
"@xenova/transformers": "^2.17.1",
"axios": "^1.6.8",
"better-sqlite3": "^11.0.0",
Expand Down
6 changes: 6 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface Config {
OPENAI: string;
GROQ: string;
ANTHROPIC: string;
Gemini: string;
};
API_ENDPOINTS: {
SEARXNG: string;
Expand Down Expand Up @@ -40,6 +41,11 @@ export const getGroqApiKey = () => loadConfig().API_KEYS.GROQ;

export const getAnthropicApiKey = () => loadConfig().API_KEYS.ANTHROPIC;


export const getGeminiApiKey = () => loadConfig().API_KEYS.Gemini;

export const getSearxngApiEndpoint = () => loadConfig().API_ENDPOINTS.SEARXNG;

export const getSearxngApiEndpoint = () =>
process.env.SEARXNG_API_URL || loadConfig().API_ENDPOINTS.SEARXNG;

Expand Down
45 changes: 45 additions & 0 deletions src/lib/providers/gemini.ts
Original file line number Diff line number Diff line change
@@ -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 {};
}
};
2 changes: 2 additions & 0 deletions src/lib/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ const chatModelProviders = {
groq: loadGroqChatModels,
ollama: loadOllamaChatModels,
anthropic: loadAnthropicChatModels,
gemini : loadGeminiChatModels
};

const embeddingModelProviders = {
openai: loadOpenAIEmbeddingsModels,
local: loadTransformersEmbeddingsModels,
ollama: loadOllamaEmbeddingsModels,
gemini : loadGeminiEmbeddingsModels
};

export const getAvailableChatModelProviders = async () => {
Expand Down
3 changes: 3 additions & 0 deletions src/routes/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getGroqApiKey,
getOllamaApiEndpoint,
getAnthropicApiKey,
getGeminiApiKey,
getOpenaiApiKey,
updateConfig,
} from '../config';
Expand Down Expand Up @@ -40,6 +41,7 @@ router.get('/', async (_, res) => {
config['ollamaApiUrl'] = getOllamaApiEndpoint();
config['anthropicApiKey'] = getAnthropicApiKey();
config['groqApiKey'] = getGroqApiKey();
config['geminiApiKey'] = getGeminiApiKey();

res.status(200).json(config);
});
Expand All @@ -52,6 +54,7 @@ router.post('/', async (req, res) => {
OPENAI: config.openaiApiKey,
GROQ: config.groqApiKey,
ANTHROPIC: config.anthropicApiKey,
Gemini: config.geminiApiKey,
},
API_ENDPOINTS: {
OLLAMA: config.ollamaApiUrl,
Expand Down
17 changes: 17 additions & 0 deletions ui/components/SettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ interface SettingsType {
openaiApiKey: string;
groqApiKey: string;
anthropicApiKey: string;
geminiApiKey: string;
ollamaApiUrl: string;
}

Expand Down Expand Up @@ -460,6 +461,22 @@ const SettingsDialog = ({
}
/>
</div>
<div className="flex flex-col space-y-1">
<p className="text-black/70 dark:text-white/70 text-sm">
Gemini API Key
</p>
<Input
type="text"
placeholder="Gemini API key"
defaultValue={config.geminiApiKey}
onChange={(e) =>
setConfig({
...config,
geminiApiKey: e.target.value,
})
}
/>
</div>
</div>
)}
{isLoading && (
Expand Down