diff --git a/frontend/src/components/window/IframeFile.vue b/frontend/src/components/window/IframeFile.vue index 882de40..463254a 100644 --- a/frontend/src/components/window/IframeFile.vue +++ b/frontend/src/components/window/IframeFile.vue @@ -199,9 +199,9 @@ const eventHandler = async (e: MessageEvent) => { if(eventData.category){ postData.category = eventData.category } - + //console.log(postData,eventData.action) // 模拟AI返回数据 - const res = await askAi(postData, eventData.action); + const res:any = await askAi(postData, eventData.action); storeRef.value?.contentWindow?.postMessage( { type: 'aiReciver', diff --git a/frontend/src/hook/useAi.ts b/frontend/src/hook/useAi.ts index 664d769..98f9ff6 100644 --- a/frontend/src/hook/useAi.ts +++ b/frontend/src/hook/useAi.ts @@ -2,44 +2,49 @@ import { getSystemConfig, fetchPost } from "@/system/config"; import { useAssistantStore } from '@/stores/assistant'; import { useModelStore } from "@/stores/model"; export async function askAi(question: any, action: string) { - const assistantStore = useAssistantStore(); - const modelStore = useModelStore(); - const config = getSystemConfig(); - const model = await modelStore.getModel('chat') - if (!model) { - return '请先设置模型' + try { + const assistantStore = useAssistantStore(); + const modelStore = useModelStore(); + const config = getSystemConfig(); + const model = await modelStore.getModel('chat') + 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) + } + const apiUrl = config.aiUrl + '/ai/chat' + const postMsg: any = { + messages: [ + { + //role: "assistant", + role: "user", + content: prompt + }, + ], + model: model.model, + stream: false, + options: modelStore.chatConfig.creation, + }; + const complain = await fetchPost(apiUrl, JSON.stringify(postMsg)) + if (!complain.ok) { + return '请求失败' + } + const data = await complain.json() + return data.choices[0].message.content + } catch (error) { + return '请求失败'+error } - 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) - } - const apiUrl = config.aiUrl + '/ai/chat' - const postMsg: any = { - messages: [ - { - //role: "assistant", - role: "user", - content: prompt - }, - ], - model: model.model, - stream: false, - options: modelStore.chatConfig.creation, - }; - const complain = await fetchPost(apiUrl, JSON.stringify(postMsg)) - if (!complain.ok) { - return '请求失败' - } - const data = await complain.json() - return data.choices[0].message.content + } \ No newline at end of file diff --git a/frontend/src/stores/db.ts b/frontend/src/stores/db.ts index a3b684f..408f1dc 100644 --- a/frontend/src/stores/db.ts +++ b/frontend/src/stores/db.ts @@ -1,6 +1,6 @@ import Dexie from 'dexie'; -export type ChatTable = 'prompts' | 'modelslabel' | 'modelslist' | 'chatuser' | 'chatmsg' |'systemChatRecord'| 'workbenchChatRecord' | 'workbenchChatUser' | 'workbenchSessionList' | 'groupSessionList' | 'workbenchGroupChatRecord' | 'workbenchGroupUserList' | 'workbenchGroupInviteMessage'; +export type ChatTable = 'prompts' | 'modelslabel' | 'modelslist' | 'chatuser' | 'chatmsg' | 'systemChatRecord' | 'workbenchChatRecord' | 'workbenchChatUser' | 'workbenchSessionList' | 'groupSessionList' | 'workbenchGroupChatRecord' | 'workbenchGroupUserList' | 'workbenchGroupInviteMessage'; export const dbInit: any = new Dexie('GodoOSDatabase'); dbInit.version(1).stores({ @@ -110,9 +110,14 @@ export const db = { }, async get(tableName: ChatTable, whereObj: any) { //console.log(whereObj) - const data = await dbInit[tableName].where(whereObj).first() - //console.log(data) - return data ? data : false + try { + const data = await dbInit[tableName].where(whereObj).first() + //console.log(data) + return data ? data : false + } catch (error) { + return false + } + }, async rows(tableName: ChatTable, whereObj: any) { return dbInit[tableName].where(whereObj).toArray()