pub struct Chatbot {
pub config: Config,
pub conversation_id: Option<Uuid>,
pub parent_id: Option<Uuid>,
/* private fields */
}
7
8
9
10
11
12
13
async fn main() {
let config_file = PathBuf::from(std::env::var("HOME").unwrap()).join(".config/chatgpt/config.json");
let config = Config::from_file(&config_file);
let mut bot = Chatbot::new(config).await;
let response = bot.ask("Hello, world!").await;
println!("{response}");
}
More examples
Hide additional examples
8
9
10
11
12
13
14
15
16
17
18
async fn main() {
std::env::set_var("RUST_LOG", "info");
pretty_env_logger::init();
let config_file = PathBuf::from(std::env::var("HOME").unwrap()).join(".config/chatgpt/config.json");
let config = Config::from_file(&config_file);
let mut bot = Chatbot::new(config).await;
let mut response = bot.ask_stream("Explain quantum physics.").await;
while let Some(Ok(response)) = response.next().await {
println!("{response}");
}
}
7
8
9
10
11
12
13
async fn main() {
let config_file = PathBuf::from(std::env::var("HOME").unwrap()).join(".config/chatgpt/config.json");
let config = Config::from_file(&config_file);
let mut bot = Chatbot::new(config).await;
let response = bot.ask("Hello, world!").await;
println!("{response}");
}
8
9
10
11
12
13
14
15
16
17
18
async fn main() {
std::env::set_var("RUST_LOG", "info");
pretty_env_logger::init();
let config_file = PathBuf::from(std::env::var("HOME").unwrap()).join(".config/chatgpt/config.json");
let config = Config::from_file(&config_file);
let mut bot = Chatbot::new(config).await;
let mut response = bot.ask_stream("Explain quantum physics.").await;
while let Some(Ok(response)) = response.next().await {
println!("{response}");
}
}
Immutably borrows from an owned value.
Read more
Mutably borrows from an owned value.
Read more
Returns the argument unchanged.
Instruments this type with the provided
Span
, returning an
Instrumented
wrapper.
Read more
Calls U::from(self)
.
That is, this conversion is whatever the implementation of
From<T> for U
chooses to do.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.