Commit
·
d41a0ac
1
Parent(s):
9c657b9
Cohere support added
Browse files- .env.example +4 -0
- README.md +1 -1
- app/lib/.server/llm/api-key.ts +2 -0
- app/lib/.server/llm/constants.ts +1 -1
- app/lib/.server/llm/model.ts +14 -0
- app/utils/constants.ts +16 -0
- package.json +1 -0
- pnpm-lock.yaml +47 -0
.env.example
CHANGED
|
@@ -49,6 +49,10 @@ OPENAI_LIKE_API_KEY=
|
|
| 49 |
# You only need this environment variable set if you want to use Mistral models
|
| 50 |
MISTRAL_API_KEY=
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
# Get LMStudio Base URL from LM Studio Developer Console
|
| 54 |
# Make sure to enable CORS
|
|
|
|
| 49 |
# You only need this environment variable set if you want to use Mistral models
|
| 50 |
MISTRAL_API_KEY=
|
| 51 |
|
| 52 |
+
# Get the Cohere Api key by following these instructions -
|
| 53 |
+
# https://dashboard.cohere.com/api-keys
|
| 54 |
+
# You only need this environment variable set if you want to use Cohere models
|
| 55 |
+
COHERE_API_KEY=
|
| 56 |
|
| 57 |
# Get LMStudio Base URL from LM Studio Developer Console
|
| 58 |
# Make sure to enable CORS
|
README.md
CHANGED
|
@@ -39,7 +39,7 @@ https://thinktank.ottomator.ai
|
|
| 39 |
- ⬜ Azure Open AI API Integration
|
| 40 |
- ⬜ Perplexity Integration
|
| 41 |
- ⬜ Vertex AI Integration
|
| 42 |
-
-
|
| 43 |
- ⬜ Deploy directly to Vercel/Netlify/other similar platforms
|
| 44 |
- ⬜ Prompt caching
|
| 45 |
- ⬜ Better prompt enhancing
|
|
|
|
| 39 |
- ⬜ Azure Open AI API Integration
|
| 40 |
- ⬜ Perplexity Integration
|
| 41 |
- ⬜ Vertex AI Integration
|
| 42 |
+
- ✅ Cohere Integration
|
| 43 |
- ⬜ Deploy directly to Vercel/Netlify/other similar platforms
|
| 44 |
- ⬜ Prompt caching
|
| 45 |
- ⬜ Better prompt enhancing
|
app/lib/.server/llm/api-key.ts
CHANGED
|
@@ -35,6 +35,8 @@ export function getAPIKey(cloudflareEnv: Env, provider: string, userApiKeys?: Re
|
|
| 35 |
return env.OPENAI_LIKE_API_KEY || cloudflareEnv.OPENAI_LIKE_API_KEY;
|
| 36 |
case "xAI":
|
| 37 |
return env.XAI_API_KEY || cloudflareEnv.XAI_API_KEY;
|
|
|
|
|
|
|
| 38 |
default:
|
| 39 |
return "";
|
| 40 |
}
|
|
|
|
| 35 |
return env.OPENAI_LIKE_API_KEY || cloudflareEnv.OPENAI_LIKE_API_KEY;
|
| 36 |
case "xAI":
|
| 37 |
return env.XAI_API_KEY || cloudflareEnv.XAI_API_KEY;
|
| 38 |
+
case "Cohere":
|
| 39 |
+
return env.COHERE_API_KEY;
|
| 40 |
default:
|
| 41 |
return "";
|
| 42 |
}
|
app/lib/.server/llm/constants.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
// see https://docs.anthropic.com/en/docs/about-claude/models
|
| 2 |
-
export const MAX_TOKENS =
|
| 3 |
|
| 4 |
// limits the number of model responses that can be returned in a single request
|
| 5 |
export const MAX_RESPONSE_SEGMENTS = 2;
|
|
|
|
| 1 |
// see https://docs.anthropic.com/en/docs/about-claude/models
|
| 2 |
+
export const MAX_TOKENS = 4096;
|
| 3 |
|
| 4 |
// limits the number of model responses that can be returned in a single request
|
| 5 |
export const MAX_RESPONSE_SEGMENTS = 2;
|
app/lib/.server/llm/model.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { createGoogleGenerativeAI } from '@ai-sdk/google';
|
|
| 7 |
import { ollama } from 'ollama-ai-provider';
|
| 8 |
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
|
| 9 |
import { createMistral } from '@ai-sdk/mistral';
|
|
|
|
| 10 |
|
| 11 |
export function getAnthropicModel(apiKey: string, model: string) {
|
| 12 |
const anthropic = createAnthropic({
|
|
@@ -23,6 +24,15 @@ export function getOpenAILikeModel(baseURL:string,apiKey: string, model: string)
|
|
| 23 |
|
| 24 |
return openai(model);
|
| 25 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
export function getOpenAIModel(apiKey: string, model: string) {
|
| 27 |
const openai = createOpenAI({
|
| 28 |
apiKey,
|
|
@@ -108,6 +118,8 @@ export function getXAIModel(apiKey: string, model: string) {
|
|
| 108 |
|
| 109 |
return openai(model);
|
| 110 |
}
|
|
|
|
|
|
|
| 111 |
export function getModel(provider: string, model: string, env: Env, apiKeys?: Record<string, string>) {
|
| 112 |
const apiKey = getAPIKey(env, provider, apiKeys);
|
| 113 |
const baseURL = getBaseURL(env, provider);
|
|
@@ -135,6 +147,8 @@ export function getModel(provider: string, model: string, env: Env, apiKeys?: Re
|
|
| 135 |
return getLMStudioModel(baseURL, model);
|
| 136 |
case 'xAI':
|
| 137 |
return getXAIModel(apiKey, model);
|
|
|
|
|
|
|
| 138 |
default:
|
| 139 |
return getOllamaModel(baseURL, model);
|
| 140 |
}
|
|
|
|
| 7 |
import { ollama } from 'ollama-ai-provider';
|
| 8 |
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
|
| 9 |
import { createMistral } from '@ai-sdk/mistral';
|
| 10 |
+
import { createCohere } from '@ai-sdk/cohere'
|
| 11 |
|
| 12 |
export function getAnthropicModel(apiKey: string, model: string) {
|
| 13 |
const anthropic = createAnthropic({
|
|
|
|
| 24 |
|
| 25 |
return openai(model);
|
| 26 |
}
|
| 27 |
+
|
| 28 |
+
export function getCohereAIModel(apiKey:string, model: string){
|
| 29 |
+
const cohere = createCohere({
|
| 30 |
+
apiKey,
|
| 31 |
+
});
|
| 32 |
+
|
| 33 |
+
return cohere(model);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
export function getOpenAIModel(apiKey: string, model: string) {
|
| 37 |
const openai = createOpenAI({
|
| 38 |
apiKey,
|
|
|
|
| 118 |
|
| 119 |
return openai(model);
|
| 120 |
}
|
| 121 |
+
|
| 122 |
+
|
| 123 |
export function getModel(provider: string, model: string, env: Env, apiKeys?: Record<string, string>) {
|
| 124 |
const apiKey = getAPIKey(env, provider, apiKeys);
|
| 125 |
const baseURL = getBaseURL(env, provider);
|
|
|
|
| 147 |
return getLMStudioModel(baseURL, model);
|
| 148 |
case 'xAI':
|
| 149 |
return getXAIModel(apiKey, model);
|
| 150 |
+
case 'Cohere':
|
| 151 |
+
return getCohereAIModel(apiKey, model);
|
| 152 |
default:
|
| 153 |
return getOllamaModel(baseURL, model);
|
| 154 |
}
|
app/utils/constants.ts
CHANGED
|
@@ -33,6 +33,22 @@ const PROVIDER_LIST: ProviderInfo[] = [
|
|
| 33 |
staticModels: [],
|
| 34 |
getDynamicModels: getOpenAILikeModels
|
| 35 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
{
|
| 37 |
name: 'OpenRouter',
|
| 38 |
staticModels: [
|
|
|
|
| 33 |
staticModels: [],
|
| 34 |
getDynamicModels: getOpenAILikeModels
|
| 35 |
},
|
| 36 |
+
{
|
| 37 |
+
name: 'Cohere',
|
| 38 |
+
staticModels: [
|
| 39 |
+
{ name: 'command-r-plus-08-2024', label: 'Command R plus Latest', provider: 'Cohere' },
|
| 40 |
+
{ name: 'command-r-08-2024', label: 'Command R Latest', provider: 'Cohere' },
|
| 41 |
+
{ name: 'command-r-plus', label: 'Command R plus', provider: 'Cohere' },
|
| 42 |
+
{ name: 'command-r', label: 'Command R', provider: 'Cohere' },
|
| 43 |
+
{ name: 'command', label: 'Command', provider: 'Cohere' },
|
| 44 |
+
{ name: 'command-nightly', label: 'Command Nightly', provider: 'Cohere' },
|
| 45 |
+
{ name: 'command-light', label: 'Command Light', provider: 'Cohere' },
|
| 46 |
+
{ name: 'command-light-nightly', label: 'Command Light Nightly', provider: 'Cohere' },
|
| 47 |
+
{ name: 'c4ai-aya-expanse-8b', label: 'c4AI Aya Expanse 8b', provider: 'Cohere' },
|
| 48 |
+
{ name: 'c4ai-aya-expanse-32b', label: 'c4AI Aya Expanse 32b', provider: 'Cohere' },
|
| 49 |
+
],
|
| 50 |
+
getApiKeyLink: 'https://dashboard.cohere.com/api-keys'
|
| 51 |
+
},
|
| 52 |
{
|
| 53 |
name: 'OpenRouter',
|
| 54 |
staticModels: [
|
package.json
CHANGED
|
@@ -27,6 +27,7 @@
|
|
| 27 |
},
|
| 28 |
"dependencies": {
|
| 29 |
"@ai-sdk/anthropic": "^0.0.39",
|
|
|
|
| 30 |
"@ai-sdk/google": "^0.0.52",
|
| 31 |
"@ai-sdk/mistral": "^0.0.43",
|
| 32 |
"@ai-sdk/openai": "^0.0.66",
|
|
|
|
| 27 |
},
|
| 28 |
"dependencies": {
|
| 29 |
"@ai-sdk/anthropic": "^0.0.39",
|
| 30 |
+
"@ai-sdk/cohere": "^1.0.1",
|
| 31 |
"@ai-sdk/google": "^0.0.52",
|
| 32 |
"@ai-sdk/mistral": "^0.0.43",
|
| 33 |
"@ai-sdk/openai": "^0.0.66",
|
pnpm-lock.yaml
CHANGED
|
@@ -14,6 +14,9 @@ importers:
|
|
| 14 |
'@ai-sdk/anthropic':
|
| 15 |
specifier: ^0.0.39
|
| 16 |
version: 0.0.39([email protected])
|
|
|
|
|
|
|
|
|
|
| 17 |
'@ai-sdk/google':
|
| 18 |
specifier: ^0.0.52
|
| 19 |
version: 0.0.52([email protected])
|
|
@@ -279,6 +282,12 @@ packages:
|
|
| 279 |
peerDependencies:
|
| 280 |
zod: ^3.0.0
|
| 281 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
'@ai-sdk/[email protected]':
|
| 283 |
resolution: {integrity: sha512-bfsA/1Ae0SQ6NfLwWKs5SU4MBwlzJjVhK6bTVBicYFjUxg9liK/W76P1Tq/qK9OlrODACz3i1STOIWsFPpIOuQ==}
|
| 284 |
engines: {node: '>=18'}
|
|
@@ -324,6 +333,15 @@ packages:
|
|
| 324 |
zod:
|
| 325 |
optional: true
|
| 326 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
'@ai-sdk/[email protected]':
|
| 328 |
resolution: {integrity: sha512-oOwPQD8i2Ynpn22cur4sk26FW3mSy6t6/X/K1Ay2yGBKYiSpRyLfObhOrZEGsXDx+3euKy4nEZ193R36NM+tpQ==}
|
| 329 |
engines: {node: '>=18'}
|
|
@@ -336,6 +354,10 @@ packages:
|
|
| 336 |
resolution: {integrity: sha512-XMsNGJdGO+L0cxhhegtqZ8+T6nn4EoShS819OvCgI2kLbYTIvk0GWFGD0AXJmxkxs3DrpsJxKAFukFR7bvTkgQ==}
|
| 337 |
engines: {node: '>=18'}
|
| 338 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
'@ai-sdk/[email protected]':
|
| 340 |
resolution: {integrity: sha512-1asDpxgmeHWL0/EZPCLENxfOHT+0jce0z/zasRhascodm2S6f6/KZn5doLG9jdmarcb+GjMjFmmwyOVXz3W1xg==}
|
| 341 |
engines: {node: '>=18'}
|
|
@@ -3033,6 +3055,10 @@ packages:
|
|
| 3033 |
resolution: {integrity: sha512-v0eOBUbiaFojBu2s2NPBfYUoRR9GjcDNvCXVaqEf5vVfpIAh9f8RCo4vXTP8c63QRKCFwoLpMpTdPwwhEKVgzA==}
|
| 3034 |
engines: {node: '>=14.18'}
|
| 3035 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3036 | |
| 3037 |
resolution: {integrity: sha512-/f2Go4TognH/KvCISP7OUsHn85hT9nUkxxA9BEWxFn+Oj9o8ZNLm/40hdlgSLyuOimsrTKLUMEorQexp/aPQeA==}
|
| 3038 |
|
|
@@ -5687,6 +5713,12 @@ snapshots:
|
|
| 5687 |
'@ai-sdk/provider-utils': 1.0.9([email protected])
|
| 5688 |
zod: 3.23.8
|
| 5689 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5690 |
'@ai-sdk/[email protected]([email protected])':
|
| 5691 |
dependencies:
|
| 5692 |
'@ai-sdk/provider': 0.0.24
|
|
@@ -5733,6 +5765,15 @@ snapshots:
|
|
| 5733 |
optionalDependencies:
|
| 5734 |
zod: 3.23.8
|
| 5735 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5736 |
'@ai-sdk/[email protected]':
|
| 5737 |
dependencies:
|
| 5738 |
json-schema: 0.4.0
|
|
@@ -5745,6 +5786,10 @@ snapshots:
|
|
| 5745 |
dependencies:
|
| 5746 |
json-schema: 0.4.0
|
| 5747 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5748 |
'@ai-sdk/[email protected]([email protected])([email protected])':
|
| 5749 |
dependencies:
|
| 5750 |
'@ai-sdk/provider-utils': 1.0.20([email protected])
|
|
@@ -8751,6 +8796,8 @@ snapshots:
|
|
| 8751 |
|
| 8752 | |
| 8753 |
|
|
|
|
|
|
|
| 8754 | |
| 8755 |
dependencies:
|
| 8756 |
md5.js: 1.3.5
|
|
|
|
| 14 |
'@ai-sdk/anthropic':
|
| 15 |
specifier: ^0.0.39
|
| 16 |
version: 0.0.39([email protected])
|
| 17 |
+
'@ai-sdk/cohere':
|
| 18 |
+
specifier: ^1.0.1
|
| 19 |
+
version: 1.0.1([email protected])
|
| 20 |
'@ai-sdk/google':
|
| 21 |
specifier: ^0.0.52
|
| 22 |
version: 0.0.52([email protected])
|
|
|
|
| 282 |
peerDependencies:
|
| 283 |
zod: ^3.0.0
|
| 284 |
|
| 285 |
+
'@ai-sdk/[email protected]':
|
| 286 |
+
resolution: {integrity: sha512-xLaSYl/hs9EqfpvT9PvqZrDWjJPQPZBd0iT32T6812vN6kwuEQ6sSgQvqHWczIqxeej2GNRgMQwDL6Lh0L5pZw==}
|
| 287 |
+
engines: {node: '>=18'}
|
| 288 |
+
peerDependencies:
|
| 289 |
+
zod: ^3.0.0
|
| 290 |
+
|
| 291 |
'@ai-sdk/[email protected]':
|
| 292 |
resolution: {integrity: sha512-bfsA/1Ae0SQ6NfLwWKs5SU4MBwlzJjVhK6bTVBicYFjUxg9liK/W76P1Tq/qK9OlrODACz3i1STOIWsFPpIOuQ==}
|
| 293 |
engines: {node: '>=18'}
|
|
|
|
| 333 |
zod:
|
| 334 |
optional: true
|
| 335 |
|
| 336 |
+
'@ai-sdk/[email protected]':
|
| 337 |
+
resolution: {integrity: sha512-TNg7rPhRtETB2Z9F0JpOvpGii9Fs8EWM8nYy1jEkvSXkrPJ6b/9zVnDdaJsmLFDyrMbOsPJlkblYtmYEQou36w==}
|
| 338 |
+
engines: {node: '>=18'}
|
| 339 |
+
peerDependencies:
|
| 340 |
+
zod: ^3.0.0
|
| 341 |
+
peerDependenciesMeta:
|
| 342 |
+
zod:
|
| 343 |
+
optional: true
|
| 344 |
+
|
| 345 |
'@ai-sdk/[email protected]':
|
| 346 |
resolution: {integrity: sha512-oOwPQD8i2Ynpn22cur4sk26FW3mSy6t6/X/K1Ay2yGBKYiSpRyLfObhOrZEGsXDx+3euKy4nEZ193R36NM+tpQ==}
|
| 347 |
engines: {node: '>=18'}
|
|
|
|
| 354 |
resolution: {integrity: sha512-XMsNGJdGO+L0cxhhegtqZ8+T6nn4EoShS819OvCgI2kLbYTIvk0GWFGD0AXJmxkxs3DrpsJxKAFukFR7bvTkgQ==}
|
| 355 |
engines: {node: '>=18'}
|
| 356 |
|
| 357 |
+
'@ai-sdk/[email protected]':
|
| 358 |
+
resolution: {integrity: sha512-Sj29AzooJ7SYvhPd+AAWt/E7j63E9+AzRnoMHUaJPRYzOd/WDrVNxxv85prF9gDcQ7XPVlSk9j6oAZV9/DXYpA==}
|
| 359 |
+
engines: {node: '>=18'}
|
| 360 |
+
|
| 361 |
'@ai-sdk/[email protected]':
|
| 362 |
resolution: {integrity: sha512-1asDpxgmeHWL0/EZPCLENxfOHT+0jce0z/zasRhascodm2S6f6/KZn5doLG9jdmarcb+GjMjFmmwyOVXz3W1xg==}
|
| 363 |
engines: {node: '>=18'}
|
|
|
|
| 3055 |
resolution: {integrity: sha512-v0eOBUbiaFojBu2s2NPBfYUoRR9GjcDNvCXVaqEf5vVfpIAh9f8RCo4vXTP8c63QRKCFwoLpMpTdPwwhEKVgzA==}
|
| 3056 |
engines: {node: '>=14.18'}
|
| 3057 |
|
| 3058 | |
| 3059 |
+
resolution: {integrity: sha512-T1C0XCUimhxVQzW4zFipdx0SficT651NnkR0ZSH3yQwh+mFMdLfgjABVi4YtMTtaL4s168593DaoaRLMqryavA==}
|
| 3060 |
+
engines: {node: '>=18.0.0'}
|
| 3061 |
+
|
| 3062 | |
| 3063 |
resolution: {integrity: sha512-/f2Go4TognH/KvCISP7OUsHn85hT9nUkxxA9BEWxFn+Oj9o8ZNLm/40hdlgSLyuOimsrTKLUMEorQexp/aPQeA==}
|
| 3064 |
|
|
|
|
| 5713 |
'@ai-sdk/provider-utils': 1.0.9([email protected])
|
| 5714 |
zod: 3.23.8
|
| 5715 |
|
| 5716 |
+
'@ai-sdk/[email protected]([email protected])':
|
| 5717 |
+
dependencies:
|
| 5718 |
+
'@ai-sdk/provider': 1.0.0
|
| 5719 |
+
'@ai-sdk/provider-utils': 2.0.1([email protected])
|
| 5720 |
+
zod: 3.23.8
|
| 5721 |
+
|
| 5722 |
'@ai-sdk/[email protected]([email protected])':
|
| 5723 |
dependencies:
|
| 5724 |
'@ai-sdk/provider': 0.0.24
|
|
|
|
| 5765 |
optionalDependencies:
|
| 5766 |
zod: 3.23.8
|
| 5767 |
|
| 5768 |
+
'@ai-sdk/[email protected]([email protected])':
|
| 5769 |
+
dependencies:
|
| 5770 |
+
'@ai-sdk/provider': 1.0.0
|
| 5771 |
+
eventsource-parser: 3.0.0
|
| 5772 |
+
nanoid: 3.3.7
|
| 5773 |
+
secure-json-parse: 2.7.0
|
| 5774 |
+
optionalDependencies:
|
| 5775 |
+
zod: 3.23.8
|
| 5776 |
+
|
| 5777 |
'@ai-sdk/[email protected]':
|
| 5778 |
dependencies:
|
| 5779 |
json-schema: 0.4.0
|
|
|
|
| 5786 |
dependencies:
|
| 5787 |
json-schema: 0.4.0
|
| 5788 |
|
| 5789 |
+
'@ai-sdk/[email protected]':
|
| 5790 |
+
dependencies:
|
| 5791 |
+
json-schema: 0.4.0
|
| 5792 |
+
|
| 5793 |
'@ai-sdk/[email protected]([email protected])([email protected])':
|
| 5794 |
dependencies:
|
| 5795 |
'@ai-sdk/provider-utils': 1.0.20([email protected])
|
|
|
|
| 8796 |
|
| 8797 | |
| 8798 |
|
| 8799 |
+
[email protected]: {}
|
| 8800 |
+
|
| 8801 | |
| 8802 |
dependencies:
|
| 8803 |
md5.js: 1.3.5
|