diff --git a/packages/plugin-translator/package.json b/packages/plugin-translator/package.json index 2bb5417..78be6bf 100644 --- a/packages/plugin-translator/package.json +++ b/packages/plugin-translator/package.json @@ -4,7 +4,7 @@ "novachat", "novachat-plugin" ], - "version": "0.2.0", + "version": "0.3.2", "license": "MIT", "type": "module", "files": [ @@ -13,7 +13,8 @@ "scripts": { "setup": "pnpm build", "build": "novachat", - "dev": "pnpm build --watch" + "dev": "pnpm build --watch", + "prepublishOnly": "pnpm build" }, "sideEffects": false, "devDependencies": { diff --git a/packages/plugin-translator/src/index.ts b/packages/plugin-translator/src/index.ts index 1a20bb4..a721d75 100644 --- a/packages/plugin-translator/src/index.ts +++ b/packages/plugin-translator/src/index.ts @@ -3,10 +3,6 @@ import { last } from 'lodash-es' import { franc } from 'franc-min' import { configuration } from './plugin.json' -const SYSTEM_MESSAGE = ` -You are a professional, authentic machine translation engine. Translate the following source text to {{to}}, Output translation directly without any additional text. -`.trim() - export async function activate() { await novachat.model.registerBot({ id: 'translator', @@ -14,11 +10,14 @@ export async function activate() { async *stream( query: novachat.QueryRequest, ): AsyncGenerator { + const systemPrompt = await novachat.setting.get('translator.systemPrompt') const lastMessage = last(query.messages) if (!lastMessage) { throw new Error('No last message') } - const defaultModel = await novachat.model.getDefault() + const defaultModel = + ((await novachat.setting.get('translator.model')) as string) ?? + (await novachat.model.getDefault())?.id if (!defaultModel) { throw new Error('No default model') } @@ -32,7 +31,7 @@ export async function activate() { messages: [ { role: 'system', - content: SYSTEM_MESSAGE.replace( + content: systemPrompt.replace( '{{to}}', translateConfig.enumDescriptions[ translateConfig.enum.indexOf(toLanguage) @@ -44,7 +43,7 @@ export async function activate() { content: lastMessage.content, }, ], - model: defaultModel.id, + model: defaultModel, }) for await (const it of stream) { yield it diff --git a/packages/plugin-translator/src/plugin.json b/packages/plugin-translator/src/plugin.json index 43fcf38..4b9a8ab 100644 --- a/packages/plugin-translator/src/plugin.json +++ b/packages/plugin-translator/src/plugin.json @@ -179,6 +179,17 @@ "Ilokano", "Қазақ" ] + }, + "translator.systemPrompt": { + "type": "string", + "description": "System prompt", + "default": "You are a professional, authentic machine translation engine. Translate the following source text to {{to}}, Output translation directly without any additional text.", + "format": "markdown" + }, + "translator.model": { + "type": "string", + "description": "Model", + "format": "model" } } }