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:
beyondkmp 2025-08-26 19:30:23 +08:00 committed by GitHub
parent bd4ba47e61
commit eac71f1f43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -22,12 +22,11 @@ import {
const logger = loggerService.withContext('TranslateService')
interface FetchTranslateProps {
content: string
assistant: TranslateAssistant
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()
if (!model) {
@ -55,7 +54,7 @@ async function fetchTranslate({ content, assistant, onResponse }: FetchTranslate
const params: CompletionsParams = {
callType: 'translate',
messages: content,
messages: 'do',
assistant: { ...assistant, model },
streamOutput: stream,
enableReasoning,
@ -83,7 +82,7 @@ export const translateText = async (
try {
const assistant = getDefaultTranslateAssistant(targetLanguage, text)
const translatedText = await fetchTranslate({ content: text, assistant, onResponse })
const translatedText = await fetchTranslate({ assistant, onResponse })
const trimmedText = translatedText.trim()