- Add comprehensive Moonshot AI provider with 11 models including: * Legacy moonshot-v1 series (8k, 32k, 128k context) * Latest Kimi K2 models (K2 Preview, Turbo, Thinking) * Vision-enabled models for multimodal capabilities * Auto-selecting model variants - Update xAI provider with latest Grok models: * Add Grok 4 (256K context) and Grok 4 (07-09) variant * Add Grok 3 Mini Beta and Mini Fast Beta variants * Update context limits to match actual model capabilities * Remove outdated grok-beta and grok-2-1212 models - Add MOONSHOT_API_KEY to environment configuration - Register Moonshot provider in service status monitoring - Full OpenAI-compatible API integration via api.moonshot.ai - Fix TypeScript errors in GitHub provider 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <noreply@anthropic.com>
64 lines
1.6 KiB
TypeScript
64 lines
1.6 KiB
TypeScript
import { BaseProvider } from '~/lib/modules/llm/base-provider';
|
|
import type { ModelInfo } from '~/lib/modules/llm/types';
|
|
import type { IProviderSetting } from '~/types/model';
|
|
import type { LanguageModelV1 } from 'ai';
|
|
import { createOpenAI } from '@ai-sdk/openai';
|
|
|
|
export default class PerplexityProvider extends BaseProvider {
|
|
name = 'Perplexity';
|
|
getApiKeyLink = 'https://www.perplexity.ai/settings/api';
|
|
|
|
config = {
|
|
apiTokenKey: 'PERPLEXITY_API_KEY',
|
|
};
|
|
|
|
staticModels: ModelInfo[] = [
|
|
{
|
|
name: 'sonar',
|
|
label: 'Sonar',
|
|
provider: 'Perplexity',
|
|
maxTokenAllowed: 8192,
|
|
},
|
|
{
|
|
name: 'sonar-pro',
|
|
label: 'Sonar Pro',
|
|
provider: 'Perplexity',
|
|
maxTokenAllowed: 8192,
|
|
},
|
|
{
|
|
name: 'sonar-reasoning-pro',
|
|
label: 'Sonar Reasoning Pro',
|
|
provider: 'Perplexity',
|
|
maxTokenAllowed: 8192,
|
|
},
|
|
];
|
|
|
|
getModelInstance(options: {
|
|
model: string;
|
|
serverEnv: Env;
|
|
apiKeys?: Record<string, string>;
|
|
providerSettings?: Record<string, IProviderSetting>;
|
|
}): LanguageModelV1 {
|
|
const { model, serverEnv, apiKeys, providerSettings } = options;
|
|
|
|
const { apiKey } = this.getProviderBaseUrlAndKey({
|
|
apiKeys,
|
|
providerSettings: providerSettings?.[this.name],
|
|
serverEnv: serverEnv as any,
|
|
defaultBaseUrlKey: '',
|
|
defaultApiTokenKey: 'PERPLEXITY_API_KEY',
|
|
});
|
|
|
|
if (!apiKey) {
|
|
throw new Error(`Missing API key for ${this.name} provider`);
|
|
}
|
|
|
|
const perplexity = createOpenAI({
|
|
baseURL: 'https://api.perplexity.ai/',
|
|
apiKey,
|
|
});
|
|
|
|
return perplexity(model);
|
|
}
|
|
}
|