Skip to content

marinac-dev/openai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenAi

Elixir OpenAi client library for with full support for streaming or SSE (Server Side Events).

Installation

Not available in Hex, but the package can be installed from git by adding openai to your list of dependencies in mix.exs:

def deps do
  [
    {:openai, git: "git@github.com:marinac-dev/openai.git", branch: "master"},
  ]
end

Documentation can be generated with ExDoc by running mix docs.

Configuration

config :openai,
  api_key: System.get_env("OPENAI_API_KEY"),
  organization_key: System.get_env("OPENAI_ORGANIZATION_KEY")

If you want to use retry mechanism, you can configure it like this:

config :openai,
  api_key: System.get_env("OPENAI_API_KEY"),
  organization_key: System.get_env("OPENAI_ORGANIZATION_KEY"),
  retry_config: %{
    retries: 5,
    delay: 200
  }

Usage

Once configured in your config.ex file, you can use the client to call the OpenAi API instantly.

prompt = %{model: "gpt-3.5-turbo", messages: [%{role: "user", content: "Hello!"}], stream: true}
OpenAi.chat_completion(prompt)
{:ok, "Hello! How may I assist you today?"}

About

Elixir OpenAi Library with streaming support

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages