feat: add neo4j

This commit is contained in:
2024-09-25 14:02:45 +08:00
parent 4cbc72def7
commit 25c055b490
16 changed files with 554 additions and 113 deletions

View File

@@ -26,10 +26,6 @@ export class ContainerModel extends Model {
declare data: ContainerData;
declare publish: ContainerPublish;
declare uid: string;
// timestamps
public readonly createdAt!: Date;
public readonly updatedAt!: Date;
}
ContainerModel.init(
{

View File

@@ -3,3 +3,5 @@ import './container/index.ts';
import './page/index.ts';
import './resource/index.ts';
import './prompt-graph/index.ts';

View File

@@ -0,0 +1 @@
import './list.ts'

View File

@@ -0,0 +1,76 @@
import { PromptNeo } from '@/models/prompt.ts';
import { app } from '@/app.ts';
import { v4 } from 'uuid';
app
.route('prompt', 'list')
.define(async (ctx) => {
const prompts = await PromptNeo.all();
const json = await prompts.toJson();
console.log('json', json);
ctx.body = json;
})
.addTo(app);
app
.route('prompt', 'update')
.define(async (ctx) => {
const { id, title, description, prompt, inputVariables, localVariables } = ctx.query;
const promptNode = await PromptNeo.first('id', id);
if (!promptNode) {
const promptData = {
id: v4(),
title,
description,
prompt,
inputVariables: JSON.stringify(inputVariables),
localVariables: JSON.stringify(localVariables),
};
const _prompt = await PromptNeo.create(promptData);
ctx.body = await _prompt.toJson();
return;
}
await promptNode.update({ title, description, prompt, inputVariables, localVariables });
ctx.body = await promptNode.toJson();
})
.addTo(app);
app
.route('prompt', 'delete')
.define(async (ctx) => {
const { id, title } = ctx.query;
const promptNode = await PromptNeo.first('id', id);
if (!promptNode) {
ctx.body = 'prompt not found';
return;
}
await promptNode.delete();
ctx.body = 'delete success';
})
.addTo(app);
app
.route('prompt', 'deleteAll')
.define(async (ctx) => {
const prompts = await PromptNeo.all();
for (const prompt of prompts) {
await prompt.delete();
}
ctx.body = 'delete all success';
})
.addTo(app);
app
.route('prompt', 'createDemo')
.define(async (ctx) => {
const promptData = {
id: v4(),
title: 'test',
description: '这是测试保存prompt的数据',
prompt: '这是测试保存prompt的数据',
inputVariables: JSON.stringify([{ key: 'test', value: 'test' }]),
localVariables: JSON.stringify([{ key: 'test', value: 'test' }]),
};
const prompt = await PromptNeo.create(promptData);
ctx.body = await prompt.toJson();
})
.addTo(app);