View Source OpenaiEx.Chat.Completions (openai_ex v0.8.5)
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.
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.Chat.Completions.new(model: "davinci", messages: [OpenaiEx.ChatMessage.user("Hello, world!")])
%{messages: [%{content: "Hello, world!", role: "user"}], model: "davinci"}
iex> _request = OpenaiEx.Chat.Completions.new(%{model: "davinci", messages: [OpenaiEx.ChatMessage.user("Hello, world!")]})
%{messages: [%{content: "Hello, world!", role: "user"}], model: "davinci"}