Cohere support added

This commit is contained in:
Raiyan Hasan
2024-11-20 15:08:42 +00:00
parent 9c657b962b
commit d41a0ac2c2
8 changed files with 86 additions and 2 deletions

View File

@@ -35,6 +35,8 @@ export function getAPIKey(cloudflareEnv: Env, provider: string, userApiKeys?: Re
return env.OPENAI_LIKE_API_KEY || cloudflareEnv.OPENAI_LIKE_API_KEY;
case "xAI":
return env.XAI_API_KEY || cloudflareEnv.XAI_API_KEY;
case "Cohere":
return env.COHERE_API_KEY;
default:
return "";
}

View File

@@ -1,5 +1,5 @@
// see https://docs.anthropic.com/en/docs/about-claude/models
export const MAX_TOKENS = 8000;
export const MAX_TOKENS = 4096;
// limits the number of model responses that can be returned in a single request
export const MAX_RESPONSE_SEGMENTS = 2;

View File

@@ -7,6 +7,7 @@ import { createGoogleGenerativeAI } from '@ai-sdk/google';
import { ollama } from 'ollama-ai-provider';
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
import { createMistral } from '@ai-sdk/mistral';
import { createCohere } from '@ai-sdk/cohere'
export function getAnthropicModel(apiKey: string, model: string) {
const anthropic = createAnthropic({
@@ -23,6 +24,15 @@ export function getOpenAILikeModel(baseURL:string,apiKey: string, model: string)
return openai(model);
}
export function getCohereAIModel(apiKey:string, model: string){
const cohere = createCohere({
apiKey,
});
return cohere(model);
}
export function getOpenAIModel(apiKey: string, model: string) {
const openai = createOpenAI({
apiKey,
@@ -108,6 +118,8 @@ export function getXAIModel(apiKey: string, model: string) {
return openai(model);
}
export function getModel(provider: string, model: string, env: Env, apiKeys?: Record<string, string>) {
const apiKey = getAPIKey(env, provider, apiKeys);
const baseURL = getBaseURL(env, provider);
@@ -135,6 +147,8 @@ export function getModel(provider: string, model: string, env: Env, apiKeys?: Re
return getLMStudioModel(baseURL, model);
case 'xAI':
return getXAIModel(apiKey, model);
case 'Cohere':
return getCohereAIModel(apiKey, model);
default:
return getOllamaModel(baseURL, model);
}

View File

@@ -33,6 +33,22 @@ const PROVIDER_LIST: ProviderInfo[] = [
staticModels: [],
getDynamicModels: getOpenAILikeModels
},
{
name: 'Cohere',
staticModels: [
{ name: 'command-r-plus-08-2024', label: 'Command R plus Latest', provider: 'Cohere' },
{ name: 'command-r-08-2024', label: 'Command R Latest', provider: 'Cohere' },
{ name: 'command-r-plus', label: 'Command R plus', provider: 'Cohere' },
{ name: 'command-r', label: 'Command R', provider: 'Cohere' },
{ name: 'command', label: 'Command', provider: 'Cohere' },
{ name: 'command-nightly', label: 'Command Nightly', provider: 'Cohere' },
{ name: 'command-light', label: 'Command Light', provider: 'Cohere' },
{ name: 'command-light-nightly', label: 'Command Light Nightly', provider: 'Cohere' },
{ name: 'c4ai-aya-expanse-8b', label: 'c4AI Aya Expanse 8b', provider: 'Cohere' },
{ name: 'c4ai-aya-expanse-32b', label: 'c4AI Aya Expanse 32b', provider: 'Cohere' },
],
getApiKeyLink: 'https://dashboard.cohere.com/api-keys'
},
{
name: 'OpenRouter',
staticModels: [