Skip to content

Commit

Permalink
chore(api): deprecate claude-1 models
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertCraigie authored and stainless-app[bot] committed Sep 4, 2024
1 parent 40ebb5f commit c7557f1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/resources/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ export class Messages extends APIResource {
body: MessageCreateParams,
options?: Core.RequestOptions,
): APIPromise<Message> | APIPromise<Stream<RawMessageStreamEvent>> {
if (body.model in DEPRECATED_MODELS) {
console.warn(
`The model '${body.model}' is deprecated and will reach end-of-life on ${
DEPRECATED_MODELS[body.model]
}\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`,
);
}
return this._client.post('/v1/messages', {
body,
timeout: (this._client as any)._options.timeout ?? 600000,
Expand Down Expand Up @@ -221,6 +228,18 @@ export type Model =
| 'claude-2.0'
| 'claude-instant-1.2';

type DeprecatedModelsType = {
[K in Model]?: string;
};

const DEPRECATED_MODELS: DeprecatedModelsType = {
'claude-1.3': 'November 6th, 2024',
'claude-1.3-100k': 'November 6th, 2024',
'claude-instant-1.1': 'November 6th, 2024',
'claude-instant-1.1-100k': 'November 6th, 2024',
'claude-instant-1.2': 'November 6th, 2024',
};

export interface RawContentBlockDeltaEvent {
delta: TextDelta | InputJSONDelta;

Expand Down
31 changes: 31 additions & 0 deletions tests/api-resources/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,34 @@ describe('resource messages', () => {
});
});
});

test('create: warns when using a deprecated model', async () => {
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation();

await client.messages.create({
max_tokens: 1024,
messages: [{ content: 'Hello, world', role: 'user' }],
model: 'claude-instant-1.2',
});

expect(consoleSpy).toHaveBeenCalledWith(
"The model 'claude-instant-1.2' is deprecated and will reach end-of-life on November 6th, 2024\n" +
'Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.',
);

consoleSpy.mockRestore();
});

test('create: does not warn for non-deprecated models', async () => {
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation();

await client.messages.create({
max_tokens: 1024,
messages: [{ content: 'Hello, world', role: 'user' }],
model: 'claude-3-5-sonnet-20240620',
});

expect(consoleSpy).not.toHaveBeenCalled();

consoleSpy.mockRestore();
});

0 comments on commit c7557f1

Please sign in to comment.