mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-08 22:39:36 +08:00
refactor(TranslateService): remove content parameter to reduce token (#9567)
* refactor(TranslateService): remove content parameter from fetchTranslate function - Updated fetchTranslate function to eliminate the content parameter, simplifying its signature. - Adjusted related calls to ensure compatibility with the new function definition, maintaining functionality while improving code clarity. * Update src/renderer/src/services/TranslateService.ts --------- Co-authored-by: Phantom <59059173+EurFelux@users.noreply.github.com>
This commit is contained in:
parent
bd4ba47e61
commit
eac71f1f43
@ -22,12 +22,11 @@ import {
|
|||||||
|
|
||||||
const logger = loggerService.withContext('TranslateService')
|
const logger = loggerService.withContext('TranslateService')
|
||||||
interface FetchTranslateProps {
|
interface FetchTranslateProps {
|
||||||
content: string
|
|
||||||
assistant: TranslateAssistant
|
assistant: TranslateAssistant
|
||||||
onResponse?: (text: string, isComplete: boolean) => void
|
onResponse?: (text: string, isComplete: boolean) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchTranslate({ content, assistant, onResponse }: FetchTranslateProps) {
|
async function fetchTranslate({ assistant, onResponse }: FetchTranslateProps) {
|
||||||
const model = getTranslateModel() || assistant.model || getDefaultModel()
|
const model = getTranslateModel() || assistant.model || getDefaultModel()
|
||||||
|
|
||||||
if (!model) {
|
if (!model) {
|
||||||
@ -55,7 +54,7 @@ async function fetchTranslate({ content, assistant, onResponse }: FetchTranslate
|
|||||||
|
|
||||||
const params: CompletionsParams = {
|
const params: CompletionsParams = {
|
||||||
callType: 'translate',
|
callType: 'translate',
|
||||||
messages: content,
|
messages: 'do',
|
||||||
assistant: { ...assistant, model },
|
assistant: { ...assistant, model },
|
||||||
streamOutput: stream,
|
streamOutput: stream,
|
||||||
enableReasoning,
|
enableReasoning,
|
||||||
@ -83,7 +82,7 @@ export const translateText = async (
|
|||||||
try {
|
try {
|
||||||
const assistant = getDefaultTranslateAssistant(targetLanguage, text)
|
const assistant = getDefaultTranslateAssistant(targetLanguage, text)
|
||||||
|
|
||||||
const translatedText = await fetchTranslate({ content: text, assistant, onResponse })
|
const translatedText = await fetchTranslate({ assistant, onResponse })
|
||||||
|
|
||||||
const trimmedText = translatedText.trim()
|
const trimmedText = translatedText.trim()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user