mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-13 12:02:51 +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 AIAssistant from "../components/AIAssistant.vue";
|
||||||
import transformEmojiToHtml from "../utils/emoji";
|
import transformEmojiToHtml from "../utils/emoji";
|
||||||
import {languageName} from "../language";
|
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'
|
import Draggable from 'vuedraggable'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -1121,7 +1121,7 @@ export default {
|
|||||||
|
|
||||||
handleProjectAIBeforeSend(context = []) {
|
handleProjectAIBeforeSend(context = []) {
|
||||||
const prepared = [
|
const prepared = [
|
||||||
['system', PROJECT_AI_SYSTEM_PROMPT]
|
['system', withLanguagePreferencePrompt(PROJECT_AI_SYSTEM_PROMPT)]
|
||||||
];
|
];
|
||||||
const contextPrompt = this.buildProjectAIContextData();
|
const contextPrompt = this.buildProjectAIContextData();
|
||||||
if (contextPrompt) {
|
if (contextPrompt) {
|
||||||
|
|||||||
@ -344,7 +344,7 @@ import {inputLoadAdd, inputLoadIsLast, inputLoadRemove} from "./one";
|
|||||||
import {languageList, languageName} from "../../../../language";
|
import {languageList, languageName} from "../../../../language";
|
||||||
import {isMarkdownFormat, MarkdownConver} from "../../../../utils/markdown";
|
import {isMarkdownFormat, MarkdownConver} from "../../../../utils/markdown";
|
||||||
import {cutText, extractPlainText} from "../../../../utils/text";
|
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 emitter from "../../../../store/events";
|
||||||
import historyMixin from "./history";
|
import historyMixin from "./history";
|
||||||
|
|
||||||
@ -1918,7 +1918,7 @@ export default {
|
|||||||
|
|
||||||
handleMessageAIBeforeSend(context = []) {
|
handleMessageAIBeforeSend(context = []) {
|
||||||
const prepared = [
|
const prepared = [
|
||||||
['system', MESSAGE_AI_SYSTEM_PROMPT]
|
['system', withLanguagePreferencePrompt(MESSAGE_AI_SYSTEM_PROMPT)]
|
||||||
];
|
];
|
||||||
let assistantContext = this.buildMessageAssistantContext();
|
let assistantContext = this.buildMessageAssistantContext();
|
||||||
if (assistantContext) {
|
if (assistantContext) {
|
||||||
|
|||||||
@ -75,7 +75,7 @@ const VMPreview = () => import('../../../components/VMEditor/preview');
|
|||||||
import {mapState} from "vuex";
|
import {mapState} from "vuex";
|
||||||
import emitter from "../../../store/events";
|
import emitter from "../../../store/events";
|
||||||
import {extractPlainText} from "../../../utils/text";
|
import {extractPlainText} from "../../../utils/text";
|
||||||
import {REPORT_ANALYSIS_SYSTEM_PROMPT} from "../../../utils/ai";
|
import {REPORT_ANALYSIS_SYSTEM_PROMPT, withLanguagePreferencePrompt} from "../../../utils/ai";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "ReportDetail",
|
name: "ReportDetail",
|
||||||
@ -184,7 +184,7 @@ export default {
|
|||||||
|
|
||||||
handleReportAnalysisBeforeSend(context = []) {
|
handleReportAnalysisBeforeSend(context = []) {
|
||||||
const prepared = [
|
const prepared = [
|
||||||
['system', REPORT_ANALYSIS_SYSTEM_PROMPT]
|
['system', withLanguagePreferencePrompt(REPORT_ANALYSIS_SYSTEM_PROMPT)]
|
||||||
];
|
];
|
||||||
const contextPrompt = this.buildReportAnalysisContextData();
|
const contextPrompt = this.buildReportAnalysisContextData();
|
||||||
if (contextPrompt) {
|
if (contextPrompt) {
|
||||||
|
|||||||
@ -64,7 +64,7 @@ import {mapState} from "vuex";
|
|||||||
import emitter from "../../../store/events";
|
import emitter from "../../../store/events";
|
||||||
import {MarkdownConver} from "../../../utils/markdown";
|
import {MarkdownConver} from "../../../utils/markdown";
|
||||||
import {extractPlainText} from "../../../utils/text";
|
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');
|
const TEditor = () => import('../../../components/TEditor');
|
||||||
export default {
|
export default {
|
||||||
@ -302,7 +302,7 @@ export default {
|
|||||||
|
|
||||||
handleReportAIBeforeSend(context = []) {
|
handleReportAIBeforeSend(context = []) {
|
||||||
const prepared = [
|
const prepared = [
|
||||||
['system', REPORT_AI_SYSTEM_PROMPT]
|
['system', withLanguagePreferencePrompt(REPORT_AI_SYSTEM_PROMPT)]
|
||||||
];
|
];
|
||||||
const contextPrompt = this.buildReportAIContextData();
|
const contextPrompt = this.buildReportAIContextData();
|
||||||
if (contextPrompt) {
|
if (contextPrompt) {
|
||||||
|
|||||||
@ -202,7 +202,7 @@ import TEditorTask from "../../../components/TEditorTask.vue";
|
|||||||
import nostyle from "../../../components/VMEditor/engine/nostyle";
|
import nostyle from "../../../components/VMEditor/engine/nostyle";
|
||||||
import {MarkdownConver} from "../../../utils/markdown";
|
import {MarkdownConver} from "../../../utils/markdown";
|
||||||
import {extractPlainText} from "../../../utils/text";
|
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 {
|
export default {
|
||||||
name: "TaskAdd",
|
name: "TaskAdd",
|
||||||
@ -713,7 +713,7 @@ export default {
|
|||||||
|
|
||||||
handleTaskAIBeforeSend(context = []) {
|
handleTaskAIBeforeSend(context = []) {
|
||||||
const prepared = [
|
const prepared = [
|
||||||
['system', TASK_AI_SYSTEM_PROMPT]
|
['system', withLanguagePreferencePrompt(TASK_AI_SYSTEM_PROMPT)]
|
||||||
];
|
];
|
||||||
const contextPrompt = this.buildTaskAIContextData();
|
const contextPrompt = this.buildTaskAIContextData();
|
||||||
if (contextPrompt) {
|
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 AIModelNames = (str) => {
|
||||||
const lines = str.split('\n').filter(line => line.trim());
|
const lines = str.split('\n').filter(line => line.trim());
|
||||||
|
|
||||||
@ -355,4 +369,5 @@ export {
|
|||||||
PROJECT_AI_SYSTEM_PROMPT,
|
PROJECT_AI_SYSTEM_PROMPT,
|
||||||
REPORT_AI_SYSTEM_PROMPT,
|
REPORT_AI_SYSTEM_PROMPT,
|
||||||
REPORT_ANALYSIS_SYSTEM_PROMPT,
|
REPORT_ANALYSIS_SYSTEM_PROMPT,
|
||||||
|
withLanguagePreferencePrompt,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user