flynn_openai/
lib.rs

1//! Rust library for OpenAI
2//!
3//! ## Creating client
4//!
5//! ```
6//! use flynn_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("flynn-openai").build().unwrap();
25//! let client = Client::new().with_http_client(http_client);
26//! ```
27//!
28//! ## Microsoft Azure Endpoints
29//!
30//! ```
31//! use flynn_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 `flynn-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 flynn_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/flynn-openai/tree/main/examples) directory in the repository.
78//!
79#![cfg_attr(docsrs, feature(doc_cfg))]
80mod assistant_files;
81mod assistants;
82mod audio;
83mod batches;
84mod chat;
85mod client;
86mod completion;
87pub mod config;
88mod download;
89mod embedding;
90pub mod error;
91mod file;
92mod fine_tuning;
93mod image;
94mod message_files;
95mod messages;
96mod model;
97mod moderation;
98mod runs;
99mod steps;
100mod threads;
101pub mod types;
102mod util;
103mod vector_store_file_batches;
104mod vector_store_files;
105mod vector_stores;
106
107pub use assistant_files::AssistantFiles;
108pub use assistants::Assistants;
109pub use audio::Audio;
110pub use batches::Batches;
111pub use chat::Chat;
112pub use client::Client;
113pub use completion::Completions;
114pub use embedding::Embeddings;
115pub use file::Files;
116pub use fine_tuning::FineTuning;
117pub use image::Images;
118pub use message_files::MessageFiles;
119pub use messages::Messages;
120pub use model::Models;
121pub use moderation::Moderations;
122pub use runs::Runs;
123pub use steps::Steps;
124pub use threads::Threads;
125pub use vector_store_file_batches::VectorStoreFileBatches;
126pub use vector_store_files::VectorStoreFiles;
127pub use vector_stores::VectorStores;