View Source AI (AI v0.3.4)

Documentation for AI.

Summary

Functions

Parses out OpenAI's chat completion response into a cleaner format. Returns {:ok, text_content} or {:error, message}

DEPRECATED: Use ~l instead. ~LLM doesn't work with string interpolation.

Implements the ~l sigil, which parses text into an OpenAI friendly chat completion prompt. ~l works by parsing out the model, system, user and assistant keywords.

Functions

Parses out OpenAI's chat completion response into a cleaner format. Returns {:ok, text_content} or {:error, message}

Instead of: {:ok, %{ id: "chatcmpl-7zSc1rsCXpyALMjM9MkaF077xYRot", usage: %{ "completion_tokens" => 10, "prompt_tokens" => 19, "total_tokens" => 29 }, created: 1694882349, choices: [ %{

 "finish_reason" => "stop",
 "index" => 0,
 "message" => %{
   "content" => "Compact and stack snow blocks in a dome shape.",
   "role" => "assistant"
 }

} ], model: "gpt-3.5-turbo-0613", object: "chat.completion" }}

DEPRECATED: Use ~l instead. ~LLM doesn't work with string interpolation.

Implements the ~LLM sigil, which parses text into an OpenAI friendly chat completion prompt. ~LLM works by parsing out the model, system, user and assistant keywords.

Examples

iex> import AI iex> ~LLM"model: gpt-3.5-turbo system: You are an expert at text to image prompts. Given a description, write a text-to-image prompt. user: sunset" [ model: "gpt-3.5-turbo", messages: [

%{
  content: "You are an expert at text to image prompts. Given a description, write a text-to-image prompt.",
  role: "system"
},
%{content: "sunset", role: "user"}

] ]

Implements the ~l sigil, which parses text into an OpenAI friendly chat completion prompt. ~l works by parsing out the model, system, user and assistant keywords.

Supports string interpolation.

Examples

iex> import AI iex> ~l"model: gpt-3.5-turbo system: You are an expert at text to image prompts. Given a description, write a text-to-image prompt. user: sunset" [ model: "gpt-3.5-turbo", messages: [

%{
  content: "You are an expert at text to image prompts. Given a description, write a text-to-image prompt.",
  role: "system"
},
%{content: "sunset", role: "user"}

] ]