chatgpt_functions/lib.rs
1//! A library to interact with OpenAI API to use GPT-3.5 and GPT-4 for chatbots.
2//!
3//! It takes care of the context and the state of the conversation, and provides a way to define
4//! functions that can be called from the chatbot.
5//!
6//! # Usage
7//! The main module to use for the chatbot is `chat_gpt`.
8//! It provides a `ChatGPT` struct that can be used to interact with the GPT API.
9//!
10//! ## Example
11//! ```no_run
12//! use anyhow::Result;
13//! use dotenv::dotenv;
14//! use chatgpt_functions::chat_gpt::ChatGPTBuilder;
15//!
16//! #[tokio::main]
17//! async fn main() -> Result<()> {
18//! dotenv().ok();
19//! let key = std::env::var("OPENAI_API_KEY")?;
20//! let mut gpt = ChatGPTBuilder::new().openai_api_token(key).build()?;
21//! let answer = gpt.completion_managed("Hello, how are you?".to_string()).await?;
22//! println!("{}", answer);
23//! Ok(())
24//! }
25
26// The main module to use, most of the use cases will only need this
27pub mod chat_gpt;
28// Internals, to be used by the library or in case more control is needed
29pub mod chat_context;
30pub mod chat_response;
31pub mod function_specification;
32pub mod message;
33
34// Escape a string to be used in JSON
35pub mod escape_json;