OpenaiEx: An Introduction to the Elixir OpenAI API Client
OpenaiEx is an impressive Elixir library crafted to serve as a robust OpenAI API client, maintained by a community of developers. Every line of code is meticulously curated by humans, although the development process benefited from the assistance of advanced AI models like ChatGPT and Claude.
Comprehensive API Support
As of May 2024, OpenaiEx supports all OpenAI API endpoints and features, ensuring comprehensive access to OpenAI services. It includes the Assistants API Beta 2 with the capability for Run streaming, cutting-edge capabilities of DALL-E-3, Text-To-Speech, and robust tools for chat completions. Additionally, it supports a streaming version of chat completions, along with the unique ability to cancel streaming requests.
Key Configuration and Differentiators
OpenaiEx sets itself apart in several ways compared to other Elixir OpenAI wrappers:
- Faithful Design: It mirrors the naming and structural conventions of the official Python API. This design choice facilitates a smooth transition for developers accustomed to the Python environment. For example, data can be uploaded directly from memory, bypassing the need for file-based uploads.
- Environment Variables: The library prioritizes simplicity by utilizing environment variables over traditional configuration settings, ideal for Livebook use-cases.
- Advanced Streaming Support: OpenaiEx supports streaming API versions that allow request cancellations, offering a new level of control and flexibility.
- Transport Layer: The library uses Finch instead of the traditional Httpoison for the underlying transport layer.
- Support for Local and Third-Party LLMs: OpenaiEx accommodates both third-party and local language models through an OpenAI proxy. This adaptability extends to the Azure OpenAI API, broadening its usability in various contexts.
Community and Discussions
For those interested in community discussions and announcements related to OpenaiEx, they can explore the dedicated thread in the Elixir Forum, providing a platform for active developer engagement.
Installation and Usage
To get started with OpenaiEx, detailed installation instructions and usage examples are available in the User Guide hosted on hexdocs. The guide, offered as a Livebook, allows users to execute code without initiating a new project, ensuring a practical and hands-on experience with the library.
Livebook Examples
For practical insights, users can explore various Livebook examples available on hexdocs:
- Streaming Orderbot: Demonstrates how to leverage ChatCompletion streaming within a chatbot environment.
- Deeplearning.AI Orderbot: An Elixir/Kino adaptation of a Python notebook from the ChatGPT Prompt Engineering course offered by Deeplearning.AI.
- Completions Chatbot: Designed to be deployed as a Livebook app, showcasing both standard and streaming completions.
- Image Generation UI: A user interface example dedicated to image generation tasks.
These examples serve as an excellent source of inspiration and starting points for creating custom projects.
Contributing to Development
For developers eager to contribute to OpenaiEx, setting up a development environment is straightforward. The library is developed using a Livebook Docker image within a VS Code devcontainer. By cloning the repository and opening it in VS Code, contributors gain access to a ready development environment.
Environment Variables
Configuring environment variables for development involves creating a .env
file within the .devcontainer
folder. This file should include sensitive data, such as OPENAI_API_KEY
and LIVEBOOK_PASSWORD
, necessary for running Livebook and interacting with OpenAI services. It's important to note that the .env
file is excluded from version control to maintain security and privacy.
In summary, OpenaiEx provides an extensive, user-friendly, and adaptable Elixir library that opens the doors to OpenAI's powerful API capabilities, making it a valuable asset for developers looking to leverage AI technology in their applications.