Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): support storing chat completions, enabling evals and model distillation in the dashboard #1112

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 68
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-8ad878332083dd506a478a293db78dc9e7b1b2124f2682e1d991225bc5bbcc3b.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-52b934aee6468039ec7f4ce046a282b5fbce114afc708e70f17121df654f71da.yml
1 change: 1 addition & 0 deletions src/resources/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type ChatModel =
| 'gpt-4o'
| 'gpt-4o-2024-08-06'
| 'gpt-4o-2024-05-13'
| 'gpt-4o-realtime-preview-2024-10-01'
| 'chatgpt-4o-latest'
| 'gpt-4o-mini'
| 'gpt-4o-mini-2024-07-18'
Expand Down
20 changes: 18 additions & 2 deletions src/resources/chat/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,12 @@ export type ChatCompletionCreateParams =

export interface ChatCompletionCreateParamsBase {
/**
* A list of messages comprising the conversation so far.
* [Example Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models).
* A list of messages comprising the conversation so far. Depending on the
* [model](https://platform.openai.com/docs/models) you use, different message
* types (modalities) are supported, like
* [text](https://platform.openai.com/docs/guides/text-generation),
* [images](https://platform.openai.com/docs/guides/vision), and
* [audio](https://platform.openai.com/docs/guides/audio).
*/
messages: Array<ChatCompletionMessageParam>;

Expand Down Expand Up @@ -806,6 +810,12 @@ export interface ChatCompletionCreateParamsBase {
*/
max_tokens?: number | null;

/**
* Developer-defined tags and values used for filtering completions in the
* [dashboard](https://platform.openai.com/completions).
*/
metadata?: Record<string, string> | null;

/**
* How many chat completion choices to generate for each input message. Note that
* you will be charged based on the number of generated tokens across all of the
Expand Down Expand Up @@ -889,6 +899,12 @@ export interface ChatCompletionCreateParamsBase {
*/
stop?: string | null | Array<string>;

/**
* Whether or not to store the output of this completion request for traffic
* logging in the [dashboard](https://platform.openai.com/completions).
*/
store?: boolean | null;

/**
* If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
* sent as data-only
Expand Down
25 changes: 25 additions & 0 deletions src/resources/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,43 @@ export interface CompletionUsage {
* Breakdown of tokens used in a completion.
*/
completion_tokens_details?: CompletionUsage.CompletionTokensDetails;

/**
* Breakdown of tokens used in the prompt.
*/
prompt_tokens_details?: CompletionUsage.PromptTokensDetails;
}

export namespace CompletionUsage {
/**
* Breakdown of tokens used in a completion.
*/
export interface CompletionTokensDetails {
/**
* Audio input tokens generated by the model.
*/
audio_tokens?: number;

/**
* Tokens generated by the model for reasoning.
*/
reasoning_tokens?: number;
}

/**
* Breakdown of tokens used in the prompt.
*/
export interface PromptTokensDetails {
/**
* Audio input tokens present in the prompt.
*/
audio_tokens?: number;

/**
* Cached tokens present in the prompt.
*/
cached_tokens?: number;
}
}

export type CompletionCreateParams = CompletionCreateParamsNonStreaming | CompletionCreateParamsStreaming;
Expand Down
2 changes: 2 additions & 0 deletions tests/api-resources/chat/completions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ describe('resource completions', () => {
logprobs: true,
max_completion_tokens: 0,
max_tokens: 0,
metadata: { foo: 'string' },
n: 1,
parallel_tool_calls: true,
presence_penalty: -2,
response_format: { type: 'text' },
seed: -9007199254740991,
service_tier: 'auto',
stop: 'string',
store: true,
stream: false,
stream_options: { include_usage: true },
temperature: 1,
Expand Down