Skip to content

Commit

Permalink
chatgpt error fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JustFrederik committed May 1, 2023
1 parent d1e6700 commit f4dc4ce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"]

Expand Down
21 changes: 12 additions & 9 deletions src/translators/api/chatgpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -82,14 +83,16 @@ impl ChatGPTTranslator {
old_proxy: &str,
temperature: f32,
) -> Result<Self, Error> {
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 {
Expand Down

0 comments on commit f4dc4ce

Please sign in to comment.