feat: move to library
This commit is contained in:
parent
1e12ca9f0b
commit
dd73c89397
22
src/lib.rs
Normal file
22
src/lib.rs
Normal 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()?;
|
||||
}
|
21
src/main.rs
21
src/main.rs
@ -1,26 +1,11 @@
|
||||
use ratmom::{prelude::*, Request};
|
||||
use crate::ask;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), 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(r#"{
|
||||
"prompt": "Hello",
|
||||
"options": {
|
||||
"parentMessageId": "8c00bd29-75b0-42c7-9d4f-05a94ac8b2de"
|
||||
}
|
||||
}"#)?
|
||||
.send()?;
|
||||
let mut response = ask("Hello, world!").await?;
|
||||
|
||||
println!("{}", request.text()?);
|
||||
println!("{}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue
Block a user