Introduction to openai-clojure
The openai-clojure library is an unofficial project designed to facilitate the interaction between Clojure applications and the OpenAI API, including its Azure variant. Aimed at developers, this library provides functions that abstract the minor differences between the two APIs, enabling the creation of tools and applications compatible with both OpenAI environments.
Key Features
Supported APIs
The library supports a variety of API endpoints offered by OpenAI, such as:
- Chat: Drive interactions using OpenAI's conversation models.
- Audio: Interact with audio processing capabilities.
- Completion: Interface with models for text completion tasks.
- Embeddings: Work with semantic vector representations.
- Models: Manage and query available models.
- Images: Use OpenAI's image generation features.
- Files: Handle file operations within the OpenAI ecosystem.
- Fine-tuning: Customize models to better fit specific needs.
- Moderations and Assistants: Beta features for content moderation and assistant interactions.
- Threads and Messages: Beta capabilities for structured conversation management.
Compatibility
The library supports the OpenAI API version v2.3.0 and the Azure OpenAI API version v2024-06-01, ensuring it leverages the latest features and improvements from OpenAI's platform.
Configuration and Setup
Dependency Management
Developers can incorporate openai-clojure into their Clojure projects with ease. The dependency can be added via:
deps.edn
net.clojars.wkok/openai-clojure {:mvn/version "0.21.1"}
Leiningen project.clj
[net.clojars.wkok/openai-clojure "0.21.1"]
Note: The library requires a minimum of Java 11 to function correctly.
Authentication
For using the OpenAI API, users must set the environment variable OPENAI_API_KEY
with their API key from OpenAI. If the OpenAI account involves multiple organizations, the OPENAI_ORGANIZATION
variable should be set to specify which organization to use. For Azure OpenAI API usage, authentication details are provided in the documentation.
Exploring Functionality
To aid developers in getting started, openai-clojure provides detailed documentation and examples. Here is a quick example of engaging in a chat with OpenAI's ChatGPT:
(require '[wkok.openai-clojure.api :as api])
(api/create-chat-completion {:model "gpt-3.5-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?"}]})
This snippet demonstrates creating a conversation flow, utilizing OpenAI's models to process and respond to queries.
Contributions and Community
openai-clojure welcomes contributions from the community. Developers can report issues or submit pull requests on GitHub. The project acknowledges its reliance on the Martian HTTP abstraction library, underscoring the collaborative nature of open-source development.
Licensing
The library operates under the MIT license, clarifying that it is not officially affiliated with OpenAI. This licensing allows broad use and distribution, encouraging further innovation and application across various projects.