Browse Source

change ai replace

master
godo 6 months ago
parent
commit
af6121d337
  1. 17
      frontend/src/hook/useAi.ts
  2. 12
      packages/word/src/editor/core/command/CommandAdapt.ts

17
frontend/src/hook/useAi.ts

@ -10,7 +10,18 @@ export async function askAi(question: any, action: string) {
if (!model) {
return '请先设置模型'
}
let prompt = await assistantStore.getPrompt(action)
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'
}
@ -23,6 +34,8 @@ export async function askAi(question: any, action: string) {
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
}

12
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()

Loading…
Cancel
Save