clear: old code
This commit is contained in:
@@ -1,94 +0,0 @@
|
||||
import { sequelize } from '@/modules/sequelize.ts';
|
||||
import { DataTypes, Model } from 'sequelize';
|
||||
|
||||
export class AiAgent extends Model {
|
||||
declare id: string;
|
||||
declare type: string;
|
||||
declare model: string;
|
||||
declare baseUrl: string;
|
||||
declare apiKey: string;
|
||||
declare temperature: number;
|
||||
declare cache: string;
|
||||
declare cacheName: string;
|
||||
declare status: string;
|
||||
declare data: any;
|
||||
declare description: string;
|
||||
declare key: string;
|
||||
}
|
||||
|
||||
// 获取AIAgent的属性
|
||||
export type AiProperties = {
|
||||
id: string;
|
||||
type: string;
|
||||
model: string;
|
||||
baseUrl: string;
|
||||
apiKey?: string;
|
||||
temperature?: number;
|
||||
cache?: string;
|
||||
cacheName?: string;
|
||||
data?: any;
|
||||
description?: string;
|
||||
};
|
||||
AiAgent.init(
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
primaryKey: true,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
},
|
||||
type: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
},
|
||||
status: {
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: 'open',
|
||||
},
|
||||
model: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
baseUrl: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
apiKey: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
key: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
},
|
||||
temperature: {
|
||||
type: DataTypes.FLOAT,
|
||||
allowNull: true,
|
||||
},
|
||||
cache: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
cacheName: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
data: {
|
||||
type: DataTypes.JSON,
|
||||
allowNull: true,
|
||||
defaultValue: {},
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
tableName: 'ai_agent',
|
||||
paranoid: true,
|
||||
},
|
||||
);
|
||||
AiAgent.sync({ alter: true, logging: false }).catch((e) => {
|
||||
console.error('AiAgent sync error', e);
|
||||
});
|
||||
@@ -1,66 +0,0 @@
|
||||
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;
|
||||
declare chatId: string;
|
||||
declare chatPromptId: string;
|
||||
declare role: 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,
|
||||
},
|
||||
role: {
|
||||
type: DataTypes.STRING, // 角色
|
||||
allowNull: true,
|
||||
defaultValue: 'user',
|
||||
},
|
||||
show: {
|
||||
type: DataTypes.BOOLEAN, // 当创建返回的时候,配置是否显示
|
||||
defaultValue: true,
|
||||
},
|
||||
uid: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize, // 传入 Sequelize 实例
|
||||
modelName: 'chat_history', // 模型名称
|
||||
},
|
||||
);
|
||||
|
||||
// force 只能run一次,否则会删除表
|
||||
ChatHistory.sync({ alter: true, logging: false }).catch((e) => {
|
||||
console.error('History sync error', e);
|
||||
});
|
||||
@@ -1,64 +0,0 @@
|
||||
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;
|
||||
chainPromptId?: 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: ChatPromptData;
|
||||
}
|
||||
|
||||
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,
|
||||
defaultValue: '',
|
||||
},
|
||||
uid: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize, // 传入 Sequelize 实例
|
||||
modelName: 'chat_prompt', // 模型名称
|
||||
paranoid: true,
|
||||
},
|
||||
);
|
||||
|
||||
// force 只能run一次,否则会删除表
|
||||
ChatPrompt.sync({ alter: true, logging: false }).catch((e) => {
|
||||
console.error('Prompt sync error', e);
|
||||
});
|
||||
@@ -1,61 +0,0 @@
|
||||
import { sequelize } from '../modules/sequelize.ts';
|
||||
import { DataTypes, Model } from 'sequelize';
|
||||
|
||||
/**
|
||||
* chat 回话记录
|
||||
* 有一些内容是预置的。
|
||||
*/
|
||||
export class ChatSession extends Model {
|
||||
declare id: string;
|
||||
declare data: string;
|
||||
declare chatPromptId: string;
|
||||
declare type: string;
|
||||
declare key: string;
|
||||
declare title: string;
|
||||
declare uid: string;
|
||||
}
|
||||
|
||||
ChatSession.init(
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
primaryKey: true,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
},
|
||||
data: {
|
||||
type: DataTypes.JSON,
|
||||
allowNull: true,
|
||||
defaultValue: {},
|
||||
},
|
||||
chatPromptId: {
|
||||
type: DataTypes.UUID, // 属于哪一个prompt
|
||||
allowNull: true,
|
||||
},
|
||||
type: {
|
||||
type: DataTypes.STRING, // 属于测试的,还是正式的
|
||||
defaultValue: 'production',
|
||||
},
|
||||
title: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
defaultValue: '',
|
||||
},
|
||||
key: {
|
||||
type: DataTypes.STRING, // 页面属于 /container/edit/list
|
||||
allowNull: true,
|
||||
},
|
||||
uid: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize, // 传入 Sequelize 实例
|
||||
modelName: 'chat_session', // 模型名称
|
||||
},
|
||||
);
|
||||
|
||||
// force 只能run一次,否则会删除表
|
||||
ChatSession.sync({ alter: true, logging: false }).catch((e) => {
|
||||
console.error('Sessuib sync error', e);
|
||||
});
|
||||
@@ -1,121 +0,0 @@
|
||||
import { sequelize } from '../modules/sequelize.ts';
|
||||
import { DataTypes, Model } from 'sequelize';
|
||||
|
||||
export type RouterCode = {
|
||||
id: string;
|
||||
path: string;
|
||||
key: string;
|
||||
active: boolean;
|
||||
project: string;
|
||||
code: string;
|
||||
exec: string;
|
||||
type: RouterCodeType;
|
||||
middleware: string[];
|
||||
next: string;
|
||||
data: any;
|
||||
validator: any;
|
||||
};
|
||||
|
||||
export enum RouterCodeType {
|
||||
route = 'route',
|
||||
middleware = 'middleware',
|
||||
}
|
||||
|
||||
export class RouterCodeModel extends Model {
|
||||
declare id: string;
|
||||
declare path: string;
|
||||
declare key: string;
|
||||
declare active: boolean;
|
||||
declare project: string;
|
||||
declare code: string;
|
||||
declare exec: string;
|
||||
declare type: RouterCodeType;
|
||||
declare middleware: string[];
|
||||
declare next: string; // 如果是中间件,不存在
|
||||
declare data: any; // 内容
|
||||
declare validator: any;
|
||||
}
|
||||
RouterCodeModel.init(
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
primaryKey: true,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
comment: 'code id',
|
||||
},
|
||||
path: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
key: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
active: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false,
|
||||
},
|
||||
project: {
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: 'default',
|
||||
},
|
||||
code: {
|
||||
type: DataTypes.TEXT,
|
||||
defaultValue: '',
|
||||
},
|
||||
exec: {
|
||||
type: DataTypes.TEXT, // 对代码进行编译后的代码
|
||||
defaultValue: '',
|
||||
},
|
||||
type: {
|
||||
type: DataTypes.ENUM(RouterCodeType.route, RouterCodeType.middleware),
|
||||
defaultValue: RouterCodeType.route,
|
||||
},
|
||||
middleware: {
|
||||
type: DataTypes.JSON,
|
||||
defaultValue: [],
|
||||
},
|
||||
next: {
|
||||
type: DataTypes.JSON,
|
||||
defaultValue: {},
|
||||
},
|
||||
data: {
|
||||
type: DataTypes.JSON,
|
||||
defaultValue: {},
|
||||
},
|
||||
validator: {
|
||||
type: DataTypes.JSON,
|
||||
defaultValue: {},
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
tableName: 'cf_router_code', // container flow router code
|
||||
paranoid: true,
|
||||
},
|
||||
);
|
||||
// RouterCodeModel 检测不存在,不存在则创建
|
||||
RouterCodeModel.sync({ alter: true, logging: false })
|
||||
.then((res) => {
|
||||
console.log('RouterCodeModel sync', res);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error('RouterCodeModel sync', e.message);
|
||||
if (!TableIsExist()) {
|
||||
RouterCodeModel.sync({ force: true })
|
||||
.then((res) => {
|
||||
console.log('RouterCodeModel force sync', res);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error('RouterCodeModel force sync error');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export const TableIsExist = async () => {
|
||||
// 判断cf_router_code表是否存在
|
||||
const tableIsExist = await sequelize.getQueryInterface().showAllTables({
|
||||
logging: false,
|
||||
});
|
||||
return tableIsExist.includes('cf_router_code');
|
||||
};
|
||||
@@ -1,83 +0,0 @@
|
||||
import { neode } from '@/modules/neo4j.ts';
|
||||
import { getSession } from '@/modules/neo4j.ts';
|
||||
import Neode from 'neode';
|
||||
|
||||
export const PromptNeo = neode.model('Prompt', {
|
||||
id: {
|
||||
type: 'uuid',
|
||||
primary: true,
|
||||
},
|
||||
title: {
|
||||
type: 'string',
|
||||
},
|
||||
description: 'string',
|
||||
// profile: { type: 'object', optional: true }, // 用于存储 JSON 对象
|
||||
prompt: 'string',
|
||||
// inputVariables: { type: 'array', item },
|
||||
// tags: { type: 'array', items: 'string', optional: true } // 定义字符串数组
|
||||
inputVariables: { type: 'string', default: JSON.stringify([]) },
|
||||
localVariables: { type: 'string', default: JSON.stringify([]) },
|
||||
|
||||
// 定义可单向或双向的关系
|
||||
relatedPrompts: {
|
||||
type: 'relationship',
|
||||
relationship: 'RELATED_TO',
|
||||
target: 'Prompt', // 指向自身
|
||||
direction: 'out', // 默认是单向的
|
||||
properties: {
|
||||
created_at: 'datetime',
|
||||
bidirectional: 'boolean', // 用来标记该关系是否为双向
|
||||
},
|
||||
eager: true, // 自动加载相关的 Prompts
|
||||
},
|
||||
});
|
||||
export async function createRelationship(promptA: Neode.Node<unknown>, promptB: Neode.Node<unknown>, isBidirectional = false) {
|
||||
// 创建单向关系
|
||||
await promptA.relateTo(promptB, 'RELATED_TO', { created_at: new Date(), bidirectional: isBidirectional });
|
||||
|
||||
// 如果是双向关系,创建反向关系
|
||||
if (isBidirectional) {
|
||||
await promptB.relateTo(promptA, 'RELATED_TO', { created_at: new Date(), bidirectional: true });
|
||||
}
|
||||
}
|
||||
export async function createRelationship2(promptId1, promptId2, isBidirectional = false) {
|
||||
const query = `
|
||||
MATCH (p1:Prompt {id: $id1}), (p2:Prompt {id: $id2})
|
||||
CREATE (p1)-[r:RELATED_TO {created_at: $createdAt, bidirectional: $bidirectional}]->(p2)
|
||||
RETURN r
|
||||
`;
|
||||
|
||||
const result = await getSession().run(query, {
|
||||
id1: promptId1,
|
||||
id2: promptId2,
|
||||
createdAt: new Date().toISOString(),
|
||||
bidirectional: isBidirectional,
|
||||
});
|
||||
|
||||
return result.records[0].get('r');
|
||||
}
|
||||
export async function createPrompt(promptData) {
|
||||
const session = getSession();
|
||||
const query = `
|
||||
CREATE (p:Prompt {
|
||||
id: $id,
|
||||
title: $title,
|
||||
description: $description,
|
||||
prompt: $prompt,
|
||||
inputVariables: $inputVariables,
|
||||
localVariables: $localVariables
|
||||
})
|
||||
RETURN p
|
||||
`;
|
||||
|
||||
const result = await session.run(query, {
|
||||
id: promptData.id,
|
||||
title: promptData.title,
|
||||
description: promptData.description,
|
||||
prompt: promptData.prompt,
|
||||
inputVariables: JSON.stringify(promptData.inputVariables || []),
|
||||
localVariables: JSON.stringify(promptData.localVariables || []),
|
||||
});
|
||||
|
||||
return result.records[0].get('p');
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
import { sequelize } from '../modules/sequelize.ts';
|
||||
import { DataTypes, Model } from 'sequelize';
|
||||
import { Variable } from '@kevisual/ai-graph';
|
||||
|
||||
/**
|
||||
* 预设数据,定义了请求的内容和验证器
|
||||
*/
|
||||
export type PresetData = {
|
||||
// 参数
|
||||
validator: {
|
||||
[key: string]: any; // 请求的内容的验证器
|
||||
};
|
||||
data: {
|
||||
prompt?: string; // 提前预设值
|
||||
inputs: Variable & { operate?: string }[]; // 请求内容的变量和内容
|
||||
};
|
||||
};
|
||||
export class Prompt extends Model {
|
||||
declare id: string;
|
||||
declare title: string;
|
||||
declare description: string;
|
||||
declare presetData: PresetData;
|
||||
}
|
||||
|
||||
Prompt.init(
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
primaryKey: true,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
},
|
||||
title: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
},
|
||||
presetData: {
|
||||
type: DataTypes.JSON,
|
||||
},
|
||||
key: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
},
|
||||
// inputVariables: {
|
||||
// type: DataTypes.JSON,
|
||||
// defaultValue: [],
|
||||
// },
|
||||
// localVariables: {
|
||||
// type: DataTypes.JSON,
|
||||
// defaultValue: [],
|
||||
// },
|
||||
},
|
||||
{
|
||||
sequelize, // 传入 Sequelize 实例
|
||||
modelName: 'prompt', // 模型名称
|
||||
paranoid: true,
|
||||
},
|
||||
);
|
||||
|
||||
Prompt.sync({ alter: true, force: false, logging: false }).catch((e) => {
|
||||
console.error('Prompt sync error', e);
|
||||
});
|
||||
Reference in New Issue
Block a user