Skip to content

Commit

Permalink
chore: update models 2024-06 (#58)
Browse files Browse the repository at this point in the history
* chore: update mistral models

* chore: update anthropic models

* chore: update SDKs

* refactor: self code review
  • Loading branch information
mdjastrzebski authored Jul 2, 2024
1 parent 86d3571 commit 847dd11
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 39 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@
"registry": "https://registry.npmjs.org/"
},
"dependencies": {
"@anthropic-ai/sdk": "^0.20.8",
"@anthropic-ai/sdk": "^0.24.3",
"@inkjs/ui": "^1.0.0",
"@mistralai/mistralai": "^0.1.3",
"@mistralai/mistralai": "^0.5.0",
"chalk": "^5.3.0",
"date-fns": "^3.6.0",
"dotenv": "^16.4.5",
"ink": "^4.4.1",
"ink-link": "^3.0.0",
"ink-text-input": "^5.0.1",
"openai": "^4.42.0",
"openai": "^4.52.2",
"prompts": "^2.4.2",
"react": "^18.2.0",
"redent": "^4.0.0",
"tiktoken": "^1.0.14",
"tiktoken": "^1.0.15",
"update-notifier": "^7.0.0",
"yargs": "^17.7.2",
"zod": "^3.23.6",
Expand Down
16 changes: 11 additions & 5 deletions src/engine/providers/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ const Anthropic: Provider = {
name: 'anthropic',
apiKeyUrl: 'https://console.anthropic.com/settings/keys',

// Anthropic models: https://docs.anthropic.com/claude/docs/models-overview
defaultModel: 'claude-3-sonnet-20240229',
// Anthropic models: https://docs.anthropic.com/en/docs/about-claude/models
defaultModel: 'claude-3-5-sonnet-20240620',

// Price per 1M tokens [input, output].
// Source: https://www.anthropic.com/api
// Source: https://docs.anthropic.com/en/docs/about-claude/models
modelPricing: {
'claude-3-haiku-20240307': { inputTokensCost: 0.25, outputTokensCost: 1.25 },
'claude-3-5-sonnet-20240620': { inputTokensCost: 3.0, outputTokensCost: 15.0 },
'claude-3-sonnet-20240229': { inputTokensCost: 3.0, outputTokensCost: 15.0 },
'claude-3-opus-20240229': { inputTokensCost: 15.0, outputTokensCost: 75.0 },
'claude-2.1': { inputTokensCost: 8.0, outputTokensCost: 24.0 },
Expand All @@ -31,7 +32,7 @@ const Anthropic: Provider = {

modelAliases: {
haiku: 'claude-3-haiku-20240307',
sonnet: 'claude-3-sonnet-20240229',
sonnet: 'claude-3-5-sonnet-20240620',
opus: 'claude-3-opus-20240229',
},

Expand All @@ -55,10 +56,15 @@ const Anthropic: Provider = {
});
const responseTime = performance.now() - startTime;

const firstContent = response.content[0];
if (firstContent?.type !== 'text') {
throw new Error(`Received unexpected content type from Anthropic API: ${firstContent?.type}`);
}

return {
message: {
role: 'assistant',
content: response.content[0]?.text ?? '',
content: firstContent.text,
},
usage: {
inputTokens: response.usage.input_tokens,
Expand Down
17 changes: 7 additions & 10 deletions src/engine/providers/mistral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ import { estimateInputTokens, estimateOutputTokens } from '../tokenizer.js';
import { responseStyles, type ProviderConfig } from './config.js';
import type { Provider } from './provider.js';

// Mistral provides output data in the last chunk.
interface ChunkWithUsage extends ChatCompletionResponseChunk {
usage?: {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
};
}

const Mistral: Provider = {
label: 'Mistral',
name: 'mistral',
Expand All @@ -28,8 +19,13 @@ const Mistral: Provider = {
'open-mixtral-8x7b': { inputTokensCost: 0.7, outputTokensCost: 0.7 },
'open-mixtral-8x22b': { inputTokensCost: 2, outputTokensCost: 6 },
'mistral-small-latest': { inputTokensCost: 1, outputTokensCost: 3 },
'mistral-small-2402': { inputTokensCost: 1, outputTokensCost: 3 },
'mistral-medium-latest': { inputTokensCost: 2.7, outputTokensCost: 8.1 },
'mistral-medium-2312': { inputTokensCost: 2.7, outputTokensCost: 8.1 },
'mistral-large-latest': { inputTokensCost: 4, outputTokensCost: 12 },
'mistral-large-2402': { inputTokensCost: 4, outputTokensCost: 12 },
'codestral-latest': { inputTokensCost: 1, outputTokensCost: 3 },
'codestral-2405': { inputTokensCost: 1, outputTokensCost: 3 },
},

modelAliases: {
Expand All @@ -38,6 +34,7 @@ const Mistral: Provider = {
small: 'mistral-small-latest',
medium: 'mistral-medium-latest',
large: 'mistral-large-latest',
codestral: 'codestral-latest',
},

getChatCompletion: async (config: ProviderConfig, messages: Message[]) => {
Expand Down Expand Up @@ -83,7 +80,7 @@ const Mistral: Provider = {
...getMistralResponseStyle(config),
});

let lastChunk: ChunkWithUsage | null = null;
let lastChunk: ChatCompletionResponseChunk | null = null;
let content = '';
for await (const chunk of stream) {
lastChunk = chunk;
Expand Down
40 changes: 20 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ __metadata:
languageName: node
linkType: hard

"@anthropic-ai/sdk@npm:^0.20.8":
version: 0.20.8
resolution: "@anthropic-ai/sdk@npm:0.20.8"
"@anthropic-ai/sdk@npm:^0.24.3":
version: 0.24.3
resolution: "@anthropic-ai/sdk@npm:0.24.3"
dependencies:
"@types/node": "npm:^18.11.18"
"@types/node-fetch": "npm:^2.6.4"
Expand All @@ -44,7 +44,7 @@ __metadata:
formdata-node: "npm:^4.3.2"
node-fetch: "npm:^2.6.7"
web-streams-polyfill: "npm:^3.2.1"
checksum: 10/3f771a7e4b106a114bf417019324376d0881da8b2a90801c3e56554b0bcaf5233e54e24dad3bba7ba419c4068893ef0f268922c43fc55dc13cac5d2a26cd2281
checksum: 10/afc865e89a49b4608f4c3db3ad05dcecbfd8799236788d798d690338cf3301c2dec6654671573dc681091339357e285e3ae3988652c9133dbb09c1cc8a4820ae
languageName: node
linkType: hard

Expand Down Expand Up @@ -694,10 +694,10 @@ __metadata:
version: 0.0.0-use.local
resolution: "@callstack/ai-cli@workspace:."
dependencies:
"@anthropic-ai/sdk": "npm:^0.20.8"
"@anthropic-ai/sdk": "npm:^0.24.3"
"@callstack/eslint-config": "npm:^14.1.1"
"@inkjs/ui": "npm:^1.0.0"
"@mistralai/mistralai": "npm:^0.1.3"
"@mistralai/mistralai": "npm:^0.5.0"
"@release-it/conventional-changelog": "npm:^5.1.1"
"@types/jest": "npm:^29.5.12"
"@types/mock-fs": "npm:^4.13.4"
Expand All @@ -718,13 +718,13 @@ __metadata:
ink-text-input: "npm:^5.0.1"
jest: "npm:^29.7.0"
mock-fs: "npm:^5.2.0"
openai: "npm:^4.42.0"
openai: "npm:^4.52.2"
prettier: "npm:^3.2.5"
prompts: "npm:^2.4.2"
react: "npm:^18.2.0"
redent: "npm:^4.0.0"
release-it: "npm:^15.11.0"
tiktoken: "npm:^1.0.14"
tiktoken: "npm:^1.0.15"
typescript: "npm:^5.4.5"
update-notifier: "npm:^7.0.0"
yargs: "npm:^17.7.2"
Expand Down Expand Up @@ -1192,12 +1192,12 @@ __metadata:
languageName: node
linkType: hard

"@mistralai/mistralai@npm:^0.1.3":
version: 0.1.3
resolution: "@mistralai/mistralai@npm:0.1.3"
"@mistralai/mistralai@npm:^0.5.0":
version: 0.5.0
resolution: "@mistralai/mistralai@npm:0.5.0"
dependencies:
node-fetch: "npm:^2.6.7"
checksum: 10/e4bbdea881c543eb54a7d8557016689f421b67205e5d553fbe3c7e36c6883478c32cef9f4ed6cbfd1cdc795ac7c3d3dd9f8a324e25bbf6b58c5cbbf70ae277c2
checksum: 10/788e4b6d4bb124131272beea1079081f4b279befc8608ac4fcf0efa147f524c48e4af4b68414c6f71a32704eaf0c9c6d5550634ed6be8a9bcf9cc8d15d55161a
languageName: node
linkType: hard

Expand Down Expand Up @@ -7357,9 +7357,9 @@ __metadata:
languageName: node
linkType: hard

"openai@npm:^4.42.0":
version: 4.42.0
resolution: "openai@npm:4.42.0"
"openai@npm:^4.52.2":
version: 4.52.2
resolution: "openai@npm:4.52.2"
dependencies:
"@types/node": "npm:^18.11.18"
"@types/node-fetch": "npm:^2.6.4"
Expand All @@ -7371,7 +7371,7 @@ __metadata:
web-streams-polyfill: "npm:^3.2.1"
bin:
openai: bin/cli
checksum: 10/e550ebdd6e805c4743d840bc1e223d1f3d98526c6edec697517d0ed3732b4fcc898b22ac28929bf448e0b2f91542bf6de4dafa1c7f0a466616e016ea865d5a43
checksum: 10/2c240dbcf8e14ce2121207809edf3844bca28c21095ffc9b58dd8279b2d68b3552da707ee2a529258581d8a4d39a448f1f4152b52eed456065280792cc1904c8
languageName: node
linkType: hard

Expand Down Expand Up @@ -9100,10 +9100,10 @@ __metadata:
languageName: node
linkType: hard

"tiktoken@npm:^1.0.14":
version: 1.0.14
resolution: "tiktoken@npm:1.0.14"
checksum: 10/14600edfc5f12753524f91a21ff3b70eaaa450c932efb1ce668d31658e7ab9495910ef3c47256a50705af231d628034a1307b03055ca1f68f4a0b6711868bed2
"tiktoken@npm:^1.0.15":
version: 1.0.15
resolution: "tiktoken@npm:1.0.15"
checksum: 10/8bca51e6e6c095319ecf2ff39afb1556141c785e7f213d5235c71a5ef2fc96a9ded19c77499d04d3173c5a92cd29f3e49effa95b80497ead5d69b5c0c762a635
languageName: node
linkType: hard

Expand Down

0 comments on commit 847dd11

Please sign in to comment.