diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..f4abdbd --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,22 @@ +use ratmom::{prelude::*, Request}; + +async fn ask(prompt: String) -> Result> { + let mut request = Request::builder() + .method("POST") + .uri("https://chatbot.theb.ai/api/chat-process") + .header("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/112.0") + .header("Accept-Language", "en-US,en;q=0.5") + .header("Content-Type", "application/json") + .header("Host", "chatbot.theb.ai") + .header("Referer", "https://chatbot.theb.ai") + .header("Origin", "https://chatbot.theb.ai") + .body(format!(r#"{ + "prompt": "{prompt}", + "options": { + "parentMessageId": "8c00bd29-75b0-42c7-9d4f-05a94ac8b2de" + } +}"#, prompt = prompt.as_str()))? + .send()?; + + return request.text()?; +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 6132646..1d61d3e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,26 +1,11 @@ -use ratmom::{prelude::*, Request}; +use crate::ask; #[tokio::main] async fn main() -> Result<(), Box> { - let mut request = Request::builder() - .method("POST") - .uri("https://chatbot.theb.ai/api/chat-process") - .header("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/112.0") - .header("Accept-Language", "en-US,en;q=0.5") - .header("Content-Type", "application/json") - .header("Host", "chatbot.theb.ai") - .header("Referer", "https://chatbot.theb.ai") - .header("Origin", "https://chatbot.theb.ai") - .body(r#"{ - "prompt": "Hello", - "options": { - "parentMessageId": "8c00bd29-75b0-42c7-9d4f-05a94ac8b2de" - } -}"#)? - .send()?; + let mut response = ask("Hello, world!").await?; - println!("{}", request.text()?); + println!("{}", response); Ok(()) } \ No newline at end of file