first runnable
This commit is contained in:
53
src/stores/settings.ts
Normal file
53
src/stores/settings.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { ref } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import { useLocalStorage } from '@vueuse/core';
|
||||
|
||||
export interface Language {
|
||||
name: string;
|
||||
code: string;
|
||||
}
|
||||
|
||||
export const LANGUAGES: Language[] = [
|
||||
{ name: 'English', code: 'en' },
|
||||
{ name: 'Chinese', code: 'zh-Hans' },
|
||||
{ name: 'Japanese', code: 'ja' },
|
||||
{ name: 'Spanish', code: 'es' },
|
||||
{ name: 'French', code: 'fr' },
|
||||
{ name: 'German', code: 'de' },
|
||||
];
|
||||
|
||||
export const DEFAULT_TEMPLATE = `You are a professional {SOURCE_LANG} ({SOURCE_CODE}) to {TARGET_LANG} ({TARGET_CODE}) translator. Your goal is to accurately convey the meaning and nuances of the original {SOURCE_LANG} text while adhering to {TARGET_LANG} grammar, vocabulary, and cultural sensitivities.
|
||||
Produce only the {TARGET_LANG} translation, without any additional explanations or commentary. Please translate the following {SOURCE_LANG} text into {TARGET_LANG}:
|
||||
|
||||
{TEXT}`;
|
||||
|
||||
export const useSettingsStore = defineStore('settings', () => {
|
||||
const ollamaApiAddress = useLocalStorage('ollama-api-address', 'http://localhost:11434');
|
||||
const modelName = useLocalStorage('model-name', 'translategemma:12b');
|
||||
const enableStreaming = useLocalStorage('enable-streaming', true);
|
||||
const systemPromptTemplate = useLocalStorage('system-prompt-template', DEFAULT_TEMPLATE);
|
||||
const sourceLang = useLocalStorage('source-lang', LANGUAGES[1]); // Default Chinese
|
||||
const targetLang = useLocalStorage('target-lang', LANGUAGES[0]); // Default English
|
||||
|
||||
const logs = ref<{ timestamp: string; type: 'request' | 'response' | 'error'; content: any }[]>([]);
|
||||
|
||||
const addLog = (type: 'request' | 'response' | 'error', content: any) => {
|
||||
logs.value.unshift({
|
||||
timestamp: new Date().toLocaleTimeString(),
|
||||
type,
|
||||
content
|
||||
});
|
||||
if (logs.value.length > 20) logs.value.pop(); // Keep last 20 logs
|
||||
};
|
||||
|
||||
return {
|
||||
ollamaApiAddress,
|
||||
modelName,
|
||||
enableStreaming,
|
||||
systemPromptTemplate,
|
||||
sourceLang,
|
||||
targetLang,
|
||||
logs,
|
||||
addLog
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user