Noizu.OpenAI.Api.Chat (Noizu Labs: OpenAI v0.1.3)

Noizu.OpenAI.Api.Chat is a module that provides functionality for handling chat-based interactions using OpenAI's API.

This module offers one main function:

  1. chat/2 - Generates a chat-based completion using the given messages and options.

usage

Usage

{:ok, chat_response} = Noizu.OpenAI.Api.Chat.chat(messages, options)

Link to this section Summary

Functions

Generates a chat-based completion using the OpenAI API.

Link to this section Types

Link to this type

chat_message()

@type chat_message() :: %{role: String.t(), message: String.t()}
Link to this type

chat_options()

@type chat_options() ::
  %{
    optional(:model) => Noizu.OpenAI.model_option(chat_supported_models()),
    optional(:temperature) => Noizu.OpenAI.temperature_option(),
    optional(:top_p) => Noizu.OpenAI.top_p_option(),
    optional(:completions | :n) => Noizu.OpenAI.completions_option(),
    optional(:stream) => Noizu.OpenAI.stream_option(),
    optional(:seed) => any(),
    optional(:stop) => Noizu.OpenAI.stop_option(),
    optional(:max_tokens) => Noizu.OpenAI.max_tokens_option(),
    optional(:presence_penalty) => Noizu.OpenAI.presence_penalty_option(),
    optional(:logit_bias) => Noizu.OpenAI.logit_bias_option(),
    optional(:user) => Noizu.OpenAI.user_option()
  }
  | Keyword.t()
Link to this type

chat_response()

@type chat_response() :: map()
Link to this type

chat_supported_models()

@type chat_supported_models() :: :"gpt-3.5-turbo" | :gpt4 | atom()

Link to this section Functions

Link to this function

chat(messages, options \\ nil)

@spec chat(messages :: [chat_message()], options :: chat_options()) ::
  {:ok, chat_response()} | {:error, term()}

Generates a chat-based completion using the OpenAI API.

parameters

Parameters

  • messages: A list of maps containing message role and content
  • options: An optional map or keyword list containing API options

returns

Returns

Returns a tuple {:ok, response} on successful API call, where response is a map containing the chat response. Returns {:error, term} on failure, where term contains error details.

example

Example

messages = [
  %{"role" => "system", "content" => "You are a helpful assistant."},
  %{"role" => "user", "content" => "Who won the world series in 2020?"}
]
{:ok, response} = Noizu.OpenAI.Api.Chat.chat(messages)