mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2026-02-02 07:35:10 +01:00
feat: using intermediate request
This commit is contained in:
parent
63821c277d
commit
f00bf0e4fc
2 changed files with 16 additions and 7 deletions
|
|
@ -185,8 +185,11 @@ If it's useful to you, **please share this project and spread the word**. Also c
|
||||||
> Configuration is done via environment variables:
|
> Configuration is done via environment variables:
|
||||||
>
|
>
|
||||||
> - `_PR_AI_API_KEY`: Your own API key
|
> - `_PR_AI_API_KEY`: Your own API key
|
||||||
> - `_PR_AI_URL`: URL used. Defaults to `https://api.groq.com/openai/v1/chat/completions`
|
> - `_PR_AI_URL`: URL used. Defaults to `https://iff.envs.net/completions.py`
|
||||||
> - `_PR_AI_MODEL`: Model used. Defaults to `llama3-8b-8192`
|
> - Any OpenAI compatible URL can be used, e.g.:
|
||||||
|
> - `https://api.openai.com/v1/chat/completions` (Note: OpenAI's ChatGPT is very slow)
|
||||||
|
> - `https://api.groq.com/openai/v1/chat/completions`
|
||||||
|
> - `_PR_AI_MODEL`: Model used. Defaults to `llama3-8b-8192` for fast response
|
||||||
> - `_PR_AI_DISABLE`: Setting to any value disables AI integration
|
> - `_PR_AI_DISABLE`: Setting to any value disables AI integration
|
||||||
> - `_PR_AI_LOCALE`: Locale in which the AI explains the suggestion. Defaults to user system locale
|
> - `_PR_AI_LOCALE`: Locale in which the AI explains the suggestion. Defaults to user system locale
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,8 @@ pub fn ai_suggestion(last_command: &str, error_msg: &str) -> Option<AISuggest> {
|
||||||
Ok(key) => Some(key),
|
Ok(key) => Some(key),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let env_key = option_env!("_DEF_PR_AI_API_KEY").map(|key| key.to_string());
|
let env_key = option_env!("_DEF_PR_AI_API_KEY").map(|key| key.to_string());
|
||||||
// I am keeping the key so anyone can use it out of the box
|
|
||||||
// Please, don't abuse the key and try to use your own key
|
|
||||||
if env_key.is_none() {
|
if env_key.is_none() {
|
||||||
Some("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".to_string())
|
Some("Y29uZ3JhdHVsYXRpb25zLCB5b3UgZm91bmQgdGhlIHNlY3JldCE=".to_string())
|
||||||
} else if env_key.as_ref().unwrap().is_empty() {
|
} else if env_key.as_ref().unwrap().is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -66,7 +64,7 @@ pub fn ai_suggestion(last_command: &str, error_msg: &str) -> Option<AISuggest> {
|
||||||
|
|
||||||
let request_url = match std::env::var("_PR_AI_URL") {
|
let request_url = match std::env::var("_PR_AI_URL") {
|
||||||
Ok(url) => url,
|
Ok(url) => url,
|
||||||
Err(_) => "https://api.groq.com/openai/v1/chat/completions".to_string(),
|
Err(_) => "https://iff.envs.net/completions.py".to_string(),
|
||||||
};
|
};
|
||||||
let model = match std::env::var("_PR_AI_MODEL") {
|
let model = match std::env::var("_PR_AI_MODEL") {
|
||||||
Ok(model) => model,
|
Ok(model) => model,
|
||||||
|
|
@ -162,7 +160,15 @@ The command `{last_command}` returns the following error message: `{error_msg}`.
|
||||||
};
|
};
|
||||||
res = String::from_utf8(out).unwrap();
|
res = String::from_utf8(out).unwrap();
|
||||||
}
|
}
|
||||||
let json: Value = serde_json::from_str(&res).unwrap();
|
let json: Value = {
|
||||||
|
let json = serde_json::from_str(&res);
|
||||||
|
if json.is_err() {
|
||||||
|
eprintln!("Failed to parse JSON response: {}", res);
|
||||||
|
return None;
|
||||||
|
} else {
|
||||||
|
json.unwrap()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let content = &json["choices"][0]["message"]["content"];
|
let content = &json["choices"][0]["message"]["content"];
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue