View Source OpenaiEx.ChatCompletion (openai_ex v0.3.0)
This module provides an implementation of the OpenAI chat completions API. The API reference can be found at https://platform.openai.com/docs/api-reference/chat/completions.
API Fields
The following fields can be used as parameters when creating a new chat completion:
:messages
:model
:frequency_penalty
:function_call
:functions
:logit_bias
:max_tokens
:n
:presence_penalty
:stop
:temperature
:top_p
:user
Summary
Functions
Calls the chat completion 'create' endpoint.
Creates a new chat completion request with the given arguments.
Functions
Calls the chat completion 'create' endpoint.
Arguments
openai
: The OpenAI configuration.chat_completion
: The chat completion request, as a map with keys corresponding to the API fields.
Returns
A map containing the API response.
See https://platform.openai.com/docs/api-reference/chat/completions/create for more information.
Creates a new chat completion request with the given arguments.
Arguments
args
: A list of key-value pairs, or a map, representing the fields of the chat completion request.
Returns
A map containing the fields of the chat completion request.
The :model
and :messages
fields are required. The :messages
field should be a list of maps with the OpenaiEx.ChatMessage
structure.
Example usage:
iex> _request = OpenaiEx.ChatCompletion.new(model: "davinci", messages: [OpenaiEx.ChatMessage.user("Hello, world!")])
%{messages: [%{content: "Hello, world!", role: "user"}], model: "davinci"}
iex> _request = OpenaiEx.ChatCompletion.new(%{model: "davinci", messages: [OpenaiEx.ChatMessage.user("Hello, world!")]})
%{messages: [%{content: "Hello, world!", role: "user"}], model: "davinci"}