Skip to content

Commit

Permalink
feat: 支持设置代理
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghonglu.neo committed Mar 20, 2023
1 parent c821ca4 commit 8a4eaff
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
13 changes: 13 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.2.4", features = ["dialog-all", "fs-all", "http-all", "os-all", "path-all", "shell-open", "window-close", "window-hide", "window-show", "window-start-dragging"] }
tauri-plugin-log = { git = "https://github.com/lencx/tauri-plugins-workspace", branch = "dev", features = ["colored"] }
tokio = "1.26.0"
reqwest = { version="0.11.14", features= ["stream"] }
reqwest = { version="0.11.14", features= ["stream", "socks"] }
rocket = {"git" = "https://github.com/SergioBenitez/Rocket"}
bytes = "*"
tokio-util = {version="0.7.7", feature= ["io"] }
Expand Down
10 changes: 9 additions & 1 deletion src-tauri/src/app/cmd/gpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ pub async fn fetch_chat_api(
"temperature": temperature,
"stream": true
});
let client = reqwest::Client::new();
let mut client_builder = reqwest::Client::builder();

let p = proxy.unwrap_or(String::from(""));
log::info!("proxy is: {}", p);
if p.len()>0 {
let proxy = reqwest::Proxy::all(p).unwrap();
client_builder = client_builder.proxy(proxy);
}
let client = client_builder.build().unwrap();
let res = client.post(url)
.header("Content-Type", "application/json")
.header("Authorization", format!("Bearer {}", token))
Expand Down
10 changes: 5 additions & 5 deletions src/components/common/Setting/User.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const rules: FormRules = {
if (!value || value.length === 0)
return true
else if (!/^(socks5|http|https):\/\/.+$/.test(value))
return new Error('请输入正确的proxy')
else if (!/^(socks5):\/\/.+$/.test(value))
return new Error('Proxy must start with socks5:https://')
return true
},
trigger: ['input', 'blur'],
Expand Down Expand Up @@ -98,9 +98,9 @@ function saveUserInfo() {
<NFormItem path="modelName" label="Model Name">
<NSelect v-model:value="model.modelName" placeholder="Select" :options="models" />
</NFormItem>
<!-- <NFormItem path="proxy" label="Proxy">
<NInput v-model:value="model.proxy" placeholder="http:https://127.0.0.1:7890" />
</NFormItem> -->
<NFormItem path="proxy" label="Proxy">
<NInput v-model:value="model.proxy" placeholder="socks5:https://127.0.0.1:7890" />
</NFormItem>
<div class="flex items-center justify-end">
<NButton size="small" @click="saveUserInfo">
{{ $t('setting.saveUserInfoBtn') }}
Expand Down

0 comments on commit 8a4eaff

Please sign in to comment.