Skip to content

Commit

Permalink
feat: added perplexity model
Browse files Browse the repository at this point in the history
  • Loading branch information
meetpateltech committed Dec 14, 2024
1 parent 9666b2a commit 8bcd82c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ LMSTUDIO_API_BASE_URL=
# You only need this environment variable set if you want to use xAI models
XAI_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

Expand Down
2 changes: 1 addition & 1 deletion app/commit.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "commit": "55094392cf4c5bc607aff796680ad50236a4cf20" }
{ "commit": "9666b2ab67d25345542722ab9d870b36ad06252e" }
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 @@ -39,6 +39,8 @@ export function getAPIKey(cloudflareEnv: Env, provider: string, userApiKeys?: Re
return env.TOGETHER_API_KEY || cloudflareEnv.TOGETHER_API_KEY;
case 'xAI':
return env.XAI_API_KEY || cloudflareEnv.XAI_API_KEY;
case 'Perplexity':
return env.PERPLEXITY_API_KEY || cloudflareEnv.PERPLEXITY_API_KEY;
case 'Cohere':
return env.COHERE_API_KEY;
case 'AzureOpenAI':
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 @@ -128,6 +128,15 @@ export function getXAIModel(apiKey: OptionalApiKey, model: string) {
return openai(model);
}

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

return perplexity(model);
}

export function getModel(
provider: string,
model: string,
Expand Down Expand Up @@ -170,6 +179,8 @@ export function getModel(
return getXAIModel(apiKey, model);
case 'Cohere':
return getCohereAIModel(apiKey, model);
case 'Perplexity':
return getPerplexityModel(apiKey, model);
default:
return getOllamaModel(baseURL, model);
}
Expand Down
24 changes: 24 additions & 0 deletions app/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,30 @@ const PROVIDER_LIST: ProviderInfo[] = [
],
getApiKeyLink: 'https://api.together.xyz/settings/api-keys',
},
{
name: 'Perplexity',
staticModels: [
{
name: 'llama-3.1-sonar-small-128k-online',
label: 'Sonar Small Online',
provider: 'Perplexity',
maxTokenAllowed: 8192,
},
{
name: 'llama-3.1-sonar-large-128k-online',
label: 'Sonar Large Online',
provider: 'Perplexity',
maxTokenAllowed: 8192,
},
{
name: 'llama-3.1-sonar-huge-128k-online',
label: 'Sonar Huge Online',
provider: 'Perplexity',
maxTokenAllowed: 8192,
},
],
getApiKeyLink: 'https://www.perplexity.ai/settings/api',
},
];

export const DEFAULT_PROVIDER = PROVIDER_LIST[0];
Expand Down
1 change: 1 addition & 0 deletions worker-configuration.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ interface Env {
GOOGLE_GENERATIVE_AI_API_KEY: string;
MISTRAL_API_KEY: string;
XAI_API_KEY: string;
PERPLEXITY_API_KEY: string;
}

0 comments on commit 8bcd82c

Please sign in to comment.