Skip to content

Commit c7a1fe4

Browse files
alecfhenry-langRPate97github-actions[bot]
authored
refresh token.js for new openai 4.1 models (#20)
Co-authored-by: Henry Langmack <henry.langmack@gmail.com> Co-authored-by: RPate97 <ryantpate97@gmail.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent c0f8221 commit c7a1fe4

File tree

6 files changed

+58
-2
lines changed

6 files changed

+58
-2
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
* Rebase with upstream/main
66
* Upgrade @libretto/openai to better handle streams.
77

8+
## 0.7.1
9+
10+
### Patch Changes
11+
12+
- 2fc6edd: Fix: resolve error where new anthropic models do not work due to hardcoded max token limit
13+
14+
## 0.7.0
15+
16+
### Minor Changes
17+
18+
- 9b53159: Add gpt 4.1 models
19+
820
## 0.6.0
921

1022
https://github.com/libretto-ai/token.js/pull/17

docs/providers/openai.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ main()
4242
| -------------------------- | --------------- | --------- | ----------- | ----------- | ---------------- | ----- |
4343
| gpt-4.5-preview |||||||
4444
| gpt-4.5-preview-2025-02-27 |||||||
45+
| gpt-4.1 |||||||
46+
| gpt-4.1-2025-04-14 |||||||
4547
| gpt-4o |||||||
4648
| gpt-4o-mini |||||||
4749
| gpt-4o-2024-05-13 |||||||

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@libretto/token.js",
3-
"version": "0.7.0",
3+
"version": "0.7.1",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/libretto-ai/token.js"

pull_request_template.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Thank you for your contribution! To help get your changes merged as quickly as possible, please fill out this template and confirm you've completed all of the pre-submission checks. You may remove this note from your PR if you'd like.
2+
3+
Cheers,
4+
Pate
5+
6+
### All Submissions (required):
7+
8+
* [ ] Have you read the [Contributing](https://github.com/token-js/token.js/blob/main/CONTRIBUTING.md) guidelines?
9+
* [ ] Have you updated the documentation with `pnpm docs`?
10+
* [ ] Have you ran the linter with `pnpm lint:fix`?
11+
* [ ] Have you successfully ran the tests locally with `pnpm test`?
12+
* [ ] Have you added a changeset file with `pnpm changeset`?
13+
* [ ] Please link any relevant GitHub issue here.
14+
15+
### New Feature Submissions (optional):
16+
17+
* [ ] Have you added new tests for your feature? Do those tests cover each model provider as applicable?
18+
* [ ] Please provide a summary of your new feature and the reasoning behind it here.
19+
20+
### Bug Fixes (optional):
21+
22+
* [ ] Have you added new regression tests to cover the bug?
23+
* [ ] Please provide replication steps for the bug here. For complex bugs, a repository that replicates the issue can also be linked here.

src/handlers/anthropic.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,17 @@ export const getDefaultMaxTokens = (model: string): number => {
348348
model === 'claude-instant-1.2'
349349
) {
350350
return 4096
351+
} else if (
352+
model === 'claude-3-5-sonnet-latest' ||
353+
model === 'claude-3-5-sonnet-20241022' ||
354+
model === 'claude-3-7-sonnet-latest' ||
355+
model === 'claude-3-7-sonnet-20250219' ||
356+
model === 'claude-3-5-haiku-20241022'
357+
) {
358+
return 8192
351359
} else {
352-
throw new InputError(`Unknown model: ${model}`)
360+
// We default to 8192 when the model is not specifically handled here to avoid throwing errors
361+
return 8192
353362
}
354363
}
355364

src/models.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export const models = {
1313
models: [
1414
'gpt-4.5-preview',
1515
'gpt-4.5-preview-2025-02-27',
16+
'gpt-4.1',
17+
'gpt-4.1-2025-04-14',
1618
'gpt-4o',
1719
'gpt-4o-mini',
1820
'gpt-4o-2024-05-13',
@@ -44,6 +46,8 @@ export const models = {
4446
] as const,
4547
supportsCompletion: true,
4648
supportsStreaming: [
49+
'gpt-4.1',
50+
'gpt-4.1-2025-04-14',
4751
'gpt-4.5-preview',
4852
'gpt-4.5-preview-2025-02-27',
4953
'gpt-4o',
@@ -72,6 +76,8 @@ export const models = {
7276
'o3-mini',
7377
] as const,
7478
supportsJSON: [
79+
'gpt-4.1',
80+
'gpt-4.1-2025-04-14',
7581
'gpt-4.5-preview',
7682
'gpt-4.5-preview-2025-02-27',
7783
'gpt-4o',
@@ -90,6 +96,8 @@ export const models = {
9096
'o3-mini',
9197
] as const,
9298
supportsImages: [
99+
'gpt-4.1',
100+
'gpt-4.1-2025-04-14',
93101
'gpt-4.5-preview',
94102
'gpt-4.5-preview-2025-02-27',
95103
'gpt-4o',
@@ -104,6 +112,8 @@ export const models = {
104112
'gpt-4-vision-preview',
105113
] as const,
106114
supportsToolCalls: [
115+
'gpt-4.1',
116+
'gpt-4.1-2025-04-14',
107117
'gpt-4.5-preview',
108118
'gpt-4.5-preview-2025-02-27',
109119
'gpt-4o',

0 commit comments

Comments
 (0)