async_openai_alt/
lib.rs

1//! Rust library for OpenAI
2//!
3//! ## Creating client
4//!
5//! ```
6//! use async_openai::{Client, config::OpenAIConfig};
7//!
8//! // Create a OpenAI client with api key from env var OPENAI_API_KEY and default base url.
9//! let client = Client::new();
10//!
11//! // Above is shortcut for
12//! let config = OpenAIConfig::default();
13//! let client = Client::with_config(config);
14//!
15//! // OR use API key from different source and a non default organization
16//! let api_key = "sk-..."; // This secret could be from a file, or environment variable.
17//! let config = OpenAIConfig::new()
18//!     .with_api_key(api_key)
19//!     .with_org_id("the-continental");
20//!
21//! let client = Client::with_config(config);
22//!
23//! // Use custom reqwest client
24//! let http_client = reqwest::ClientBuilder::new().user_agent("async-openai").build().unwrap();
25//! let client = Client::new().with_http_client(http_client);
26//! ```
27//!
28//! ## Microsoft Azure Endpoints
29//!
30//! ```
31//! use async_openai::{Client, config::AzureConfig};
32//!
33//! let config = AzureConfig::new()
34//!     .with_api_base("https://my-resource-name.openai.azure.com")
35//!     .with_api_version("2023-03-15-preview")
36//!     .with_deployment_id("deployment-id")
37//!     .with_api_key("...");
38//!
39//! let client = Client::with_config(config);
40//!
41//! // Note that `async-openai` only implements OpenAI spec
42//! // and doesn't maintain parity with the spec of Azure OpenAI service.
43//!
44//! ```
45//!
46//! ## Making requests
47//!
48//!```
49//!# tokio_test::block_on(async {
50//!
51//! use async_openai::{Client, types::{CreateCompletionRequestArgs}};
52//!
53//! // Create client
54//! let client = Client::new();
55//!
56//! // Create request using builder pattern
57//! // Every request struct has companion builder struct with same name + Args suffix
58//! let request = CreateCompletionRequestArgs::default()
59//!     .model("gpt-3.5-turbo-instruct")
60//!     .prompt("Tell me the recipe of alfredo pasta")
61//!     .max_tokens(40_u32)
62//!     .build()
63//!     .unwrap();
64//!
65//! // Call API
66//! let response = client
67//!     .completions()      // Get the API "group" (completions, images, etc.) from the client
68//!     .create(request)    // Make the API call in that "group"
69//!     .await
70//!     .unwrap();
71//!
72//! println!("{}", response.choices.first().unwrap().text);
73//! # });
74//!```
75//!
76//! ## Examples
77//! For full working examples for all supported features see [examples](https://github.com/64bit/async-openai/tree/main/examples) directory in the repository.
78//!
79#![cfg_attr(docsrs, feature(doc_cfg))]
80mod assistant_files;
81mod assistants;
82mod audio;
83mod audit_logs;
84mod batches;
85mod chat;
86mod client;
87mod completion;
88pub mod config;
89mod download;
90mod embedding;
91pub mod error;
92mod file;
93mod fine_tuning;
94mod image;
95mod invites;
96mod message_files;
97mod messages;
98mod model;
99mod moderation;
100mod project_api_keys;
101mod project_service_accounts;
102mod project_users;
103mod projects;
104mod runs;
105mod steps;
106mod threads;
107pub mod types;
108mod uploads;
109mod users;
110mod util;
111mod vector_store_file_batches;
112mod vector_store_files;
113mod vector_stores;
114
115pub use assistant_files::AssistantFiles;
116pub use assistants::Assistants;
117pub use audio::Audio;
118pub use audit_logs::AuditLogs;
119pub use batches::Batches;
120pub use chat::Chat;
121pub use client::Client;
122pub use completion::Completions;
123pub use embedding::Embeddings;
124pub use file::Files;
125pub use fine_tuning::FineTuning;
126pub use image::Images;
127pub use invites::Invites;
128pub use message_files::MessageFiles;
129pub use messages::Messages;
130pub use model::Models;
131pub use moderation::Moderations;
132pub use project_api_keys::ProjectAPIKeys;
133pub use project_service_accounts::ProjectServiceAccounts;
134pub use project_users::ProjectUsers;
135pub use projects::Projects;
136pub use runs::Runs;
137pub use steps::Steps;
138pub use threads::Threads;
139pub use uploads::Uploads;
140pub use users::Users;
141pub use vector_store_file_batches::VectorStoreFileBatches;
142pub use vector_store_files::VectorStoreFiles;
143pub use vector_stores::VectorStores;