Clojure functions to drive the Azure OpenAI API
Add the openai-clojure
dependency
net.clojars.wkok/openai-clojure {:mvn/version "0.12.0"}
[net.clojars.wkok/openai-clojure "0.12.0"]
Set the environment variable AZURE_OPENAI_API_KEY
to your Azure OpenAI API key.
An API key can be retrieved from your Azure account
Set the environment variable AZURE_OPENAI_API_ENDPOINT
to your Azure OpenAPI endpoint, example: https://myendpoint.openai.azure.com
Alternatively the api-key
and/or api-endpoint
can be passed in the options
argument of each api function
(api/create-completion {:model "text-davinci-003"
:prompt "Say this is a test"}
{:api-key "xxxxx"
:api-endpoint "https://myendpoint.openai.azure.com"
:impl :azure})
See the full API Reference api documentation for examples of all the supported OpenAI APIs.
Require the api
namespace
(:require [wkok.openai-clojure.api :as api])
A simple chat conversation with ChatGPT could be:
(api/create-chat-completion {:model "gpt-35-turbo"
:messages [{:role "system" :content "You are a helpful assistant."}
{:role "user" :content "Who won the world series in 2020?"}
{:role "assistant" :content "The Los Angeles Dodgers won the World Series in 2020."}
{:role "user" :content "Where was it played?"}]}
{:impl :azure})
Result:
{:id "chatcmpl-6srOKLabYTpTRwRUQxjkcBxw3uf1H",
:object "chat.completion",
:created 1678532968,
:model "gpt-35-turbo-0301",
:usage {:prompt_tokens 56, :completion_tokens 19, :total_tokens 75},
:choices
[{:message
{:role "assistant",
:content
"The 2020 World Series was played at Globe Life Field in Arlington, Texas."},
:finish_reason "stop",
:index 0}]}
Also see the Azure OpenAI documentation
Also see the Azure OpenAI documentation
Also see the Azure OpenAI documentation
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close