This commit is contained in:
2024-09-30 01:39:07 +08:00
parent 962d89ff29
commit e05c042827
8 changed files with 152 additions and 9 deletions

View File

@@ -0,0 +1,58 @@
import { chat } from '@/modules/ollama.ts';
import { sequelize } from '../modules/sequelize.ts';
import { DataTypes, Model } from 'sequelize';
/**
* chat 回话记录
* 有一些内容是预置的。
*/
export class ChatHistory extends Model {
declare id: string;
declare data: string;
declare root: boolean;
declare show: boolean;
declare uid: string;
}
ChatHistory.init(
{
id: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: DataTypes.UUIDV4,
},
data: {
type: DataTypes.JSON,
allowNull: true,
},
chatId: {
type: DataTypes.UUID, // 历史属于哪一条会话
allowNull: true,
},
chatPromptId: {
type: DataTypes.UUID, // 属于哪一个prompt
allowNull: true,
},
root: {
type: DataTypes.BOOLEAN, // 是否是根节点
defaultValue: false,
},
show: {
type: DataTypes.BOOLEAN, // 当创建返回的时候,配置是否显示
defaultValue: true,
},
uid: {
type: DataTypes.STRING,
allowNull: true,
},
},
{
sequelize, // 传入 Sequelize 实例
modelName: 'chat_history', // 模型名称
},
);
// force 只能run一次否则会删除表
ChatHistory.sync({ alter: true, force: true, logging: false }).catch((e) => {
console.error('History sync error', e);
});

61
src/models/chat-prompt.ts Normal file
View File

@@ -0,0 +1,61 @@
import { sequelize } from '../modules/sequelize.ts';
import { DataTypes, Model } from 'sequelize';
import { Variable } from '@kevisual/ai-graph';
export type ChatPromptData = {
// 使用那个agent, 必须要有
aiAgentId: string;
// 使用那个初始化的prompt如果不存在则纯粹的白对话。
promptId?: string;
};
/**
* chat绑定就的agent和prompt
* 有一些内容是预置的。
*/
export class ChatPrompt extends Model {
declare id: string;
declare title: string;
declare description: string;
declare uid: string;
declare key: string;
declare data: string;
}
ChatPrompt.init(
{
id: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: DataTypes.UUIDV4,
},
title: {
type: DataTypes.STRING,
allowNull: false,
},
description: {
type: DataTypes.TEXT,
allowNull: true,
},
data: {
type: DataTypes.JSON,
allowNull: true,
},
key: {
type: DataTypes.STRING, // 页面属于 /container/edit/list
allowNull: false,
},
uid: {
type: DataTypes.STRING,
allowNull: true,
},
},
{
sequelize, // 传入 Sequelize 实例
modelName: 'chat_prompt', // 模型名称
},
);
// force 只能run一次否则会删除表
ChatPrompt.sync({ alter: true, force: true, logging: false }).catch((e) => {
console.error('Prompt sync error', e);
});