diff --git a/frontend/src/hook/useAi.ts b/frontend/src/hook/useAi.ts index 98f9ff6..352c0e1 100644 --- a/frontend/src/hook/useAi.ts +++ b/frontend/src/hook/useAi.ts @@ -10,19 +10,32 @@ export async function askAi(question: any, action: string) { if (!model) { return '请先设置模型' } - let prompt = await assistantStore.getPrompt(action) - if (!prompt) { - return '请先设置prompt' - } - if (question.content) { - prompt = prompt.replace('{content}', question.content) - } - if (question.title) { - prompt = prompt.replace('{title}', question.title) - } - if (question.category) { - prompt = prompt.replace('{category}', question.category) + let prompt = "" + if (action === 'creation_ask') { + if (question.title) { + prompt = question.title + } else { + return "" + } + if (question.content || question.content != "") { + prompt = `${prompt} \n ${question.content}` + } + } else { + prompt = await assistantStore.getPrompt(action) + if (!prompt) { + return '请先设置prompt' + } + if (question.content) { + prompt = prompt.replace('{content}', question.content) + } + if (question.title) { + prompt = prompt.replace('{title}', question.title) + } + if (question.category) { + prompt = prompt.replace('{category}', question.category) + } } + const apiUrl = config.aiUrl + '/ai/chat' const postMsg: any = { messages: [ @@ -43,7 +56,7 @@ export async function askAi(question: any, action: string) { const data = await complain.json() return data.choices[0].message.content } catch (error) { - return '请求失败'+error + return '请求失败' + error } diff --git a/packages/word/src/editor/core/command/CommandAdapt.ts b/packages/word/src/editor/core/command/CommandAdapt.ts index c1b3154..abe2a6f 100644 --- a/packages/word/src/editor/core/command/CommandAdapt.ts +++ b/packages/word/src/editor/core/command/CommandAdapt.ts @@ -1203,18 +1203,24 @@ export class CommandAdapt { public getSearchNavigateInfo(): null | INavigateInfo { return this.searchManager.getSearchNavigateInfo() } - + public checkPayload(payload: string): boolean { + if (!payload || payload.includes(ZERO)) { + return true; + } + return false; + } public replace(payload: string, aiArticle?: boolean) { // console.log('替换', payload) const isReadonly = this.draw.isReadonly() if (isReadonly) return - if(aiArticle == true) { + if (aiArticle == true) { if (!payload) return } else { // console.log('zero:', new RegExp(`${ZERO}`, 'g').test(payload)) - - if (!payload || new RegExp(`${ZERO}`, 'g').test(payload)) return + + //if (!payload || new RegExp(`${ZERO}`, 'g').test(payload)) return + if(this.checkPayload(payload))return } // if (!payload || (isZero && aiArticle)) return const matchList = this.draw.getSearch().getSearchMatchList() @@ -1841,8 +1847,8 @@ export class CommandAdapt { const getElementList = (htmlText?: string) => htmlText !== undefined ? getElementListByHTML(htmlText, { - innerWidth - }) + innerWidth + }) : undefined this.setValue({ header: getElementList(header), @@ -2076,7 +2082,7 @@ export class CommandAdapt { if ( nextElement.level && titleOrderNumberMapping[nextElement.level] <= - titleOrderNumberMapping[element.level!] + titleOrderNumberMapping[element.level!] ) { break }