From 6424924b6361e54f07c04fce9075ab16fcb712fb Mon Sep 17 00:00:00 2001 From: Stainless Bot Date: Tue, 1 Oct 2024 17:52:44 +0000 Subject: [PATCH] feat(api): support storing chat completions, enabling evals and model distillation in the dashboard (#1112) Learn more at http://openai.com/devday2024 --- src/resources/chat/chat.ts | 1 + src/resources/chat/completions.ts | 20 ++++++++++++++-- src/resources/completions.ts | 25 ++++++++++++++++++++ tests/api-resources/chat/completions.test.ts | 2 ++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/resources/chat/chat.ts b/src/resources/chat/chat.ts index 1a758fbb5..5bc7de955 100644 --- a/src/resources/chat/chat.ts +++ b/src/resources/chat/chat.ts @@ -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' diff --git a/src/resources/chat/completions.ts b/src/resources/chat/completions.ts index f426ce36f..27aebdc4c 100644 --- a/src/resources/chat/completions.ts +++ b/src/resources/chat/completions.ts @@ -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; @@ -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 | 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 @@ -889,6 +899,12 @@ export interface ChatCompletionCreateParamsBase { */ stop?: string | null | Array; + /** + * 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 diff --git a/src/resources/completions.ts b/src/resources/completions.ts index 152496766..7acd5d13f 100644 --- a/src/resources/completions.ts +++ b/src/resources/completions.ts @@ -125,6 +125,11 @@ 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 { @@ -132,11 +137,31 @@ 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; diff --git a/tests/api-resources/chat/completions.test.ts b/tests/api-resources/chat/completions.test.ts index 692b953f2..4f015b47e 100644 --- a/tests/api-resources/chat/completions.test.ts +++ b/tests/api-resources/chat/completions.test.ts @@ -34,6 +34,7 @@ describe('resource completions', () => { logprobs: true, max_completion_tokens: 0, max_tokens: 0, + metadata: { foo: 'string' }, n: 1, parallel_tool_calls: true, presence_penalty: -2, @@ -41,6 +42,7 @@ describe('resource completions', () => { seed: -9007199254740991, service_tier: 'auto', stop: 'string', + store: true, stream: false, stream_options: { include_usage: true }, temperature: 1,