From f4dc4cefba5423bfa3479156b4f3cd4b9fd07b18 Mon Sep 17 00:00:00 2001 From: frederik Date: Mon, 1 May 2023 15:40:53 +0200 Subject: [PATCH] chatgpt error fix --- Cargo.toml | 4 ++-- src/translators/api/chatgpt.rs | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a98423b..715e281 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ whatlang = { version = "0.16.2", optional = true } lingua = { version = "1.4.0", optional = true } futures = { version = "0.3.28", optional = true } tokio = { version = "1.0", optional = true } -chatgpt_rs = { git = "https://github.com/JustFrederik/chatgpt_rs.git", optional = true } +chatgpt_rs = { git = "https://github.com/JustFrederik/chatgpt_rs.git", rev = "5f60316", features=["gpt3"], optional = true } regex = { version = "1.8.1", optional = true } serde_urlencoded = { version = "0.7.1", optional = true } select = { version = "0.6.0", optional = true } @@ -40,7 +40,7 @@ retries = ["dep:tokio", "dep:futures", "tokio?/full"] #Google is always available deepl = [] mymemory = [] -chatgpt = ["dep:chatgpt_rs"] +chatgpt = ["dep:chatgpt_rs", "chatgpt_rs?/gpt3"] libre = [] api = ["chatgpt", "deepl", "libre", "mymemory"] diff --git a/src/translators/api/chatgpt.rs b/src/translators/api/chatgpt.rs index eaa99b9..a046ac6 100644 --- a/src/translators/api/chatgpt.rs +++ b/src/translators/api/chatgpt.rs @@ -3,7 +3,8 @@ use chatgpt::client::ChatGPT; use chatgpt::config::{ChatGPTEngine, ModelConfiguration, OldChatGPTEngine, OldModelConfiguration}; use chatgpt::prelude::ChatMessage; use chatgpt::types::{CompletionResponse, Role}; -use reqwest::Client; +use reqwest::{Client, Url}; +use std::str::FromStr; use crate::error::Error; use crate::languages::Language; @@ -82,14 +83,16 @@ impl ChatGPTTranslator { old_proxy: &str, temperature: f32, ) -> Result { - let url = match proxy { - "" => "https://api.openai.com/v1/chat/completions".to_string(), - _ => proxy.to_string(), - }; - let oldurl = match old_proxy { - "" => "https://api.openai.com/v1/completions".to_string(), - _ => old_proxy.to_string(), - }; + let url = Url::from_str(match proxy { + "" => "https://api.openai.com/v1/chat/completions", + _ => proxy, + }) + .map_err(|e| Error::new("Failed to parse url", e))?; + let oldurl = Url::from_str(match old_proxy { + "" => "https://api.openai.com/v1/completions", + _ => old_proxy, + }) + .map_err(|e| Error::new("Failed to parse url", e))?; let client = match model { ChatGPTModel::GPT3 => { let config = OldModelConfiguration {