rust-openai-lib 0.1.0

A Rust library for OpenAI API integration
docs.rs failed to build rust-openai-lib-0.1.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

rust-openai-lib

This project is a Rust library for interacting with the OpenAI API. It provides a simple and intuitive interface for sending requests to the API and processing the responses. The library supports various features of the OpenAI API, including chat completions. It's designed for developers who want to integrate OpenAI's powerful AI models into their Rust applications.

Installation

Install this project with cargo

cargo install rust-openai-lib

Usage/Examples

use rust-openai-lib::{Model, Openai};

let openai = Openai::new("your-api-key", Model::Gpt35Turbo);

API Reference

Initialize OpenAI

let openai = Openai::new("your-api-key", Model::Gpt35Turbo);
Parameter Type Description
api_key String Your OpenAI API key
model Model The model to use

Returns: Openai

Get chat completion

let messages = vec![Message {
	"role": "user",
	"content": "Hello world"
}];
let response = openai.get_chat_completion(messages).await.unwrap();
Parameter Type Description
messages Vec<Message> List of messages for the chat completion

Returns: Result<Value, Error>

Where Value is response object.