Skip to content

Commit

Permalink
added perplexity models
Browse files Browse the repository at this point in the history
Perplexity Integration
  • Loading branch information
meetpateltech committed Oct 27, 2024
1 parent 8e7220e commit ab1aab8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,10 @@ OPENAI_LIKE_API_KEY=
# You only need this environment variable set if you want to use Mistral models
MISTRAL_API_KEY=

# Get your Perplexity API Key here -
# https://www.perplexity.ai/settings/api
# You only need this environment variable set if you want to use Perplexity models
PERPLEXITY_API_KEY=

# Include this environment variable if you want more logging for debugging locally
VITE_LOG_LEVEL=debug
2 changes: 2 additions & 0 deletions app/lib/.server/llm/api-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export function getAPIKey(cloudflareEnv: Env, provider: string) {
return env.MISTRAL_API_KEY || cloudflareEnv.MISTRAL_API_KEY;
case "OpenAILike":
return env.OPENAI_LIKE_API_KEY || cloudflareEnv.OPENAI_LIKE_API_KEY;
case 'Perplexity':
return env.PERPLEXITY_API_KEY || cloudflareEnv.PERPLEXITY_API_KEY;
default:
return "";
}
Expand Down
11 changes: 11 additions & 0 deletions app/lib/.server/llm/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ export function getGroqModel(apiKey: string, model: string) {
return openai(model);
}

export function getPerplexityModel(apiKey: string, model: string) {
const perplexity = createOpenAI({
baseURL: 'https://api.perplexity.ai/',
apiKey,
});

return perplexity(model);
}

export function getOllamaModel(baseURL: string, model: string) {
let Ollama = ollama(model);
Ollama.config.baseURL = `${baseURL}/api`;
Expand Down Expand Up @@ -101,6 +110,8 @@ export function getModel(provider: string, model: string, env: Env) {
return getDeepseekModel(apiKey, model)
case 'Mistral':
return getMistralModel(apiKey, model);
case 'Perplexity':
return getPerplexityModel(apiKey, model);
default:
return getOllamaModel(baseURL, model);
}
Expand Down
5 changes: 5 additions & 0 deletions app/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ const staticModels: ModelInfo[] = [
{ name: 'mistral-small-latest', label: 'Mistral Small', provider: 'Mistral' },
{ name: 'codestral-latest', label: 'Codestral', provider: 'Mistral' },
{ name: 'mistral-large-latest', label: 'Mistral Large Latest', provider: 'Mistral' },
{ name: 'llama-3.1-sonar-small-128k-online', label: 'Sonar Small Online', provider: 'Perplexity' },
{ name: 'llama-3.1-sonar-large-128k-online', label: 'Sonar Large Online', provider: 'Perplexity' },
{ name: 'llama-3.1-sonar-huge-128k-online', label: 'Sonar Huge Online', provider: 'Perplexity' },
{ name: 'llama-3.1-sonar-small-128k-chat', label: 'Sonar Small Chat', provider: 'Perplexity' },
{ name: 'llama-3.1-sonar-large-128k-chat', label: 'Sonar Large Chat', provider: 'Perplexity'},
];

export let MODEL_LIST: ModelInfo[] = [...staticModels];
Expand Down

0 comments on commit ab1aab8

Please sign in to comment.