feat: add parent message id
This commit is contained in:
parent
80eabb9f9f
commit
bf5fb5df49
40
src/lib.rs
40
src/lib.rs
@ -34,17 +34,46 @@ pub struct DeltaChoice {
|
|||||||
pub content: String,
|
pub content: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn ask(prompt: &str) -> Result<Vec<Delta>, Box<dyn std::error::Error>> {
|
struct ThebAI {
|
||||||
|
pub parent_message_id: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ThebAI {
|
||||||
|
pub fn new(parent_message_id: Option<&str>) -> ThebAI {
|
||||||
|
if let Some(parent_message_id) = parent_message_id {
|
||||||
|
return ThebAI {
|
||||||
|
parent_message_id: Some(parent_message_id.to_string()),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return ThebAI {
|
||||||
|
parent_message_id: String::from("8c00bd29-75b0-42c7-9d4f-05a94ac8b2de"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn ask(&self, prompt: &str, parent_message_id: Option<String>) -> Result<Vec<Delta>, Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
let mut body = String::new();
|
let mut body = String::new();
|
||||||
body.push_str(r#"{
|
body.push_str(r#"{
|
||||||
"prompt": ""#);
|
"prompt": ""#);
|
||||||
body.push_str(&prompt);
|
body.push_str(&prompt);
|
||||||
|
if let Some(parent_message_id) = parent_message_id {
|
||||||
body.push_str(r#"",
|
body.push_str(r#"",
|
||||||
"options": {
|
"options": {
|
||||||
"parentMessageId": "8c00bd29-75b0-42c7-9d4f-05a94ac8b2de"
|
"parentMessageId": ""#);
|
||||||
|
body.push_str(parent_message_id.as_str());
|
||||||
|
body.push_str(r#""
|
||||||
}
|
}
|
||||||
}"#);
|
}"#);
|
||||||
|
} else {
|
||||||
|
body.push_str(r#"",
|
||||||
|
"options": {
|
||||||
|
"parentMessageId": ""#);
|
||||||
|
body.push_str(self.parent_message_id.as_ref().unwrap().as_str());
|
||||||
|
body.push_str(r#""
|
||||||
|
}
|
||||||
|
}"#);
|
||||||
|
}
|
||||||
let mut request = Request::builder()
|
let mut request = Request::builder()
|
||||||
.method("POST")
|
.method("POST")
|
||||||
.uri("https://chatbot.theb.ai/api/chat-process")
|
.uri("https://chatbot.theb.ai/api/chat-process")
|
||||||
@ -64,13 +93,16 @@ pub async fn ask(prompt: &str) -> Result<Vec<Delta>, Box<dyn std::error::Error>>
|
|||||||
if line == "" {
|
if line == "" {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
println!("{}", line);
|
|
||||||
println!("------------------");
|
|
||||||
let delta: Delta = serde_json::from_str(line).unwrap();
|
let delta: Delta = serde_json::from_str(line).unwrap();
|
||||||
deltas.push(delta);
|
deltas.push(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.parent_message_id = Some(deltas.last().unwrap().id.clone());
|
||||||
|
|
||||||
println!("{:?}", deltas);
|
println!("{:?}", deltas);
|
||||||
|
|
||||||
return Ok(deltas);
|
return Ok(deltas);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user