Browse Source

change db

master
godo 6 months ago
parent
commit
e3b2b67812
  1. 4
      frontend/src/components/window/IframeFile.vue
  2. 81
      frontend/src/hook/useAi.ts
  3. 13
      frontend/src/stores/db.ts

4
frontend/src/components/window/IframeFile.vue

@ -199,9 +199,9 @@ const eventHandler = async (e: MessageEvent) => {
if(eventData.category){ if(eventData.category){
postData.category = eventData.category postData.category = eventData.category
} }
//console.log(postData,eventData.action)
// AI // AI
const res = await askAi(postData, eventData.action); const res:any = await askAi(postData, eventData.action);
storeRef.value?.contentWindow?.postMessage( storeRef.value?.contentWindow?.postMessage(
{ {
type: 'aiReciver', type: 'aiReciver',

81
frontend/src/hook/useAi.ts

@ -2,44 +2,49 @@ import { getSystemConfig, fetchPost } from "@/system/config";
import { useAssistantStore } from '@/stores/assistant'; import { useAssistantStore } from '@/stores/assistant';
import { useModelStore } from "@/stores/model"; import { useModelStore } from "@/stores/model";
export async function askAi(question: any, action: string) { export async function askAi(question: any, action: string) {
const assistantStore = useAssistantStore(); try {
const modelStore = useModelStore(); const assistantStore = useAssistantStore();
const config = getSystemConfig(); const modelStore = useModelStore();
const model = await modelStore.getModel('chat') const config = getSystemConfig();
if (!model) { const model = await modelStore.getModel('chat')
return '请先设置模型' 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
} }

13
frontend/src/stores/db.ts

@ -1,6 +1,6 @@
import Dexie from 'dexie'; 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'); export const dbInit: any = new Dexie('GodoOSDatabase');
dbInit.version(1).stores({ dbInit.version(1).stores({
@ -110,9 +110,14 @@ export const db = {
}, },
async get(tableName: ChatTable, whereObj: any) { async get(tableName: ChatTable, whereObj: any) {
//console.log(whereObj) //console.log(whereObj)
const data = await dbInit[tableName].where(whereObj).first() try {
//console.log(data) const data = await dbInit[tableName].where(whereObj).first()
return data ? data : false //console.log(data)
return data ? data : false
} catch (error) {
return false
}
}, },
async rows(tableName: ChatTable, whereObj: any) { async rows(tableName: ChatTable, whereObj: any) {
return dbInit[tableName].where(whereObj).toArray() return dbInit[tableName].where(whereObj).toArray()

Loading…
Cancel
Save