View Source WiseGPTEx.OpenAIUtils (WiseGPTEx v0.3.0)
Provides facilities for processing some of the responses from third party APIs.
Link to this section Summary
Functions
A function that takes a list of completions and returns the content of the first one that finished.
A function that takes a list of completions and returns the content of all that finished.
A function that takes a list of completions and prepares them as answer options. Each option is prefixed with "Answer Option" followed by its index in the list, and all options are joined together with newline.
A function that takes a message and returns a prompt with a reasoning template.
A function that takes a message and completions with reasoning, and returns a string prompt for a researcher.
A simple function that returns a static string. This string serves as an instruction for a "resolver" role, outlining the tasks it needs to perform.
A function that extracts the resolver's answer from a string.
The answer is expected to start within the special marker <|answerstart|>
.
If these markers are not found, the function returns the original string.
Link to this section Functions
A function that takes a list of completions and returns the content of the first one that finished.
example
Example
iex> body = %{
...> "choices" => [
...> %{
...> "finish_reason" => "stop",
...> "index" => 0,
...> "message" => %{
...> "content" => "Correct Answer: Option 1.",
...> "role" => "assistant"
...> }
...> }
...> ]
...> }
...> WiseGPTEx.OpenAIUtils.extract_completion(body)
"Correct Answer: Option 1."
A function that takes a list of completions and returns the content of all that finished.
example
Example
iex> body = %{
...> "choices" => [
...> %{
...> "finish_reason" => "stop",
...> "index" => 0,
...> "message" => %{
...> "content" => "First, 456 * 23421 = 54,456.",
...> "role" => "assistant"
...> }
...> },
...> %{
...> "finish_reason" => "stop",
...> "index" => 1,
...> "message" => %{
...> "content" => "Second, we get the answer: 10,686,876.",
...> "role" => "assistant"
...> }
...> }
...> ]
...> }
...> WiseGPTEx.OpenAIUtils.extract_completions(body)
["First, 456 * 23421 = 54,456.", "Second, we get the answer: 10,686,876."]
A function that takes a list of completions and prepares them as answer options. Each option is prefixed with "Answer Option" followed by its index in the list, and all options are joined together with newline.
example
Example
iex> completions = ["PHP", "Elixir", "Go"]
...> WiseGPTEx.OpenAIUtils.prepare_completion_options(completions)
"Answer Option 1: PHP\nAnswer Option 2: Elixir\nAnswer Option 3: Go"
A function that takes a message and returns a prompt with a reasoning template.
example
Example
iex> WiseGPTEx.OpenAIUtils.reasoning_prompt("What is 2+2?")
"Question: What is 2+2?\nAnswer: Let's work this out in a step by step way to be sure we have the right answer."
A function that takes a message and completions with reasoning, and returns a string prompt for a researcher.
The researcher is tasked with investigating the answer options provided, listing the flaws and faulty logic of each answer option.
example
Example
iex> message = "What is the capital of France?"
...> completions_with_reasoning = "Option 1: Paris - This is the correct answer. Paris is the capital of France.\nOption 2: London - This is incorrect. London is the capital of the United Kingdom, not France."
...> WiseGPTEx.OpenAIUtils.researcher_prompt(message, completions_with_reasoning)
"What is the capital of France?\n\nOption 1: Paris - This is the correct answer. Paris is the capital of France.\nOption 2: London - This is incorrect. London is the capital of the United Kingdom, not France.\n\nYou are researcher tasked with investigating the answer options provided. List the flaws and faulty logic of each answer option. Let's work this out in a step by step way to be sure we have all the errors\n\n**Answer format:**\nCorrect Answer: <Option Number>\n**If there are multiple correct answers, pick the first one.**"
A simple function that returns a static string. This string serves as an instruction for a "resolver" role, outlining the tasks it needs to perform.
These tasks include:
- Identifying the best answer from a set of options.
- Improving the selected answer.
- Printing the improved answer in its entirety.
- Adding a special marker to the beginning of the improved answer.
The string also includes a statement encouraging a step-by-step approach to ensure the correct answer is found. This function doesn't take any arguments and always returns the same string.
example
Example
iex> WiseGPTEx.OpenAIUtils.resolver_prompt()
"You are a resolver tasked with 1) finding which of the X answer options was best 2) improving that answer, 3) printing the improved answer in full, and 4) adding to the begining of the improved answer special marker <|answerstart|>. Let's work this out in step by step way to be sure we have the right answer:"
A function that extracts the resolver's answer from a string.
The answer is expected to start within the special marker <|answerstart|>
.
If these markers are not found, the function returns the original string.
example
Example
iex> answer = "Some text before<|answerstart|>Hello"
...> WiseGPTEx.OpenAIUtils.trim_resolver_answer(answer)
"Hello"