1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Legacy text completions.
//!
//! This module provides support for the legacy text completions API. While
//! chat completions are generally preferred for new projects, this module
//! is available for compatibility with older models or specific use cases
//! that require the text completions format.
//!
//! # Key Components
//!
//! - [`Completions`]: The main struct for performing text completion operations.
//! - [`completions_request`]: A convenient function for creating completion request parameters.
//! - [`Completion`]: The response type for text completions.
//!
//! # Examples
//!
//! ## Unary (Non-Streaming) Text Completion
//!
//! ```rust,no_run
//! use openai4rs::{OpenAI, completions_request};
//! use dotenvy::dotenv;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! dotenv().ok();
//! let client = OpenAI::from_env()?;
//! let response = client
//! .completions()
//! .create(completions_request("text-davinci-003", "Write a poem about Rust.").max_tokens(100))
//! .await?;
//!
//! println!("{:#?}", response);
//! Ok(())
//! }
//! ```
//!
//! ## Streaming Text Completion
//!
//! ```rust,no_run
//! use openai4rs::{OpenAI, completions_request};
//! use futures::StreamExt;
//! use dotenvy::dotenv;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! dotenv().ok();
//! let client = OpenAI::from_env()?;
//! let mut stream = client
//! .completions()
//! .create_stream(completions_request("text-davinci-003", "Write a story about a robot.").max_tokens(100))
//! .await?;
//!
//! while let Some(chunk) = stream.next().await {
//! let chunk = chunk?;
//! if let Some(choice) = chunk.choices.first() {
//! print!("{}", choice.text);
//! }
//! }
//! Ok(())
//! }
//! ```
pub use Completions;
pub use completions_request;
pub use Completion;