codacus commited on
Commit
b06f6e3
·
unverified ·
2 Parent(s): 9efc709 86f37fc

Merge pull request #715 from meetpateltech/perplexity-models

Browse files
.env.example CHANGED
@@ -70,6 +70,11 @@ LMSTUDIO_API_BASE_URL=
70
  # You only need this environment variable set if you want to use xAI models
71
  XAI_API_KEY=
72
 
 
 
 
 
 
73
  # Include this environment variable if you want more logging for debugging locally
74
  VITE_LOG_LEVEL=debug
75
 
 
70
  # You only need this environment variable set if you want to use xAI models
71
  XAI_API_KEY=
72
 
73
+ # Get your Perplexity API Key here -
74
+ # https://www.perplexity.ai/settings/api
75
+ # You only need this environment variable set if you want to use Perplexity models
76
+ PERPLEXITY_API_KEY=
77
+
78
  # Include this environment variable if you want more logging for debugging locally
79
  VITE_LOG_LEVEL=debug
80
 
app/lib/.server/llm/api-key.ts CHANGED
@@ -39,6 +39,8 @@ export function getAPIKey(cloudflareEnv: Env, provider: string, userApiKeys?: Re
39
  return env.TOGETHER_API_KEY || cloudflareEnv.TOGETHER_API_KEY;
40
  case 'xAI':
41
  return env.XAI_API_KEY || cloudflareEnv.XAI_API_KEY;
 
 
42
  case 'Cohere':
43
  return env.COHERE_API_KEY;
44
  case 'AzureOpenAI':
 
39
  return env.TOGETHER_API_KEY || cloudflareEnv.TOGETHER_API_KEY;
40
  case 'xAI':
41
  return env.XAI_API_KEY || cloudflareEnv.XAI_API_KEY;
42
+ case 'Perplexity':
43
+ return env.PERPLEXITY_API_KEY || cloudflareEnv.PERPLEXITY_API_KEY;
44
  case 'Cohere':
45
  return env.COHERE_API_KEY;
46
  case 'AzureOpenAI':
app/lib/.server/llm/model.ts CHANGED
@@ -128,6 +128,15 @@ export function getXAIModel(apiKey: OptionalApiKey, model: string) {
128
  return openai(model);
129
  }
130
 
 
 
 
 
 
 
 
 
 
131
  export function getModel(
132
  provider: string,
133
  model: string,
@@ -170,6 +179,8 @@ export function getModel(
170
  return getXAIModel(apiKey, model);
171
  case 'Cohere':
172
  return getCohereAIModel(apiKey, model);
 
 
173
  default:
174
  return getOllamaModel(baseURL, model);
175
  }
 
128
  return openai(model);
129
  }
130
 
131
+ export function getPerplexityModel(apiKey: OptionalApiKey, model: string) {
132
+ const perplexity = createOpenAI({
133
+ baseURL: 'https://api.perplexity.ai/',
134
+ apiKey,
135
+ });
136
+
137
+ return perplexity(model);
138
+ }
139
+
140
  export function getModel(
141
  provider: string,
142
  model: string,
 
179
  return getXAIModel(apiKey, model);
180
  case 'Cohere':
181
  return getCohereAIModel(apiKey, model);
182
+ case 'Perplexity':
183
+ return getPerplexityModel(apiKey, model);
184
  default:
185
  return getOllamaModel(baseURL, model);
186
  }
app/utils/constants.ts CHANGED
@@ -293,6 +293,30 @@ const PROVIDER_LIST: ProviderInfo[] = [
293
  ],
294
  getApiKeyLink: 'https://api.together.xyz/settings/api-keys',
295
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  ];
297
 
298
  export const DEFAULT_PROVIDER = PROVIDER_LIST[0];
 
293
  ],
294
  getApiKeyLink: 'https://api.together.xyz/settings/api-keys',
295
  },
296
+ {
297
+ name: 'Perplexity',
298
+ staticModels: [
299
+ {
300
+ name: 'llama-3.1-sonar-small-128k-online',
301
+ label: 'Sonar Small Online',
302
+ provider: 'Perplexity',
303
+ maxTokenAllowed: 8192,
304
+ },
305
+ {
306
+ name: 'llama-3.1-sonar-large-128k-online',
307
+ label: 'Sonar Large Online',
308
+ provider: 'Perplexity',
309
+ maxTokenAllowed: 8192,
310
+ },
311
+ {
312
+ name: 'llama-3.1-sonar-huge-128k-online',
313
+ label: 'Sonar Huge Online',
314
+ provider: 'Perplexity',
315
+ maxTokenAllowed: 8192,
316
+ },
317
+ ],
318
+ getApiKeyLink: 'https://www.perplexity.ai/settings/api',
319
+ },
320
  ];
321
 
322
  export const DEFAULT_PROVIDER = PROVIDER_LIST[0];
worker-configuration.d.ts CHANGED
@@ -14,4 +14,5 @@ interface Env {
14
  GOOGLE_GENERATIVE_AI_API_KEY: string;
15
  MISTRAL_API_KEY: string;
16
  XAI_API_KEY: string;
 
17
  }
 
14
  GOOGLE_GENERATIVE_AI_API_KEY: string;
15
  MISTRAL_API_KEY: string;
16
  XAI_API_KEY: string;
17
+ PERPLEXITY_API_KEY: string;
18
  }