add refinement to history
This commit is contained in:
@@ -49,6 +49,7 @@ const sourceText = ref('');
|
||||
const context = ref('');
|
||||
const targetText = ref('');
|
||||
const isTranslating = ref(false);
|
||||
const currentHistoryId = ref<string | null>(null);
|
||||
|
||||
interface Suggestion { id: number; text: string; importance: number; }
|
||||
interface EvaluationResult { score: number; analysis: string; suggestions?: Suggestion[]; }
|
||||
@@ -207,6 +208,12 @@ const refineTranslation = async () => {
|
||||
selectedSuggestionIds.value = [];
|
||||
}
|
||||
settings.addLog('response', 'Refinement completed');
|
||||
|
||||
if (currentHistoryId.value) {
|
||||
settings.updateHistoryItem(currentHistoryId.value, {
|
||||
targetText: targetText.value
|
||||
});
|
||||
}
|
||||
} catch (err: any) {
|
||||
const errorMsg = String(err);
|
||||
settings.addLog('error', errorMsg);
|
||||
@@ -220,6 +227,7 @@ const translate = async () => {
|
||||
if (!sourceText.value.trim() || isTranslating.value) return;
|
||||
|
||||
isTranslating.value = true;
|
||||
currentHistoryId.value = null;
|
||||
targetText.value = '';
|
||||
evaluationResult.value = null;
|
||||
|
||||
@@ -248,7 +256,7 @@ const translate = async () => {
|
||||
if (!settings.enableStreaming) targetText.value = response;
|
||||
settings.addLog('response', 'Translation completed');
|
||||
|
||||
settings.addHistory({
|
||||
currentHistoryId.value = settings.addHistory({
|
||||
sourceLang: { ...sourceLang.value },
|
||||
targetLang: { ...targetLang.value },
|
||||
sourceText: sourceText.value,
|
||||
|
||||
@@ -178,10 +178,11 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
const addHistory = (item: Omit<HistoryItem, 'id' | 'timestamp'>) => {
|
||||
const now = new Date();
|
||||
const timestamp = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')} ${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}:${String(now.getSeconds()).padStart(2, '0')}`;
|
||||
const id = crypto.randomUUID();
|
||||
|
||||
history.value.unshift({
|
||||
...item,
|
||||
id: crypto.randomUUID(),
|
||||
id,
|
||||
timestamp
|
||||
});
|
||||
|
||||
@@ -189,6 +190,15 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
if (history.value.length > 100) {
|
||||
history.value = history.value.slice(0, 100);
|
||||
}
|
||||
|
||||
return id;
|
||||
};
|
||||
|
||||
const updateHistoryItem = (id: string, updates: Partial<HistoryItem>) => {
|
||||
const index = history.value.findIndex(h => h.id === id);
|
||||
if (index !== -1) {
|
||||
history.value[index] = { ...history.value[index], ...updates };
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -210,6 +220,7 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
logs,
|
||||
history,
|
||||
addLog,
|
||||
addHistory
|
||||
addHistory,
|
||||
updateHistoryItem
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user