Commit 7c8c1115
Changed files (9)
src
openai
resources
beta
chat
chat
tests
api_resources
src/openai/resources/beta/chat/completions.py
@@ -69,12 +69,14 @@ class Completions(SyncAPIResource):
logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
max_completion_tokens: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
+ metadata: Optional[Dict[str, str]] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
seed: Optional[int] | NotGiven = NOT_GIVEN,
service_tier: Optional[Literal["auto", "default"]] | NotGiven = NOT_GIVEN,
stop: Union[Optional[str], List[str]] | NotGiven = NOT_GIVEN,
+ store: Optional[bool] | NotGiven = NOT_GIVEN,
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
@@ -158,6 +160,7 @@ class Completions(SyncAPIResource):
"logprobs": logprobs,
"max_completion_tokens": max_completion_tokens,
"max_tokens": max_tokens,
+ "metadata": metadata,
"n": n,
"parallel_tool_calls": parallel_tool_calls,
"presence_penalty": presence_penalty,
@@ -165,6 +168,7 @@ class Completions(SyncAPIResource):
"seed": seed,
"service_tier": service_tier,
"stop": stop,
+ "store": store,
"stream": False,
"stream_options": stream_options,
"temperature": temperature,
@@ -202,12 +206,14 @@ class Completions(SyncAPIResource):
logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
max_completion_tokens: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
+ metadata: Optional[Dict[str, str]] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
seed: Optional[int] | NotGiven = NOT_GIVEN,
service_tier: Optional[Literal["auto", "default"]] | NotGiven = NOT_GIVEN,
stop: Union[Optional[str], List[str]] | NotGiven = NOT_GIVEN,
+ store: Optional[bool] | NotGiven = NOT_GIVEN,
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
@@ -262,11 +268,13 @@ class Completions(SyncAPIResource):
logprobs=logprobs,
max_completion_tokens=max_completion_tokens,
max_tokens=max_tokens,
+ metadata=metadata,
n=n,
parallel_tool_calls=parallel_tool_calls,
presence_penalty=presence_penalty,
seed=seed,
service_tier=service_tier,
+ store=store,
stop=stop,
stream_options=stream_options,
temperature=temperature,
@@ -320,12 +328,14 @@ class AsyncCompletions(AsyncAPIResource):
logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
max_completion_tokens: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
+ metadata: Optional[Dict[str, str]] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
seed: Optional[int] | NotGiven = NOT_GIVEN,
service_tier: Optional[Literal["auto", "default"]] | NotGiven = NOT_GIVEN,
stop: Union[Optional[str], List[str]] | NotGiven = NOT_GIVEN,
+ store: Optional[bool] | NotGiven = NOT_GIVEN,
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
@@ -409,12 +419,14 @@ class AsyncCompletions(AsyncAPIResource):
"logprobs": logprobs,
"max_completion_tokens": max_completion_tokens,
"max_tokens": max_tokens,
+ "metadata": metadata,
"n": n,
"parallel_tool_calls": parallel_tool_calls,
"presence_penalty": presence_penalty,
"response_format": _type_to_response_format(response_format),
"seed": seed,
"service_tier": service_tier,
+ "store": store,
"stop": stop,
"stream": False,
"stream_options": stream_options,
@@ -453,12 +465,14 @@ class AsyncCompletions(AsyncAPIResource):
logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
max_completion_tokens: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
+ metadata: Optional[Dict[str, str]] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
seed: Optional[int] | NotGiven = NOT_GIVEN,
service_tier: Optional[Literal["auto", "default"]] | NotGiven = NOT_GIVEN,
stop: Union[Optional[str], List[str]] | NotGiven = NOT_GIVEN,
+ store: Optional[bool] | NotGiven = NOT_GIVEN,
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
@@ -514,12 +528,14 @@ class AsyncCompletions(AsyncAPIResource):
logprobs=logprobs,
max_completion_tokens=max_completion_tokens,
max_tokens=max_tokens,
+ metadata=metadata,
n=n,
parallel_tool_calls=parallel_tool_calls,
presence_penalty=presence_penalty,
seed=seed,
service_tier=service_tier,
stop=stop,
+ store=store,
stream_options=stream_options,
temperature=temperature,
tool_choice=tool_choice,
src/openai/resources/chat/completions.py
@@ -66,6 +66,7 @@ class Completions(SyncAPIResource):
logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
max_completion_tokens: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
+ metadata: Optional[Dict[str, str]] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
@@ -73,6 +74,7 @@ class Completions(SyncAPIResource):
seed: Optional[int] | NotGiven = NOT_GIVEN,
service_tier: Optional[Literal["auto", "default"]] | NotGiven = NOT_GIVEN,
stop: Union[Optional[str], List[str]] | NotGiven = NOT_GIVEN,
+ store: Optional[bool] | NotGiven = NOT_GIVEN,
stream: Optional[Literal[False]] | NotGiven = NOT_GIVEN,
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
@@ -92,8 +94,12 @@ class Completions(SyncAPIResource):
Creates a model response for the given chat conversation.
Args:
- messages: A list of messages comprising the conversation so far.
- [Example Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models).
+ messages: 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).
model: ID of the model to use. See the
[model endpoint compatibility](https://platform.openai.com/docs/models/model-endpoint-compatibility)
@@ -145,6 +151,9 @@ class Completions(SyncAPIResource):
compatible with
[o1 series models](https://platform.openai.com/docs/guides/reasoning).
+ metadata: Developer-defined tags and values used for filtering completions in the
+ [dashboard](https://platform.openai.com/completions).
+
n: 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
choices. Keep `n` as `1` to minimize costs.
@@ -204,6 +213,9 @@ class Completions(SyncAPIResource):
stop: Up to 4 sequences where the API will stop generating further tokens.
+ store: Whether or not to store the output of this completion request for traffic
+ logging in the [dashboard](https://platform.openai.com/completions).
+
stream: If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
sent as data-only
[server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
@@ -271,6 +283,7 @@ class Completions(SyncAPIResource):
logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
max_completion_tokens: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
+ metadata: Optional[Dict[str, str]] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
@@ -278,6 +291,7 @@ class Completions(SyncAPIResource):
seed: Optional[int] | NotGiven = NOT_GIVEN,
service_tier: Optional[Literal["auto", "default"]] | NotGiven = NOT_GIVEN,
stop: Union[Optional[str], List[str]] | NotGiven = NOT_GIVEN,
+ store: Optional[bool] | NotGiven = NOT_GIVEN,
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
@@ -296,8 +310,12 @@ class Completions(SyncAPIResource):
Creates a model response for the given chat conversation.
Args:
- messages: A list of messages comprising the conversation so far.
- [Example Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models).
+ messages: 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).
model: ID of the model to use. See the
[model endpoint compatibility](https://platform.openai.com/docs/models/model-endpoint-compatibility)
@@ -356,6 +374,9 @@ class Completions(SyncAPIResource):
compatible with
[o1 series models](https://platform.openai.com/docs/guides/reasoning).
+ metadata: Developer-defined tags and values used for filtering completions in the
+ [dashboard](https://platform.openai.com/completions).
+
n: 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
choices. Keep `n` as `1` to minimize costs.
@@ -415,6 +436,9 @@ class Completions(SyncAPIResource):
stop: Up to 4 sequences where the API will stop generating further tokens.
+ store: Whether or not to store the output of this completion request for traffic
+ logging in the [dashboard](https://platform.openai.com/completions).
+
stream_options: Options for streaming response. Only set this when you set `stream: true`.
temperature: What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
@@ -475,6 +499,7 @@ class Completions(SyncAPIResource):
logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
max_completion_tokens: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
+ metadata: Optional[Dict[str, str]] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
@@ -482,6 +507,7 @@ class Completions(SyncAPIResource):
seed: Optional[int] | NotGiven = NOT_GIVEN,
service_tier: Optional[Literal["auto", "default"]] | NotGiven = NOT_GIVEN,
stop: Union[Optional[str], List[str]] | NotGiven = NOT_GIVEN,
+ store: Optional[bool] | NotGiven = NOT_GIVEN,
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
@@ -500,8 +526,12 @@ class Completions(SyncAPIResource):
Creates a model response for the given chat conversation.
Args:
- messages: A list of messages comprising the conversation so far.
- [Example Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models).
+ messages: 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).
model: ID of the model to use. See the
[model endpoint compatibility](https://platform.openai.com/docs/models/model-endpoint-compatibility)
@@ -560,6 +590,9 @@ class Completions(SyncAPIResource):
compatible with
[o1 series models](https://platform.openai.com/docs/guides/reasoning).
+ metadata: Developer-defined tags and values used for filtering completions in the
+ [dashboard](https://platform.openai.com/completions).
+
n: 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
choices. Keep `n` as `1` to minimize costs.
@@ -619,6 +652,9 @@ class Completions(SyncAPIResource):
stop: Up to 4 sequences where the API will stop generating further tokens.
+ store: Whether or not to store the output of this completion request for traffic
+ logging in the [dashboard](https://platform.openai.com/completions).
+
stream_options: Options for streaming response. Only set this when you set `stream: true`.
temperature: What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
@@ -678,6 +714,7 @@ class Completions(SyncAPIResource):
logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
max_completion_tokens: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
+ metadata: Optional[Dict[str, str]] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
@@ -685,6 +722,7 @@ class Completions(SyncAPIResource):
seed: Optional[int] | NotGiven = NOT_GIVEN,
service_tier: Optional[Literal["auto", "default"]] | NotGiven = NOT_GIVEN,
stop: Union[Optional[str], List[str]] | NotGiven = NOT_GIVEN,
+ store: Optional[bool] | NotGiven = NOT_GIVEN,
stream: Optional[Literal[False]] | Literal[True] | NotGiven = NOT_GIVEN,
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
@@ -714,6 +752,7 @@ class Completions(SyncAPIResource):
"logprobs": logprobs,
"max_completion_tokens": max_completion_tokens,
"max_tokens": max_tokens,
+ "metadata": metadata,
"n": n,
"parallel_tool_calls": parallel_tool_calls,
"presence_penalty": presence_penalty,
@@ -721,6 +760,7 @@ class Completions(SyncAPIResource):
"seed": seed,
"service_tier": service_tier,
"stop": stop,
+ "store": store,
"stream": stream,
"stream_options": stream_options,
"temperature": temperature,
@@ -774,6 +814,7 @@ class AsyncCompletions(AsyncAPIResource):
logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
max_completion_tokens: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
+ metadata: Optional[Dict[str, str]] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
@@ -781,6 +822,7 @@ class AsyncCompletions(AsyncAPIResource):
seed: Optional[int] | NotGiven = NOT_GIVEN,
service_tier: Optional[Literal["auto", "default"]] | NotGiven = NOT_GIVEN,
stop: Union[Optional[str], List[str]] | NotGiven = NOT_GIVEN,
+ store: Optional[bool] | NotGiven = NOT_GIVEN,
stream: Optional[Literal[False]] | NotGiven = NOT_GIVEN,
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
@@ -800,8 +842,12 @@ class AsyncCompletions(AsyncAPIResource):
Creates a model response for the given chat conversation.
Args:
- messages: A list of messages comprising the conversation so far.
- [Example Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models).
+ messages: 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).
model: ID of the model to use. See the
[model endpoint compatibility](https://platform.openai.com/docs/models/model-endpoint-compatibility)
@@ -853,6 +899,9 @@ class AsyncCompletions(AsyncAPIResource):
compatible with
[o1 series models](https://platform.openai.com/docs/guides/reasoning).
+ metadata: Developer-defined tags and values used for filtering completions in the
+ [dashboard](https://platform.openai.com/completions).
+
n: 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
choices. Keep `n` as `1` to minimize costs.
@@ -912,6 +961,9 @@ class AsyncCompletions(AsyncAPIResource):
stop: Up to 4 sequences where the API will stop generating further tokens.
+ store: Whether or not to store the output of this completion request for traffic
+ logging in the [dashboard](https://platform.openai.com/completions).
+
stream: If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
sent as data-only
[server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
@@ -979,6 +1031,7 @@ class AsyncCompletions(AsyncAPIResource):
logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
max_completion_tokens: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
+ metadata: Optional[Dict[str, str]] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
@@ -986,6 +1039,7 @@ class AsyncCompletions(AsyncAPIResource):
seed: Optional[int] | NotGiven = NOT_GIVEN,
service_tier: Optional[Literal["auto", "default"]] | NotGiven = NOT_GIVEN,
stop: Union[Optional[str], List[str]] | NotGiven = NOT_GIVEN,
+ store: Optional[bool] | NotGiven = NOT_GIVEN,
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
@@ -1004,8 +1058,12 @@ class AsyncCompletions(AsyncAPIResource):
Creates a model response for the given chat conversation.
Args:
- messages: A list of messages comprising the conversation so far.
- [Example Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models).
+ messages: 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).
model: ID of the model to use. See the
[model endpoint compatibility](https://platform.openai.com/docs/models/model-endpoint-compatibility)
@@ -1064,6 +1122,9 @@ class AsyncCompletions(AsyncAPIResource):
compatible with
[o1 series models](https://platform.openai.com/docs/guides/reasoning).
+ metadata: Developer-defined tags and values used for filtering completions in the
+ [dashboard](https://platform.openai.com/completions).
+
n: 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
choices. Keep `n` as `1` to minimize costs.
@@ -1123,6 +1184,9 @@ class AsyncCompletions(AsyncAPIResource):
stop: Up to 4 sequences where the API will stop generating further tokens.
+ store: Whether or not to store the output of this completion request for traffic
+ logging in the [dashboard](https://platform.openai.com/completions).
+
stream_options: Options for streaming response. Only set this when you set `stream: true`.
temperature: What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
@@ -1183,6 +1247,7 @@ class AsyncCompletions(AsyncAPIResource):
logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
max_completion_tokens: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
+ metadata: Optional[Dict[str, str]] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
@@ -1190,6 +1255,7 @@ class AsyncCompletions(AsyncAPIResource):
seed: Optional[int] | NotGiven = NOT_GIVEN,
service_tier: Optional[Literal["auto", "default"]] | NotGiven = NOT_GIVEN,
stop: Union[Optional[str], List[str]] | NotGiven = NOT_GIVEN,
+ store: Optional[bool] | NotGiven = NOT_GIVEN,
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
@@ -1208,8 +1274,12 @@ class AsyncCompletions(AsyncAPIResource):
Creates a model response for the given chat conversation.
Args:
- messages: A list of messages comprising the conversation so far.
- [Example Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models).
+ messages: 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).
model: ID of the model to use. See the
[model endpoint compatibility](https://platform.openai.com/docs/models/model-endpoint-compatibility)
@@ -1268,6 +1338,9 @@ class AsyncCompletions(AsyncAPIResource):
compatible with
[o1 series models](https://platform.openai.com/docs/guides/reasoning).
+ metadata: Developer-defined tags and values used for filtering completions in the
+ [dashboard](https://platform.openai.com/completions).
+
n: 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
choices. Keep `n` as `1` to minimize costs.
@@ -1327,6 +1400,9 @@ class AsyncCompletions(AsyncAPIResource):
stop: Up to 4 sequences where the API will stop generating further tokens.
+ store: Whether or not to store the output of this completion request for traffic
+ logging in the [dashboard](https://platform.openai.com/completions).
+
stream_options: Options for streaming response. Only set this when you set `stream: true`.
temperature: What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
@@ -1386,6 +1462,7 @@ class AsyncCompletions(AsyncAPIResource):
logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
max_completion_tokens: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
+ metadata: Optional[Dict[str, str]] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
@@ -1393,6 +1470,7 @@ class AsyncCompletions(AsyncAPIResource):
seed: Optional[int] | NotGiven = NOT_GIVEN,
service_tier: Optional[Literal["auto", "default"]] | NotGiven = NOT_GIVEN,
stop: Union[Optional[str], List[str]] | NotGiven = NOT_GIVEN,
+ store: Optional[bool] | NotGiven = NOT_GIVEN,
stream: Optional[Literal[False]] | Literal[True] | NotGiven = NOT_GIVEN,
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
@@ -1422,6 +1500,7 @@ class AsyncCompletions(AsyncAPIResource):
"logprobs": logprobs,
"max_completion_tokens": max_completion_tokens,
"max_tokens": max_tokens,
+ "metadata": metadata,
"n": n,
"parallel_tool_calls": parallel_tool_calls,
"presence_penalty": presence_penalty,
@@ -1429,6 +1508,7 @@ class AsyncCompletions(AsyncAPIResource):
"seed": seed,
"service_tier": service_tier,
"stop": stop,
+ "store": store,
"stream": stream,
"stream_options": stream_options,
"temperature": temperature,
src/openai/types/chat/completion_create_params.py
@@ -30,7 +30,11 @@ class CompletionCreateParamsBase(TypedDict, total=False):
messages: Required[Iterable[ChatCompletionMessageParam]]
"""A list of messages comprising the conversation so far.
- [Example Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models).
+ 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).
"""
model: Required[Union[str, ChatModel]]
@@ -105,6 +109,12 @@ class CompletionCreateParamsBase(TypedDict, total=False):
[o1 series models](https://platform.openai.com/docs/guides/reasoning).
"""
+ metadata: Optional[Dict[str, str]]
+ """
+ Developer-defined tags and values used for filtering completions in the
+ [dashboard](https://platform.openai.com/completions).
+ """
+
n: Optional[int]
"""How many chat completion choices to generate for each input message.
@@ -183,6 +193,12 @@ class CompletionCreateParamsBase(TypedDict, total=False):
stop: Union[Optional[str], List[str]]
"""Up to 4 sequences where the API will stop generating further tokens."""
+ store: Optional[bool]
+ """
+ Whether or not to store the output of this completion request for traffic
+ logging in the [dashboard](https://platform.openai.com/completions).
+ """
+
stream_options: Optional[ChatCompletionStreamOptionsParam]
"""Options for streaming response. Only set this when you set `stream: true`."""
src/openai/types/chat_model.py
@@ -12,6 +12,7 @@ ChatModel: TypeAlias = Literal[
"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",
src/openai/types/completion_usage.py
@@ -4,14 +4,25 @@ from typing import Optional
from .._models import BaseModel
-__all__ = ["CompletionUsage", "CompletionTokensDetails"]
+__all__ = ["CompletionUsage", "CompletionTokensDetails", "PromptTokensDetails"]
class CompletionTokensDetails(BaseModel):
+ audio_tokens: Optional[int] = None
+ """Audio input tokens generated by the model."""
+
reasoning_tokens: Optional[int] = None
"""Tokens generated by the model for reasoning."""
+class PromptTokensDetails(BaseModel):
+ audio_tokens: Optional[int] = None
+ """Audio input tokens present in the prompt."""
+
+ cached_tokens: Optional[int] = None
+ """Cached tokens present in the prompt."""
+
+
class CompletionUsage(BaseModel):
completion_tokens: int
"""Number of tokens in the generated completion."""
@@ -24,3 +35,6 @@ class CompletionUsage(BaseModel):
completion_tokens_details: Optional[CompletionTokensDetails] = None
"""Breakdown of tokens used in a completion."""
+
+ prompt_tokens_details: Optional[PromptTokensDetails] = None
+ """Breakdown of tokens used in the prompt."""
tests/api_resources/chat/test_completions.py
@@ -57,6 +57,7 @@ class TestCompletions:
logprobs=True,
max_completion_tokens=0,
max_tokens=0,
+ metadata={"foo": "string"},
n=1,
parallel_tool_calls=True,
presence_penalty=-2,
@@ -64,6 +65,7 @@ class TestCompletions:
seed=-9007199254740991,
service_tier="auto",
stop="string",
+ store=True,
stream=False,
stream_options={"include_usage": True},
temperature=1,
@@ -178,6 +180,7 @@ class TestCompletions:
logprobs=True,
max_completion_tokens=0,
max_tokens=0,
+ metadata={"foo": "string"},
n=1,
parallel_tool_calls=True,
presence_penalty=-2,
@@ -185,6 +188,7 @@ class TestCompletions:
seed=-9007199254740991,
service_tier="auto",
stop="string",
+ store=True,
stream_options={"include_usage": True},
temperature=1,
tool_choice="none",
@@ -318,6 +322,7 @@ class TestAsyncCompletions:
logprobs=True,
max_completion_tokens=0,
max_tokens=0,
+ metadata={"foo": "string"},
n=1,
parallel_tool_calls=True,
presence_penalty=-2,
@@ -325,6 +330,7 @@ class TestAsyncCompletions:
seed=-9007199254740991,
service_tier="auto",
stop="string",
+ store=True,
stream=False,
stream_options={"include_usage": True},
temperature=1,
@@ -439,6 +445,7 @@ class TestAsyncCompletions:
logprobs=True,
max_completion_tokens=0,
max_tokens=0,
+ metadata={"foo": "string"},
n=1,
parallel_tool_calls=True,
presence_penalty=-2,
@@ -446,6 +453,7 @@ class TestAsyncCompletions:
seed=-9007199254740991,
service_tier="auto",
stop="string",
+ store=True,
stream_options={"include_usage": True},
temperature=1,
tool_choice="none",
tests/lib/chat/test_completions.py
@@ -76,8 +76,9 @@ recommend checking a reliable weather website or app like the Weather Channel or
system_fingerprint='fp_b40fb1c6fb',
usage=CompletionUsage(
completion_tokens=37,
- completion_tokens_details=CompletionTokensDetails(reasoning_tokens=0),
+ completion_tokens_details=CompletionTokensDetails(audio_tokens=None, reasoning_tokens=0),
prompt_tokens=14,
+ prompt_tokens_details=None,
total_tokens=51
)
)
@@ -136,8 +137,9 @@ ParsedChatCompletion[Location](
system_fingerprint='fp_5050236cbd',
usage=CompletionUsage(
completion_tokens=14,
- completion_tokens_details=CompletionTokensDetails(reasoning_tokens=0),
+ completion_tokens_details=CompletionTokensDetails(audio_tokens=None, reasoning_tokens=0),
prompt_tokens=79,
+ prompt_tokens_details=None,
total_tokens=93
)
)
@@ -198,8 +200,9 @@ ParsedChatCompletion[Location](
system_fingerprint='fp_b40fb1c6fb',
usage=CompletionUsage(
completion_tokens=14,
- completion_tokens_details=CompletionTokensDetails(reasoning_tokens=0),
+ completion_tokens_details=CompletionTokensDetails(audio_tokens=None, reasoning_tokens=0),
prompt_tokens=88,
+ prompt_tokens_details=None,
total_tokens=102
)
)
@@ -385,8 +388,9 @@ ParsedChatCompletion[CalendarEvent](
system_fingerprint='fp_7568d46099',
usage=CompletionUsage(
completion_tokens=17,
- completion_tokens_details=CompletionTokensDetails(reasoning_tokens=0),
+ completion_tokens_details=CompletionTokensDetails(audio_tokens=None, reasoning_tokens=0),
prompt_tokens=92,
+ prompt_tokens_details=None,
total_tokens=109
)
)
@@ -829,8 +833,9 @@ ParsedChatCompletion[Location](
system_fingerprint='fp_5050236cbd',
usage=CompletionUsage(
completion_tokens=14,
- completion_tokens_details=CompletionTokensDetails(reasoning_tokens=0),
+ completion_tokens_details=CompletionTokensDetails(audio_tokens=None, reasoning_tokens=0),
prompt_tokens=79,
+ prompt_tokens_details=None,
total_tokens=93
)
)
@@ -897,8 +902,9 @@ ParsedChatCompletion[Location](
system_fingerprint='fp_5050236cbd',
usage=CompletionUsage(
completion_tokens=14,
- completion_tokens_details=CompletionTokensDetails(reasoning_tokens=0),
+ completion_tokens_details=CompletionTokensDetails(audio_tokens=None, reasoning_tokens=0),
prompt_tokens=79,
+ prompt_tokens_details=None,
total_tokens=93
)
)
tests/lib/chat/test_completions_streaming.py
@@ -155,8 +155,9 @@ ParsedChatCompletion[Location](
system_fingerprint='fp_5050236cbd',
usage=CompletionUsage(
completion_tokens=14,
- completion_tokens_details=CompletionTokensDetails(reasoning_tokens=0),
+ completion_tokens_details=CompletionTokensDetails(audio_tokens=None, reasoning_tokens=0),
prompt_tokens=79,
+ prompt_tokens_details=None,
total_tokens=93
)
)
.stats.yml
@@ -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