View Source WiseGPTEx (WiseGPTEx v0.2.0)
Documentation for WiseGPTEx
.
This module provides functions to obtain the best completion from the OpenAI models (default: "gpt-3.5-turbo") using the OpenAI API completions endpoint (https://api.openai.com/v1/chat/completions
).
The get_best_completion/2
and get_best_completion_with_resolver/2
functions take a question and an optional list of options to configure the API request. get_best_completion_with_resolver/2
also involves a secondary step to resolve the best completion among the options, which leads to an additional API call for a more accurate response.
installation
Installation
Add
wise_gpt_ex
to your list of dependencies inmix.exs
:def deps do [ {:wise_gpt_ex, "~> 0.2.0"} ] end
Add the OpenAI API key to your configuration file (e.g., config/config.exs):
config :wise_gpt_ex, :openai_api_key, "your_openai_api_key"
examples
Examples
Basic usage:
iex> WiseGPTEx.get_best_completion("What is the capital of France?")
{:ok, "Paris"}
iex> WiseGPTEx.get_best_completion_with_resolver("What is the capital of France?")
{:ok, "Paris"}
Using all available options:
iex> opts = [model: "gpt-4", temperature: 0.7, num_completions: 5, timeout: 300_000]
iex> WiseGPTEx.get_best_completion("What is the capital of France?", opts)
{:ok, "Paris"}
iex> WiseGPTEx.get_best_completion_with_resolver("What is the capital of France?", opts)
{:ok, "Paris"}
Note that the examples for the get_best_completion_with_resolver/2
function are similar to get_best_completion/2
.
This is because the difference between these two functions is in the method of how they select the best completion, not in their usage or the nature of their inputs or outputs.
The get_best_completion_with_resolver/2
function will perform an additional API call to get a more accurate completion, which can be beneficial for complex or ambiguous queries.
options
Options
The following options can be passed to the get_best_completion/2
and get_best_completion_with_resolver/2
functions:
:model
- The name of the model to use (default: "gpt-3.5-turbo"). All OpenAI models are supported.:temperature
- Controls the randomness of the model's output. Higher values result in more diverse responses (default: 0.5).:num_completions
- The number of completions to generate (default: 3).:timeout
- The maximum time in milliseconds to wait for a response from the OpenAI API (default: 300_000 ms, or 5 minutes).
Link to this section Summary
Functions
get_best_completion/2
attempts to answer a given question using OpenAI's completion endpoint.
get_best_completion_with_resolver/2
is similar to get_best_completion/2
but uses a secondary step to resolve the best completion among the options.
Link to this section Functions
get_best_completion/2
attempts to answer a given question using OpenAI's completion endpoint.
params
Params:
question
: a binary string containing the question to be answeredopts
: a keyword list of options to configure the API request
returns
Returns:
{:ok, binary()}
: the best completion for the given question{:error, any()}
: an error message in the case of failure
example
Example:
iex> WiseGPTEx.get_best_completion("What is the capital of France?")
{:ok, "Paris"}
options
Options:
The function accepts the following options:
:model
- The name of the model to use (default: "gpt-3.5-turbo"). All OpenAI models are supported.:temperature
- Controls the randomness of the model's output. Higher values result in more diverse responses (default: 0.5).:num_completions
- The number of completions to generate (default: 3).:timeout
- The maximum time in milliseconds to wait for a response from the OpenAI API (default: 300_000 ms, or 5 minutes).
get_best_completion_with_resolver/2
is similar to get_best_completion/2
but uses a secondary step to resolve the best completion among the options.
This function will perform an additional API call to get a more accurate completion, which can be beneficial for complex or ambiguous queries.
params
Params:
question
: a binary string containing the question to be answeredopts
: a keyword list of options to configure the API request
returns
Returns:
{:ok, binary()}: the best completion for the given question -
: an error message in the case of failure
example
Example:
iex> WiseGPTEx.get_best_completion_with_resolver("What is the capital of France?")
{:ok, "Paris"}
options
Options:
The function accepts the following options:
:model
- The name of the model to use (default: "gpt-3.5-turbo"). All OpenAI models are supported.:temperature - Controls the randomness of the model's output. Higher values result in more diverse responses (default: 0.5). -
:num_completions- The number of completions to generate (default: 3). -
:timeout` - The maximum time in milliseconds to wait for a response from the OpenAI API (default: 300_000 ms, or 5 minutes).