simple_chat/
simple_chat.rs1use gpt5::{Gpt5Client, Gpt5Model};
7use std::io::{self, Write};
8
9#[tokio::main]
10async fn main() -> Result<(), Box<dyn std::error::Error>> {
11 let api_key =
12 std::env::var("OPENAI_API_KEY").expect("Please set OPENAI_API_KEY environment variable");
13
14 let client = Gpt5Client::new(api_key);
15
16 println!("🤖 GPT-5 Chat Bot");
17 println!("Type 'quit' or 'exit' to end the conversation\n");
18
19 loop {
20 print!("You: ");
21 io::stdout().flush()?;
22
23 let mut input = String::new();
24 io::stdin().read_line(&mut input)?;
25 let input = input.trim();
26
27 if input == "quit" || input == "exit" {
28 println!("Goodbye! 👋");
29 break;
30 }
31
32 if input.is_empty() {
33 continue;
34 }
35
36 println!("🤖 Thinking...");
37
38 match client.simple(Gpt5Model::Gpt5Nano, input).await {
39 Ok(response) => {
40 println!("Bot: {}\n", response);
41 }
42 Err(e) => {
43 println!("❌ Error: {}\n", e);
44 }
45 }
46 }
47
48 Ok(())
49}