Skip to content

Commit

Permalink
feat:更新默认请求地址
Browse files Browse the repository at this point in the history
fix:win部分修改缩放后导致输入或快捷键显示翻译窗口时自动增加问题
feat:流式翻译服务异常时输出详细问题
  • Loading branch information
ByLiangCheng committed Oct 10, 2023
1 parent b1f89f3 commit 6b78125
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 17 deletions.
4 changes: 2 additions & 2 deletions electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import vue from '@vitejs/plugin-vue'
// @ts-ignore 抑制错误校验问题
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'

const BASE_API = 'https://timerecord.cn/apis/'
const BASE_API = 'https://ink.timerecord.cn/apis/'

export default defineConfig({
main: {
plugins: [externalizeDepsPlugin()],
plugins: [externalizeDepsPlugin()]
},
preload: {
plugins: [externalizeDepsPlugin()],
Expand Down
6 changes: 6 additions & 0 deletions src/main/service/Win.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ class WinEvent {
// win.setMaximumSize(width, height)
win.setMinimumSize(450, height)
win.setSize(width, height)
const newWidth = win.getSize()[0]
if (newWidth != width) {
if (newWidth > width) {
win.setSize(width - (newWidth - width), height)
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/utils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { injectAgent } from './RequestUtil'
import StoreService from '../service/StoreService'
import { isNotNull, isNull } from '../../common/utils/validate'

const BASE_API = 'https://timerecord.cn/apis/'
const BASE_API = 'https://ink.timerecord.cn/apis/'

// 创建 axios
const service = axios.create({
Expand Down
19 changes: 12 additions & 7 deletions src/renderer/src/channel/AzureOpenAIChannelRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ class AzureOpenAIChannelRequest {
let contentPrompt = `${quoteProcessor.quoteStart}${info.translateContent}${quoteProcessor.quoteEnd}`
if (languageResultType === '文字润色') {
rolePrompt =
'You are a professional text summarizer, you can only summarize the text, don\'t interpret it.'
"You are a professional text summarizer, you can only summarize the text, don't interpret it."
commandPrompt = `Please polish this text in ${languageType}. Only polish the text between ${quoteProcessor.quoteStart} and ${quoteProcessor.quoteEnd}.`
} else if (languageResultType === '总结') {
rolePrompt =
'You are a professional text summarizer, you can only summarize the text, don\'t interpret it.'
"You are a professional text summarizer, you can only summarize the text, don't interpret it."
commandPrompt = `Please summarize this text in the most concise language and must use ${languageType} language! Only summarize the text between ${quoteProcessor.quoteStart} and ${quoteProcessor.quoteEnd}.`
contentPrompt = `${quoteProcessor.quoteStart}${info.translateContent}${quoteProcessor.quoteEnd}`
} else if (languageResultType === '分析') {
Expand Down Expand Up @@ -210,9 +210,10 @@ class AzureOpenAIChannelRequest {
let text = ''
await fetchEventSource(
info.endpoint +
'/openai/deployments/' +
info.deploymentName +
'/chat/completions?api-version=2023-05-15', {
'/openai/deployments/' +
info.deploymentName +
'/chat/completions?api-version=2023-05-15',
{
method: 'POST',
body: JSON.stringify(data),
headers: {
Expand All @@ -226,7 +227,10 @@ class AzureOpenAIChannelRequest {
) {
return // everything's good
} else {
window.api.logInfoEvent('[AzureOpenAI翻译事件] - error : 连接失败')
window.api.logInfoEvent('[AzureOpenAI翻译事件] - error 连接失败 :', {
status: response.status,
statusText: response.statusText
})
window.api['agentApiTranslateCallback'](
R.errorD(
new AgentTranslateCallbackVo(info, {
Expand Down Expand Up @@ -300,7 +304,8 @@ class AzureOpenAIChannelRequest {
)
throw err
}
})
}
)
}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/renderer/src/channel/OpenAIChannelRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ class OpenAIChannelRequest {
let contentPrompt = `${quoteProcessor.quoteStart}${info.translateContent}${quoteProcessor.quoteEnd}`
if (languageResultType === '文字润色') {
rolePrompt =
'You are a professional text summarizer, you can only summarize the text, don\'t interpret it.'
"You are a professional text summarizer, you can only summarize the text, don't interpret it."
commandPrompt = `Please polish this text in ${languageType}. Only polish the text between ${quoteProcessor.quoteStart} and ${quoteProcessor.quoteEnd}.`
} else if (languageResultType === '总结') {
rolePrompt =
'You are a professional text summarizer, you can only summarize the text, don\'t interpret it.'
"You are a professional text summarizer, you can only summarize the text, don't interpret it."
commandPrompt = `Please summarize this text in the most concise language and must use ${languageType} language! Only summarize the text between ${quoteProcessor.quoteStart} and ${quoteProcessor.quoteEnd}.`
contentPrompt = `${quoteProcessor.quoteStart}${info.translateContent}${quoteProcessor.quoteEnd}`
} else if (languageResultType === '分析') {
Expand Down Expand Up @@ -223,7 +223,10 @@ class OpenAIChannelRequest {
) {
return // everything's good
} else {
window.api.logInfoEvent('[OpenAI翻译事件] - error : 连接失败')
window.api.logInfoEvent('[OpenAI翻译事件] - error 连接失败 :', {
status: response.status,
statusText: response.statusText
})
window.api['agentApiTranslateCallback'](
R.errorD(
new AgentTranslateCallbackVo(info, {
Expand Down
10 changes: 6 additions & 4 deletions src/renderer/src/channel/TTimeAIChannelRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { isNotNull } from '../../../common/utils/validate'
import { cacheGet } from '../utils/cacheUtil'

class TTimeAIChannelRequest {

/**
* OpenAI - 翻译
*
Expand All @@ -22,7 +21,7 @@ class TTimeAIChannelRequest {
)
let text = ''

await fetchEventSource('https://timerecord.cn/apis/translate/translateAi/stream', {
await fetchEventSource('https://ink.timerecord.cn/apis/translate/translateAi/stream', {
method: 'POST',
body: JSON.stringify({
languageType: info.languageType,
Expand All @@ -31,13 +30,16 @@ class TTimeAIChannelRequest {
}),
headers: {
'Content-Type': 'application/json',
'token': cacheGet("token")
token: cacheGet('token')
},
async onopen(response) {
if (response.ok && response.headers.get('content-type') === EventStreamContentType) {
return // everything's good
} else {
window.api.logInfoEvent('[TTimeAI翻译事件] - error 连接失败')
window.api.logInfoEvent('[TTimeAI翻译事件] - error 连接失败 :', {
status: response.status,
statusText: response.statusText
})
window.api['agentApiTranslateCallback'](
R.errorD(
new AgentTranslateCallbackVo(info, {
Expand Down

0 comments on commit 6b78125

Please sign in to comment.