Provides a community maintained Julia wrapper to the OpenAI API. For API functionality see reference documentation. Autogenerated documentation can be found here: https://juliaml.github.io/OpenAI.jl/dev/
using Pkg; Pkg.add("OpenAI")
-
Create an OpenAI account, if you don't already have one
-
Create a secret API key
-
Choose a model to interact with
secret_key = ENV["OPENAI_API_KEY"]
model = "gpt-3.5-turbo"
prompt = "Say \"this is a test\""
r = create_chat(
secret_key,
model,
[Dict("role" => "user", "content"=> prompt)]
)
println(r.response[:choices][begin][:message][:content])
returns
"This is a test."
If you have a non-standard setup, such as a local LLM or third-party service that
conforms to the OpenAI interface, you can override parameters using the OpenAIProvider
struct in your application like this:
using OpenAI
provider = OpenAI.OpenAIProvider(
api_key=ENV["OPENAI_API_KEY"],
base_url=ENV["OPENAI_BASE_URL_OVERRIDE"]
)
response = create_chat(
provider,
"gpt-3.5-turbo",
[Dict("role" => "user", "content" => "Write some ancient Greek poetry")]
)
For more use cases see tests.
Feel free to open a PR, or file an issue if that's out of reach!