OpenAI Tools
API Wrapper for OpenAI API.
Installation
To start using the openai-tools
, add it to your projects's dependencies in the `Cargo.toml' file:
API key is necessary to access OpenAI API.
Set it in the .env
file:
OPENAI_API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
Then, import the necesarry modules in your code:
use OpenAI;
Usage
Chat Completion
-
Simple Chat
let mut openai = new; let messages = vec!; openai .model_id .messages .temperature; let response: Response = openai.chat.unwrap; println!; // Hello! How can I assist you today?
-
Chat with Json Schema
let mut openai = new; let messages = vec!; // build json schema let mut json_schema = new; json_schema.add_property; json_schema.add_property; json_schema.add_property; json_schema.add_property; // configure chat completion model openai .model_id .messages .temperature .response_format; // execute chat let response = openai.chat.unwrap; let answer: Weather = println! // Weather { // location: "Tokyo", // date: "2023-10-01", // weather: "Temperatures around 25°C with partly cloudy skies and a slight chance of rain.", // error: "", // }