Skip to content

Commit

Permalink
refactor: extract model out to a named type and rename partialjson (#477
Browse files Browse the repository at this point in the history
)
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Jul 24, 2024
1 parent a8ca93c commit d2d4e36
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 2
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-e38cd52aed438cef6e0a25eeeab8ff6000583c3cf152a10f0c3610ceb3da7b4e.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-5903ec2fd4efd7f261908bc4ec8ecd6b19cb9efa79637ad273583f1b763f80fd.yml
3 changes: 2 additions & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ Types:
- <code><a href="./src/resources/messages.ts">ContentBlockStartEvent</a></code>
- <code><a href="./src/resources/messages.ts">ContentBlockStopEvent</a></code>
- <code><a href="./src/resources/messages.ts">ImageBlockParam</a></code>
- <code><a href="./src/resources/messages.ts">InputJsonDelta</a></code>
- <code><a href="./src/resources/messages.ts">InputJSONDelta</a></code>
- <code><a href="./src/resources/messages.ts">Message</a></code>
- <code><a href="./src/resources/messages.ts">MessageDeltaEvent</a></code>
- <code><a href="./src/resources/messages.ts">MessageDeltaUsage</a></code>
- <code><a href="./src/resources/messages.ts">MessageParam</a></code>
- <code><a href="./src/resources/messages.ts">MessageStartEvent</a></code>
- <code><a href="./src/resources/messages.ts">MessageStopEvent</a></code>
- <code><a href="./src/resources/messages.ts">MessageStreamEvent</a></code>
- <code><a href="./src/resources/messages.ts">Model</a></code>
- <code><a href="./src/resources/messages.ts">RawContentBlockDeltaEvent</a></code>
- <code><a href="./src/resources/messages.ts">RawContentBlockStartEvent</a></code>
- <code><a href="./src/resources/messages.ts">RawContentBlockStopEvent</a></code>
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,15 @@ export namespace Anthropic {
export import ContentBlockStartEvent = API.ContentBlockStartEvent;
export import ContentBlockStopEvent = API.ContentBlockStopEvent;
export import ImageBlockParam = API.ImageBlockParam;
export import InputJsonDelta = API.InputJsonDelta;
export import InputJSONDelta = API.InputJSONDelta;
export import Message = API.Message;
export import MessageDeltaEvent = API.MessageDeltaEvent;
export import MessageDeltaUsage = API.MessageDeltaUsage;
export import MessageParam = API.MessageParam;
export import MessageStartEvent = API.MessageStartEvent;
export import MessageStopEvent = API.MessageStopEvent;
export import MessageStreamEvent = API.MessageStreamEvent;
export import Model = API.Model;
export import RawContentBlockDeltaEvent = API.RawContentBlockDeltaEvent;
export import RawContentBlockStartEvent = API.RawContentBlockStartEvent;
export import RawContentBlockStopEvent = API.RawContentBlockStopEvent;
Expand Down
14 changes: 8 additions & 6 deletions src/resources/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { APIResource } from '../resource';
import { APIPromise } from '../core';
import * as Core from '../core';
import * as CompletionsAPI from './completions';
import * as MessagesAPI from './messages';
import { Stream } from '../streaming';

export class Completions extends APIResource {
Expand Down Expand Up @@ -53,9 +54,11 @@ export interface Completion {
completion: string;

/**
* The model that handled the request.
* The model that will complete your prompt.\n\nSee
* [models](https://docs.anthropic.com/en/docs/models-overview) for additional
* details and options.
*/
model: string;
model: MessagesAPI.Model;

/**
* The reason that we stopped.
Expand Down Expand Up @@ -88,12 +91,11 @@ export interface CompletionCreateParamsBase {
max_tokens_to_sample: number;

/**
* The model that will complete your prompt.
*
* See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
* The model that will complete your prompt.\n\nSee
* [models](https://docs.anthropic.com/en/docs/models-overview) for additional
* details and options.
*/
model: (string & {}) | 'claude-2.0' | 'claude-2.1' | 'claude-instant-1.2';
model: MessagesAPI.Model;

/**
* The prompt that you want Claude to complete.
Expand Down
3 changes: 2 additions & 1 deletion src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ export {
ContentBlockStartEvent,
ContentBlockStopEvent,
ImageBlockParam,
InputJsonDelta,
InputJSONDelta,
Message,
MessageDeltaEvent,
MessageDeltaUsage,
MessageParam,
MessageStartEvent,
MessageStopEvent,
MessageStreamEvent,
Model,
RawContentBlockDeltaEvent,
RawContentBlockStartEvent,
RawContentBlockStopEvent,
Expand Down
43 changes: 26 additions & 17 deletions src/resources/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export namespace ImageBlockParam {
}
}

export interface InputJsonDelta {
export interface InputJSONDelta {
partial_json: string;

type: 'input_json_delta';
Expand Down Expand Up @@ -123,9 +123,11 @@ export interface Message {
content: Array<ContentBlock>;

/**
* The model that handled the request.
* The model that will complete your prompt.\n\nSee
* [models](https://docs.anthropic.com/en/docs/models-overview) for additional
* details and options.
*/
model: string;
model: Model;

/**
* Conversational role of the generated message.
Expand Down Expand Up @@ -202,8 +204,23 @@ export type MessageStopEvent = RawMessageStopEvent;

export type MessageStreamEvent = RawMessageStreamEvent;

/**
* The model that will complete your prompt.\n\nSee
* [models](https://docs.anthropic.com/en/docs/models-overview) for additional
* details and options.
*/
export type Model =
| (string & {})
| 'claude-3-5-sonnet-20240620'
| 'claude-3-opus-20240229'
| 'claude-3-sonnet-20240229'
| 'claude-3-haiku-20240307'
| 'claude-2.1'
| 'claude-2.0'
| 'claude-instant-1.2';

export interface RawContentBlockDeltaEvent {
delta: TextDelta | InputJsonDelta;
delta: TextDelta | InputJSONDelta;

index: number;

Expand Down Expand Up @@ -473,20 +490,11 @@ export interface MessageCreateParamsBase {
messages: Array<MessageParam>;

/**
* The model that will complete your prompt.
*
* See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
* The model that will complete your prompt.\n\nSee
* [models](https://docs.anthropic.com/en/docs/models-overview) for additional
* details and options.
*/
model:
| (string & {})
| 'claude-3-5-sonnet-20240620'
| 'claude-3-opus-20240229'
| 'claude-3-sonnet-20240229'
| 'claude-3-haiku-20240307'
| 'claude-2.1'
| 'claude-2.0'
| 'claude-instant-1.2';
model: Model;

/**
* An object describing metadata about the request.
Expand Down Expand Up @@ -714,14 +722,15 @@ export namespace Messages {
export import ContentBlockStartEvent = MessagesAPI.ContentBlockStartEvent;
export import ContentBlockStopEvent = MessagesAPI.ContentBlockStopEvent;
export import ImageBlockParam = MessagesAPI.ImageBlockParam;
export import InputJsonDelta = MessagesAPI.InputJsonDelta;
export import InputJSONDelta = MessagesAPI.InputJSONDelta;
export import Message = MessagesAPI.Message;
export import MessageDeltaEvent = MessagesAPI.MessageDeltaEvent;
export import MessageDeltaUsage = MessagesAPI.MessageDeltaUsage;
export import MessageParam = MessagesAPI.MessageParam;
export import MessageStartEvent = MessagesAPI.MessageStartEvent;
export import MessageStopEvent = MessagesAPI.MessageStopEvent;
export import MessageStreamEvent = MessagesAPI.MessageStreamEvent;
export import Model = MessagesAPI.Model;
export import RawContentBlockDeltaEvent = MessagesAPI.RawContentBlockDeltaEvent;
export import RawContentBlockStartEvent = MessagesAPI.RawContentBlockStartEvent;
export import RawContentBlockStopEvent = MessagesAPI.RawContentBlockStopEvent;
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/completions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('resource completions', () => {
test('create: only required params', async () => {
const responsePromise = anthropic.completions.create({
max_tokens_to_sample: 256,
model: 'claude-2.1',
model: 'string',
prompt: '\n\nHuman: Hello, world!\n\nAssistant:',
});
const rawResponse = await responsePromise.asResponse();
Expand All @@ -27,7 +27,7 @@ describe('resource completions', () => {
test('create: required and optional params', async () => {
const response = await anthropic.completions.create({
max_tokens_to_sample: 256,
model: 'claude-2.1',
model: 'string',
prompt: '\n\nHuman: Hello, world!\n\nAssistant:',
metadata: { user_id: '13803d75-b4b5-4c3e-b2a2-6f21399b021b' },
stop_sequences: ['string', 'string', 'string'],
Expand Down

0 comments on commit d2d4e36

Please sign in to comment.