Compare commits

...

2 Commits

Author SHA1 Message Date
b1ek 3626d07d83
modify config to not include model versions 2024-05-05 16:38:28 +10:00
b1ek 063b3317e7
mimic updated API 2024-05-05 16:35:59 +10:00
2 changed files with 14 additions and 11 deletions

View File

@ -5,17 +5,20 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Model {
#[serde(rename = "claude-instant-1.2")]
Claude12,
#[serde(rename = "gpt-3.5-turbo-0125")]
GPT35,
Claude,
GPT3,
}
impl ToString for Model {
fn to_string(&self) -> String {
match self {
Self::Claude12 => String::from("claude-instant-1.2"),
Self::GPT35 => String::from("gpt-3.5-turbo-0125"),
Self::Claude12 => panic!("Your config is outdated! Please delete your ~/.config/hey directory"),
Self::GPT35 => panic!("Your config is outdated! Please delete your ~/.config/hey directory"),
Self::Claude => String::from("claude-3-haiku-20240307"),
Self::GPT3 => String::from("gpt-3.5-turbo-0125"),
}
}
}
@ -29,7 +32,7 @@ pub struct Config {
impl Default for Config {
fn default() -> Self {
Self {
model: Model::Claude12,
model: Model::Claude,
tos: false
}
}
@ -76,7 +79,10 @@ impl Config {
if ! file_path.is_file() {
Ok(Self::default())
} else {
Ok(toml::from_str(&fs::read_to_string(file_path)?)?)
let conf: Config = toml::from_str(&fs::read_to_string(file_path)?)?;
conf.model.to_string(); // so that it would panic if the config is outdated
Ok(conf)
}
}
}

View File

@ -34,9 +34,7 @@ struct ChatChunk {
pub role: String,
pub message: String,
pub created: u64,
pub id: String,
pub action: String,
pub model: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@ -50,7 +48,7 @@ struct ErrChatChunk {
fn get_headers() -> HeaderMap {
let mut map = HeaderMap::new();
map.insert("Host", HeaderValue::from_static("duckduckgo.com"));
map.insert("Accept", HeaderValue::from_static("*/*"));
map.insert("Accept", HeaderValue::from_static("text/event-stream"));
map.insert("Accept-Language", HeaderValue::from_static("en-US,en;q=0.5"));
map.insert("Accept-Encoding", HeaderValue::from_static("gzip, deflate, br"));
map.insert("Referer", HeaderValue::from_static("https://duckduckgo.com/"));
@ -58,7 +56,7 @@ fn get_headers() -> HeaderMap {
map.insert("DNT", HeaderValue::from_static("1"));
map.insert("Sec-GPC", HeaderValue::from_static("1"));
map.insert("Connection", HeaderValue::from_static("keep-alive"));
map.insert("Cookie", HeaderValue::from_static("dcm=3"));
map.insert("Cookie", HeaderValue::from_static("dcm=3; ay=b"));
map.insert("Sec-Fetch-Dest", HeaderValue::from_static("empty"));
map.insert("Sec-Fetch-Mode", HeaderValue::from_static("cors"));
map.insert("Sec-Fetch-Site", HeaderValue::from_static("same-origin"));
@ -104,7 +102,6 @@ async fn get_res<'a>(cli: &Client, query: String, vqd: String, cache: &'a mut Ca
let payload = serde_json::to_string(&payload).unwrap();
let req = cli.post("https://duckduckgo.com/duckchat/v1/chat")
// .headers(get_headers())
.header("Content-Type", "application/json")
.header("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:124.0) Gecko/20100101 Firefox/124.0")
.header("x-vqd-4", vqd.clone())