Skip to content

Commit

Permalink
fix: 修复openai请求无法走系统代理的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Pylogmon committed Mar 11, 2023
1 parent 4fd2b0b commit c03125d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 25 deletions.
20 changes: 13 additions & 7 deletions src/interfaces/openai.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fetch } from '@tauri-apps/api/http';
import axios from 'axios';
import { get } from '../global/config';

export const info = {
Expand Down Expand Up @@ -55,14 +56,19 @@ export async function translate(text, from, to) {
]
};

const res = await fetch(`https://${domain}/v1/chat/completions`, {
method: 'POST',
// const res = await fetch(`https://${domain}/v1/chat/completions`, {
// method: 'POST',
// headers: headers,
// body: {
// type: 'Json',
// payload: body
// },
// timeout: 30
// })

const res = await axios.post(`https://${domain}/v1/chat/completions`, body, {
headers: headers,
body: {
type: 'Json',
payload: body
},
timeout: 10
timeout: 30000
})

const { choices } = res.data;
Expand Down
17 changes: 11 additions & 6 deletions src/interfaces/openai_code.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ export async function translate(text, from, to) {
]
};

const res = await fetch(`https://${domain}/v1/chat/completions`, {
method: 'POST',
// const res = await fetch(`https://${domain}/v1/chat/completions`, {
// method: 'POST',
// headers: headers,
// body: {
// type: 'Json',
// payload: body
// }
// })

const res = await axios.post(`https://${domain}/v1/chat/completions`, body, {
headers: headers,
body: {
type: 'Json',
payload: body
}
timeout: 30000
})

const { choices } = res.data;
Expand Down
17 changes: 11 additions & 6 deletions src/interfaces/openai_polish.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ export async function translate(text, from, to) {
]
};

const res = await fetch(`https://${domain}/v1/chat/completions`, {
method: 'POST',
// const res = await fetch(`https://${domain}/v1/chat/completions`, {
// method: 'POST',
// headers: headers,
// body: {
// type: 'Json',
// payload: body
// }
// })

const res = await axios.post(`https://${domain}/v1/chat/completions`, body, {
headers: headers,
body: {
type: 'Json',
payload: body
}
timeout: 30000
})

const { choices } = res.data;
Expand Down
17 changes: 11 additions & 6 deletions src/interfaces/openai_summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ export async function translate(text, from, to) {
]
};

const res = await fetch(`https://${domain}/v1/chat/completions`, {
method: 'POST',
// const res = await fetch(`https://${domain}/v1/chat/completions`, {
// method: 'POST',
// headers: headers,
// body: {
// type: 'Json',
// payload: body
// }
// })

const res = await axios.post(`https://${domain}/v1/chat/completions`, body, {
headers: headers,
body: {
type: 'Json',
payload: body
}
timeout: 30000
})

const { choices } = res.data;
Expand Down

0 comments on commit c03125d

Please sign in to comment.