mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-11 10:33:54 +00:00
feat: 添加语言偏好提示功能到AI系统提示
This commit is contained in:
parent
19d79ab055
commit
b9215e2410
@ -457,7 +457,7 @@ import SearchBox from "../components/SearchBox.vue";
|
||||
import AIAssistant from "../components/AIAssistant.vue";
|
||||
import transformEmojiToHtml from "../utils/emoji";
|
||||
import {languageName} from "../language";
|
||||
import {AINormalizeJsonContent, PROJECT_AI_SYSTEM_PROMPT} from "../utils/ai";
|
||||
import {AINormalizeJsonContent, PROJECT_AI_SYSTEM_PROMPT, withLanguagePreferencePrompt} from "../utils/ai";
|
||||
import Draggable from 'vuedraggable'
|
||||
|
||||
export default {
|
||||
@ -1121,7 +1121,7 @@ export default {
|
||||
|
||||
handleProjectAIBeforeSend(context = []) {
|
||||
const prepared = [
|
||||
['system', PROJECT_AI_SYSTEM_PROMPT]
|
||||
['system', withLanguagePreferencePrompt(PROJECT_AI_SYSTEM_PROMPT)]
|
||||
];
|
||||
const contextPrompt = this.buildProjectAIContextData();
|
||||
if (contextPrompt) {
|
||||
|
||||
@ -344,7 +344,7 @@ import {inputLoadAdd, inputLoadIsLast, inputLoadRemove} from "./one";
|
||||
import {languageList, languageName} from "../../../../language";
|
||||
import {isMarkdownFormat, MarkdownConver} from "../../../../utils/markdown";
|
||||
import {cutText, extractPlainText} from "../../../../utils/text";
|
||||
import {MESSAGE_AI_SYSTEM_PROMPT} from "../../../../utils/ai";
|
||||
import {MESSAGE_AI_SYSTEM_PROMPT, withLanguagePreferencePrompt} from "../../../../utils/ai";
|
||||
import emitter from "../../../../store/events";
|
||||
import historyMixin from "./history";
|
||||
|
||||
@ -1918,7 +1918,7 @@ export default {
|
||||
|
||||
handleMessageAIBeforeSend(context = []) {
|
||||
const prepared = [
|
||||
['system', MESSAGE_AI_SYSTEM_PROMPT]
|
||||
['system', withLanguagePreferencePrompt(MESSAGE_AI_SYSTEM_PROMPT)]
|
||||
];
|
||||
let assistantContext = this.buildMessageAssistantContext();
|
||||
if (assistantContext) {
|
||||
|
||||
@ -75,7 +75,7 @@ const VMPreview = () => import('../../../components/VMEditor/preview');
|
||||
import {mapState} from "vuex";
|
||||
import emitter from "../../../store/events";
|
||||
import {extractPlainText} from "../../../utils/text";
|
||||
import {REPORT_ANALYSIS_SYSTEM_PROMPT} from "../../../utils/ai";
|
||||
import {REPORT_ANALYSIS_SYSTEM_PROMPT, withLanguagePreferencePrompt} from "../../../utils/ai";
|
||||
|
||||
export default {
|
||||
name: "ReportDetail",
|
||||
@ -184,7 +184,7 @@ export default {
|
||||
|
||||
handleReportAnalysisBeforeSend(context = []) {
|
||||
const prepared = [
|
||||
['system', REPORT_ANALYSIS_SYSTEM_PROMPT]
|
||||
['system', withLanguagePreferencePrompt(REPORT_ANALYSIS_SYSTEM_PROMPT)]
|
||||
];
|
||||
const contextPrompt = this.buildReportAnalysisContextData();
|
||||
if (contextPrompt) {
|
||||
|
||||
@ -64,7 +64,7 @@ import {mapState} from "vuex";
|
||||
import emitter from "../../../store/events";
|
||||
import {MarkdownConver} from "../../../utils/markdown";
|
||||
import {extractPlainText} from "../../../utils/text";
|
||||
import {REPORT_AI_SYSTEM_PROMPT} from "../../../utils/ai";
|
||||
import {REPORT_AI_SYSTEM_PROMPT, withLanguagePreferencePrompt} from "../../../utils/ai";
|
||||
|
||||
const TEditor = () => import('../../../components/TEditor');
|
||||
export default {
|
||||
@ -302,7 +302,7 @@ export default {
|
||||
|
||||
handleReportAIBeforeSend(context = []) {
|
||||
const prepared = [
|
||||
['system', REPORT_AI_SYSTEM_PROMPT]
|
||||
['system', withLanguagePreferencePrompt(REPORT_AI_SYSTEM_PROMPT)]
|
||||
];
|
||||
const contextPrompt = this.buildReportAIContextData();
|
||||
if (contextPrompt) {
|
||||
|
||||
@ -202,7 +202,7 @@ import TEditorTask from "../../../components/TEditorTask.vue";
|
||||
import nostyle from "../../../components/VMEditor/engine/nostyle";
|
||||
import {MarkdownConver} from "../../../utils/markdown";
|
||||
import {extractPlainText} from "../../../utils/text";
|
||||
import {AINormalizeJsonContent, TASK_AI_SYSTEM_PROMPT} from "../../../utils/ai";
|
||||
import {AINormalizeJsonContent, TASK_AI_SYSTEM_PROMPT, withLanguagePreferencePrompt} from "../../../utils/ai";
|
||||
|
||||
export default {
|
||||
name: "TaskAdd",
|
||||
@ -713,7 +713,7 @@ export default {
|
||||
|
||||
handleTaskAIBeforeSend(context = []) {
|
||||
const prepared = [
|
||||
['system', TASK_AI_SYSTEM_PROMPT]
|
||||
['system', withLanguagePreferencePrompt(TASK_AI_SYSTEM_PROMPT)]
|
||||
];
|
||||
const contextPrompt = this.buildTaskAIContextData();
|
||||
if (contextPrompt) {
|
||||
|
||||
15
resources/assets/js/utils/ai.js
vendored
15
resources/assets/js/utils/ai.js
vendored
@ -1,3 +1,17 @@
|
||||
import {languageList, languageName} from "../language";
|
||||
|
||||
const withLanguagePreferencePrompt = (prompt, extraInstruction = null) => {
|
||||
if (typeof prompt !== 'string' || !prompt) {
|
||||
return prompt;
|
||||
}
|
||||
const label = languageList[languageName] || languageName || '';
|
||||
if (!label) {
|
||||
return prompt;
|
||||
}
|
||||
const instruction = extraInstruction || '除非我在后续输入中明确指定其他语言,否则请使用该语言进行思考并输出所有内容。';
|
||||
return `${prompt}\n\n当前我使用的语言是:${label},${instruction}`;
|
||||
};
|
||||
|
||||
const AIModelNames = (str) => {
|
||||
const lines = str.split('\n').filter(line => line.trim());
|
||||
|
||||
@ -355,4 +369,5 @@ export {
|
||||
PROJECT_AI_SYSTEM_PROMPT,
|
||||
REPORT_AI_SYSTEM_PROMPT,
|
||||
REPORT_ANALYSIS_SYSTEM_PROMPT,
|
||||
withLanguagePreferencePrompt,
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user