1use std::path::Path;
2
3use crate::{
4 client::ChatGPT,
5 types::{ChatMessage, CompletionResponse, Role},
6};
7
8pub struct Conversation {
10 client: ChatGPT,
11 pub history: Vec<ChatMessage>,
13}
14
15impl Conversation {
16 pub fn new(client: ChatGPT, first_message: String) -> Self {
18 Self {
19 client,
20 history: vec![ChatMessage {
21 role: Role::System,
22 content: first_message,
23 }],
24 }
25 }
26
27 pub fn new_with_history(client: ChatGPT, history: Vec<ChatMessage>) -> Self {
29 Self { client, history }
30 }
31
32 pub fn send_message<S: Into<String>>(
36 &mut self,
37 message: S,
38 ) -> String {
39 self.history.push(ChatMessage {
40 role: Role::User,
41 content: message.into(),
42 });
43 let resp = self.client.send_history(&self.history);
44 self.history.push(ChatMessage {
45 role: Role::User,
46 content: resp.clone(),
47 });
48 resp
49 }
50}