OpenAI Rust SDK
[!NOTE] This is an unofficial OpenAI SDK for Rust, providing a convenient abstraction over OpenAI's API. It enables you to easily perform tasks such as generating completions, creating and editing images, moderating text, fine-tuning models, and more.
Table of Contents
Installation
[!TIP] Make sure you have Rust and Cargo installed on your system before proceeding. Visit rust-lang.org for installation instructions.
To use this SDK, add the following dependencies to your Cargo.toml
file:
[]
= "0.1.11"
= "1.0"
= { = "1", = ["full"] }
= { = "0.12.5", = ["json", "multipart"] }
Getting Started
To get started with the OpenAI Rust SDK, follow these steps:
Initialize OpenAI Client
[!IMPORTANT] You'll need an OpenAI API key to use this SDK. Get your API key from the OpenAI dashboard.
First, create an instance of the OpenAI
struct with your API key:
use OpenAI;
async
Generate Chat Completions
[!NOTE] The SDK now supports structured outputs with JSON Schema validation, allowing for more controlled and predictable responses.
Here's an example of generating chat completions with structured output:
use OpenAI;
use ChatCompletionRequest;
use json;
use env;
async
Features
[!TIP] The SDK supports all major OpenAI API endpoints and features:
- π€ Chat Completions with GPT-4 and GPT-3.5
- π¨ Image Generation and Editing (DALLΒ·E)
- π Text Moderation
- π Fine-tuning Models
- π Embeddings Generation
- π Structured Outputs with JSON Schema
- π Custom Base URL Support
- β‘ Async/Await Support
- π Type-safe API
Documentation
[!NOTE] For detailed information on all available endpoints and their respective methods, please refer to the SDK Documentation.
License
[!IMPORTANT] This SDK is licensed under the MIT License. See the LICENSE file for details.