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

Noizu.OpenAI.Api.Completion is a module that provides functionality for generating completions using OpenAI's API.

This module offers one main function:

  1. completion/2 - Generates a completion using the given prompt and options.

usage

Usage

{:ok, completion_response} = Noizu.OpenAI.Api.Completion.completion(prompt, options)

Link to this section Summary

Functions

Generates a completion for the given prompt using the specified options.

Link to this section Types

Link to this type

completion_options()

@type completion_options() ::
  %{
    optional(:model) =>
      Noizu.OpenAI.model_option(completion_supported_models()),
    optional(:suffix) => Noizu.OpenAI.stream_option(),
    optional(:max_tokens) => Noizu.OpenAI.max_tokens_option(),
    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(:logprobs) => Noizu.OpenAI.log_probability_option(),
    optional(:echo) => Noizu.OpenAI.echo_option(),
    optional(:stop) => Noizu.OpenAI.stop_option(),
    optional(:presence_penalty) => Noizu.OpenAI.presence_penalty_option(),
    optional(:frequency_penalty) => Noizu.OpenAI.frequency_penalty_option(),
    optional(:best_of) => Noizu.OpenAI.best_of_option(),
    optional(:logit_bias) => Noizu.OpenAI.logit_bias_option(),
    optional(:user) => Noizu.OpenAI.user_option(),
    optional(atom()) => any()
  }
  | Keyword.t()
Link to this type

completion_response()

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

completion_supported_models()

@type completion_supported_models() ::
  :text_davinci_003 | :text_curie_003 | :text_babbage_003 | :text_ada_003

Link to this section Functions

Link to this function

completion(prompt, options)

@spec completion(prompt :: String.t(), options :: completion_options()) ::
  {:ok, completion_response()} | {:error, term()}

Generates a completion for the given prompt using the specified options.

parameters

Parameters

  • prompt: The input text to generate a completion for
  • options: A map or keyword list of options for the API call, such as model, max_tokens, temperature, etc.

returns

Returns

Returns a tuple {:ok, completion} on successful API call, where completion is the generated text completion. Returns {:error, term} on failure, where term contains error details.

example

Example

options = %{max_tokens: 50, temperature: 0.7}
{:ok, completion} = Noizu.OpenAI.Api.Completion.completion("Once upon a time", options)