feat: add flow edit
This commit is contained in:
@@ -3,15 +3,20 @@ import { Prompt } from '@/models/prompt.ts';
|
||||
import { chat } from '@/modules/ollama.ts';
|
||||
import { CustomError } from '@abearxiong/router';
|
||||
import { PromptTemplate } from '@kevisual/ai-graph';
|
||||
|
||||
import { v4 } from 'uuid';
|
||||
app
|
||||
.route('ai', 'run', { nextRoute: { id: 'runOllama' } })
|
||||
.define({
|
||||
validator: {
|
||||
key: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
message: 'Prompt key is required',
|
||||
data: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
key: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
message: 'Prompt key is required',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -23,6 +28,7 @@ app
|
||||
throw new CustomError('Prompt key is required');
|
||||
}
|
||||
const prompt = await Prompt.findOne({ where: { key } });
|
||||
console.log('prompt', 'key', key, prompt);
|
||||
if (!prompt) {
|
||||
throw new CustomError('Prompt not found');
|
||||
}
|
||||
@@ -54,16 +60,16 @@ app
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const prompt = ctx.state.prompt;
|
||||
const uuid = v4();
|
||||
if (!prompt) {
|
||||
throw new CustomError('Prompt not found');
|
||||
throw new CustomError('Prompt Template not found');
|
||||
}
|
||||
console.log('prompt', typeof prompt, prompt);
|
||||
const res = await chat([
|
||||
{
|
||||
role: 'user',
|
||||
content: prompt,
|
||||
},
|
||||
]);
|
||||
ctx.body = res;
|
||||
ctx.body = { id: uuid, ...res };
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
Reference in New Issue
Block a user