chat_stream/
chat_stream_example.rs1use openai_rust;
3use openai_rust::futures_util::StreamExt;
4use std::io::Write;
5
6#[tokio::main]
7async fn main() {
8 let client = openai_rust::Client::new(&std::env::var("OPENAI_API_KEY").unwrap());
9 let args = openai_rust::chat::ChatArguments::new(
10 "gpt-3.5-turbo",
11 vec![openai_rust::chat::Message {
12 role: "user".to_owned(),
13 content: "Hello GPT!".to_owned(),
14 }],
15 );
16 let mut res = client.create_chat_stream(args).await.unwrap();
17 while let Some(chunk) = res.next().await {
18 print!("{}", chunk.unwrap());
19 std::io::stdout().flush().unwrap();
20 }
21}