feat: move to library

This commit is contained in:
0xMRTT 2023-06-17 15:21:55 +02:00
parent 1e12ca9f0b
commit dd73c89397
Signed by: 0xMRTT
GPG Key ID: 910B287304120902
2 changed files with 25 additions and 18 deletions

22
src/lib.rs Normal file
View File

@ -0,0 +1,22 @@
use ratmom::{prelude::*, Request};
async fn ask(prompt: String) -> Result<String, Box<dyn std::error::Error>> {
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()?;
}

View File

@ -1,26 +1,11 @@
use ratmom::{prelude::*, Request}; use crate::ask;
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> { async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut request = Request::builder() let mut response = ask("Hello, world!").await?;
.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()?;
println!("{}", request.text()?); println!("{}", response);
Ok(()) Ok(())
} }