completions
The completions
module provides access to the legacy chat endpoint, /v1/completions
. Use the chat.completions
module instead for new applications.
You should not use this module for new projects. The legacy /v1/completions
endpoint this module interacts with no longer receives updates and is expected to be deprecated. Use this module only in applications that require compatibility with the legacy endpoint.
You're strongly encouraged to migrate existing applications to the chat.completions
module—which interacts with the current (non-legacy) /v1/chat/completions
endpoint—prior to the deprecation of the /v1/completions
endpoint.
Classes:
Name | Description |
---|---|
AsyncCompletions |
|
AsyncCompletionsWithRawResponse |
|
AsyncCompletionsWithStreamingResponse |
|
Completions |
|
CompletionsWithRawResponse |
|
CompletionsWithStreamingResponse |
|
AsyncCompletions
AsyncCompletions(client: AsyncOpenAI)
Methods:
Name | Description |
---|---|
create |
Creates a completion for the provided prompt and parameters. |
with_raw_response |
|
with_streaming_response |
|
create
async
create(
*,
model: Union[
str,
Literal[
"gpt-3.5-turbo-instruct",
"davinci-002",
"babbage-002",
],
],
prompt: Union[
str,
List[str],
Iterable[int],
Iterable[Iterable[int]],
None,
],
best_of: Optional[int] | NotGiven = NOT_GIVEN,
echo: Optional[bool] | NotGiven = NOT_GIVEN,
frequency_penalty: (
Optional[float] | NotGiven
) = NOT_GIVEN,
logit_bias: (
Optional[Dict[str, int]] | NotGiven
) = NOT_GIVEN,
logprobs: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
presence_penalty: (
Optional[float] | NotGiven
) = NOT_GIVEN,
seed: Optional[int] | NotGiven = NOT_GIVEN,
stop: (
Union[Optional[str], List[str], None] | NotGiven
) = NOT_GIVEN,
stream: Optional[Literal[False]] | NotGiven = NOT_GIVEN,
suffix: Optional[str] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
top_p: Optional[float] | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Completion
create(
*,
model: Union[
str,
Literal[
"gpt-3.5-turbo-instruct",
"davinci-002",
"babbage-002",
],
],
prompt: Union[
str,
List[str],
Iterable[int],
Iterable[Iterable[int]],
None,
],
stream: Literal[True],
best_of: Optional[int] | NotGiven = NOT_GIVEN,
echo: Optional[bool] | NotGiven = NOT_GIVEN,
frequency_penalty: (
Optional[float] | NotGiven
) = NOT_GIVEN,
logit_bias: (
Optional[Dict[str, int]] | NotGiven
) = NOT_GIVEN,
logprobs: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
presence_penalty: (
Optional[float] | NotGiven
) = NOT_GIVEN,
seed: Optional[int] | NotGiven = NOT_GIVEN,
stop: (
Union[Optional[str], List[str], None] | NotGiven
) = NOT_GIVEN,
suffix: Optional[str] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
top_p: Optional[float] | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> AsyncStream[Completion]
create(
*,
model: Union[
str,
Literal[
"gpt-3.5-turbo-instruct",
"davinci-002",
"babbage-002",
],
],
prompt: Union[
str,
List[str],
Iterable[int],
Iterable[Iterable[int]],
None,
],
stream: bool,
best_of: Optional[int] | NotGiven = NOT_GIVEN,
echo: Optional[bool] | NotGiven = NOT_GIVEN,
frequency_penalty: (
Optional[float] | NotGiven
) = NOT_GIVEN,
logit_bias: (
Optional[Dict[str, int]] | NotGiven
) = NOT_GIVEN,
logprobs: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
presence_penalty: (
Optional[float] | NotGiven
) = NOT_GIVEN,
seed: Optional[int] | NotGiven = NOT_GIVEN,
stop: (
Union[Optional[str], List[str], None] | NotGiven
) = NOT_GIVEN,
suffix: Optional[str] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
top_p: Optional[float] | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Completion | AsyncStream[Completion]
create(
*,
model: Union[
str,
Literal[
"gpt-3.5-turbo-instruct",
"davinci-002",
"babbage-002",
],
],
prompt: Union[
str,
List[str],
Iterable[int],
Iterable[Iterable[int]],
None,
],
best_of: Optional[int] | NotGiven = NOT_GIVEN,
echo: Optional[bool] | NotGiven = NOT_GIVEN,
frequency_penalty: (
Optional[float] | NotGiven
) = NOT_GIVEN,
logit_bias: (
Optional[Dict[str, int]] | NotGiven
) = NOT_GIVEN,
logprobs: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
presence_penalty: (
Optional[float] | NotGiven
) = NOT_GIVEN,
seed: Optional[int] | NotGiven = NOT_GIVEN,
stop: (
Union[Optional[str], List[str], None] | NotGiven
) = NOT_GIVEN,
stream: (
Optional[Literal[False]] | Literal[True] | NotGiven
) = NOT_GIVEN,
suffix: Optional[str] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
top_p: Optional[float] | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Completion | AsyncStream[Completion]
Creates a completion for the provided prompt and parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Union[str, Literal['gpt-3.5-turbo-instruct', 'davinci-002', 'babbage-002']]
|
ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them. |
required |
prompt
|
Union[str, List[str], Iterable[int], Iterable[Iterable[int]], None]
|
The prompt(s) to generate completions for, encoded as a string, array of strings, array of tokens, or array of token arrays. Note that <|endoftext|> is the document separator that the model sees during training, so if a prompt is not specified the model will generate as if from the beginning of a new document. |
required |
best_of
|
Optional[int] | NotGiven
|
Generates When used with Note: Because this parameter generates many completions, it can quickly
consume your token quota. Use carefully and ensure that you have reasonable
settings for |
NOT_GIVEN
|
echo
|
Optional[bool] | NotGiven
|
Echo back the prompt in addition to the completion |
NOT_GIVEN
|
frequency_penalty
|
Optional[float] | NotGiven
|
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. See more information about frequency and presence penalties. |
NOT_GIVEN
|
logit_bias
|
Optional[Dict[str, int]] | NotGiven
|
Modify the likelihood of specified tokens appearing in the completion. Accepts a JSON object that maps tokens (specified by their token ID in the GPT tokenizer) to an associated bias value from -100 to 100. You can use this tokenizer tool to convert text to token IDs. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token. As an example, you can pass |
NOT_GIVEN
|
logprobs
|
Optional[int] | NotGiven
|
Include the log probabilities on the The maximum value for |
NOT_GIVEN
|
max_tokens
|
Optional[int] | NotGiven
|
The maximum number of tokens that can be generated in the completion. The token count of your prompt plus |
NOT_GIVEN
|
n
|
Optional[int] | NotGiven
|
How many completions to generate for each prompt. Note: Because this parameter generates many completions, it can quickly
consume your token quota. Use carefully and ensure that you have reasonable
settings for |
NOT_GIVEN
|
presence_penalty
|
Optional[float] | NotGiven
|
Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. See more information about frequency and presence penalties. |
NOT_GIVEN
|
seed
|
Optional[int] | NotGiven
|
If specified, our system will make a best effort to sample deterministically,
such that repeated requests with the same Determinism is not guaranteed, and you should refer to the |
NOT_GIVEN
|
stop
|
Union[Optional[str], List[str], None] | NotGiven
|
Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence. |
NOT_GIVEN
|
stream
|
Optional[Literal[False]] | Literal[True] | NotGiven
|
Whether to stream back partial progress. If set, tokens will be sent as
data-only
server-sent events
as they become available, with the stream terminated by a |
NOT_GIVEN
|
suffix
|
Optional[str] | NotGiven
|
The suffix that comes after a completion of inserted text. |
NOT_GIVEN
|
temperature
|
Optional[float] | NotGiven
|
What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or |
NOT_GIVEN
|
top_p
|
Optional[float] | NotGiven
|
An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or |
NOT_GIVEN
|
user
|
str | NotGiven
|
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more. |
NOT_GIVEN
|
extra_headers
|
Headers | None
|
Send extra headers |
None
|
extra_query
|
Query | None
|
Add additional query parameters to the request |
None
|
extra_body
|
Body | None
|
Add additional JSON properties to the request |
None
|
timeout
|
float | Timeout | None | NotGiven
|
Override the client-level default timeout for this request, in seconds |
NOT_GIVEN
|
AsyncCompletionsWithRawResponse
AsyncCompletionsWithRawResponse(
completions: AsyncCompletions,
)
Attributes:
Name | Type | Description |
---|---|---|
create |
|
AsyncCompletionsWithStreamingResponse
AsyncCompletionsWithStreamingResponse(
completions: AsyncCompletions,
)
Attributes:
Name | Type | Description |
---|---|---|
create |
|
Completions
Completions(client: OpenAI)
Methods:
Name | Description |
---|---|
create |
Creates a completion for the provided prompt and parameters. |
with_raw_response |
|
with_streaming_response |
|
create
create(
*,
model: Union[
str,
Literal[
"gpt-3.5-turbo-instruct",
"davinci-002",
"babbage-002",
],
],
prompt: Union[
str,
List[str],
Iterable[int],
Iterable[Iterable[int]],
None,
],
best_of: Optional[int] | NotGiven = NOT_GIVEN,
echo: Optional[bool] | NotGiven = NOT_GIVEN,
frequency_penalty: (
Optional[float] | NotGiven
) = NOT_GIVEN,
logit_bias: (
Optional[Dict[str, int]] | NotGiven
) = NOT_GIVEN,
logprobs: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
presence_penalty: (
Optional[float] | NotGiven
) = NOT_GIVEN,
seed: Optional[int] | NotGiven = NOT_GIVEN,
stop: (
Union[Optional[str], List[str], None] | NotGiven
) = NOT_GIVEN,
stream: Optional[Literal[False]] | NotGiven = NOT_GIVEN,
suffix: Optional[str] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
top_p: Optional[float] | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Completion
create(
*,
model: Union[
str,
Literal[
"gpt-3.5-turbo-instruct",
"davinci-002",
"babbage-002",
],
],
prompt: Union[
str,
List[str],
Iterable[int],
Iterable[Iterable[int]],
None,
],
stream: Literal[True],
best_of: Optional[int] | NotGiven = NOT_GIVEN,
echo: Optional[bool] | NotGiven = NOT_GIVEN,
frequency_penalty: (
Optional[float] | NotGiven
) = NOT_GIVEN,
logit_bias: (
Optional[Dict[str, int]] | NotGiven
) = NOT_GIVEN,
logprobs: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
presence_penalty: (
Optional[float] | NotGiven
) = NOT_GIVEN,
seed: Optional[int] | NotGiven = NOT_GIVEN,
stop: (
Union[Optional[str], List[str], None] | NotGiven
) = NOT_GIVEN,
suffix: Optional[str] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
top_p: Optional[float] | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Stream[Completion]
create(
*,
model: Union[
str,
Literal[
"gpt-3.5-turbo-instruct",
"davinci-002",
"babbage-002",
],
],
prompt: Union[
str,
List[str],
Iterable[int],
Iterable[Iterable[int]],
None,
],
stream: bool,
best_of: Optional[int] | NotGiven = NOT_GIVEN,
echo: Optional[bool] | NotGiven = NOT_GIVEN,
frequency_penalty: (
Optional[float] | NotGiven
) = NOT_GIVEN,
logit_bias: (
Optional[Dict[str, int]] | NotGiven
) = NOT_GIVEN,
logprobs: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
presence_penalty: (
Optional[float] | NotGiven
) = NOT_GIVEN,
seed: Optional[int] | NotGiven = NOT_GIVEN,
stop: (
Union[Optional[str], List[str], None] | NotGiven
) = NOT_GIVEN,
suffix: Optional[str] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
top_p: Optional[float] | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Completion | Stream[Completion]
create(
*,
model: Union[
str,
Literal[
"gpt-3.5-turbo-instruct",
"davinci-002",
"babbage-002",
],
],
prompt: Union[
str,
List[str],
Iterable[int],
Iterable[Iterable[int]],
None,
],
best_of: Optional[int] | NotGiven = NOT_GIVEN,
echo: Optional[bool] | NotGiven = NOT_GIVEN,
frequency_penalty: (
Optional[float] | NotGiven
) = NOT_GIVEN,
logit_bias: (
Optional[Dict[str, int]] | NotGiven
) = NOT_GIVEN,
logprobs: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
presence_penalty: (
Optional[float] | NotGiven
) = NOT_GIVEN,
seed: Optional[int] | NotGiven = NOT_GIVEN,
stop: (
Union[Optional[str], List[str], None] | NotGiven
) = NOT_GIVEN,
stream: (
Optional[Literal[False]] | Literal[True] | NotGiven
) = NOT_GIVEN,
suffix: Optional[str] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
top_p: Optional[float] | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Completion | Stream[Completion]
Creates a completion for the provided prompt and parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Union[str, Literal['gpt-3.5-turbo-instruct', 'davinci-002', 'babbage-002']]
|
ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them. |
required |
prompt
|
Union[str, List[str], Iterable[int], Iterable[Iterable[int]], None]
|
The prompt(s) to generate completions for, encoded as a string, array of strings, array of tokens, or array of token arrays. Note that <|endoftext|> is the document separator that the model sees during training, so if a prompt is not specified the model will generate as if from the beginning of a new document. |
required |
best_of
|
Optional[int] | NotGiven
|
Generates When used with Note: Because this parameter generates many completions, it can quickly
consume your token quota. Use carefully and ensure that you have reasonable
settings for |
NOT_GIVEN
|
echo
|
Optional[bool] | NotGiven
|
Echo back the prompt in addition to the completion |
NOT_GIVEN
|
frequency_penalty
|
Optional[float] | NotGiven
|
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. See more information about frequency and presence penalties. |
NOT_GIVEN
|
logit_bias
|
Optional[Dict[str, int]] | NotGiven
|
Modify the likelihood of specified tokens appearing in the completion. Accepts a JSON object that maps tokens (specified by their token ID in the GPT tokenizer) to an associated bias value from -100 to 100. You can use this tokenizer tool to convert text to token IDs. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token. As an example, you can pass |
NOT_GIVEN
|
logprobs
|
Optional[int] | NotGiven
|
Include the log probabilities on the The maximum value for |
NOT_GIVEN
|
max_tokens
|
Optional[int] | NotGiven
|
The maximum number of tokens that can be generated in the completion. The token count of your prompt plus |
NOT_GIVEN
|
n
|
Optional[int] | NotGiven
|
How many completions to generate for each prompt. Note: Because this parameter generates many completions, it can quickly
consume your token quota. Use carefully and ensure that you have reasonable
settings for |
NOT_GIVEN
|
presence_penalty
|
Optional[float] | NotGiven
|
Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. See more information about frequency and presence penalties. |
NOT_GIVEN
|
seed
|
Optional[int] | NotGiven
|
If specified, our system will make a best effort to sample deterministically,
such that repeated requests with the same Determinism is not guaranteed, and you should refer to the |
NOT_GIVEN
|
stop
|
Union[Optional[str], List[str], None] | NotGiven
|
Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence. |
NOT_GIVEN
|
stream
|
Optional[Literal[False]] | Literal[True] | NotGiven
|
Whether to stream back partial progress. If set, tokens will be sent as
data-only
server-sent events
as they become available, with the stream terminated by a |
NOT_GIVEN
|
suffix
|
Optional[str] | NotGiven
|
The suffix that comes after a completion of inserted text. |
NOT_GIVEN
|
temperature
|
Optional[float] | NotGiven
|
What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or |
NOT_GIVEN
|
top_p
|
Optional[float] | NotGiven
|
An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or |
NOT_GIVEN
|
user
|
str | NotGiven
|
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more. |
NOT_GIVEN
|
extra_headers
|
Headers | None
|
Send extra headers |
None
|
extra_query
|
Query | None
|
Add additional query parameters to the request |
None
|
extra_body
|
Body | None
|
Add additional JSON properties to the request |
None
|
timeout
|
float | Timeout | None | NotGiven
|
Override the client-level default timeout for this request, in seconds |
NOT_GIVEN
|
CompletionsWithRawResponse
CompletionsWithRawResponse(completions: Completions)
Attributes:
Name | Type | Description |
---|---|---|
create |
|
CompletionsWithStreamingResponse
CompletionsWithStreamingResponse(completions: Completions)
Attributes:
Name | Type | Description |
---|---|---|
create |
|