deps: remove reqwest, use bare curl

This commit is contained in:
iff 2024-11-22 00:48:54 +01:00
parent 8c6b78f6ca
commit 98a00674f3
3 changed files with 14 additions and 1187 deletions

1173
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -24,7 +24,6 @@ regex-lite = "0.1"
toml = { version = "0.8", optional = true }
serde_json = { version = "1.0", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
reqwest = { version = "0.12", features = ["blocking", "json"], optional = true }
textwrap = { version = "0.16", features = ["terminal_size"], optional = true}
pay-respects-parser = "0.2.6"
@ -33,7 +32,7 @@ pay-respects-parser = "0.2.6"
[features]
runtime-rules = ["dep:serde", "dep:toml"]
request-ai = ["dep:serde", "dep:serde_json", "dep:reqwest", "dep:textwrap"]
request-ai = ["dep:serde", "dep:serde_json", "dep:textwrap"]
[profile.release]
strip = true

View file

@ -1,6 +1,5 @@
use std::collections::HashMap;
use reqwest::blocking::Client;
use serde::{Deserialize, Serialize};
use serde_json::Value;
@ -98,25 +97,27 @@ The command `{last_command}` returns the following error message: `{error_msg}`.
model,
};
let client = Client::new();
let res = client
.post(&request_url)
.header("Authorization", format!("Bearer {}", api_key))
.header("Content-Type", "application/json")
.json(&messages)
.timeout(std::time::Duration::from_secs(10))
.send();
let res = std::process::Command::new("curl")
.arg("-X")
.arg("POST")
.arg("-H")
.arg(format!("Authorization: Bearer {}", api_key))
.arg("-H")
.arg("Content-Type: application/json")
.arg("-d")
.arg(serde_json::to_string(&messages).unwrap())
.arg(request_url)
.output();
let res = match res {
Ok(res) => res,
Ok(res) => res.stdout,
Err(_) => {
return None;
}
};
let res = &res.text().unwrap();
let json: Value = {
let json = serde_json::from_str(res);
let json = serde_json::from_str(std::str::from_utf8(&res).unwrap());
if json.is_err() {
return None;
}