feat: 暂存添加ai chat and prompt generate

This commit is contained in:
2024-09-26 01:18:04 +08:00
parent 3da62fd254
commit 553e4d62f0
16 changed files with 1265 additions and 60 deletions

View File

@@ -0,0 +1,97 @@
import { create } from 'zustand';
import { query } from '@/modules';
import { message } from 'antd';
type PromptStore = {
showEdit: boolean;
setShowEdit: (showEdit: boolean) => void;
formData: any;
setFormData: (formData: any) => void;
loading: boolean;
setLoading: (loading: boolean) => void;
list: any[];
getList: () => Promise<void>;
updateData: (data: any) => Promise<void>;
deleteData: (id: string) => Promise<void>;
runAi: () => any;
};
export const usePromptStore = create<PromptStore>((set, get) => {
return {
showEdit: false,
setShowEdit: (showEdit) => set({ showEdit }),
formData: {},
setFormData: (formData) => set({ formData }),
loading: false,
setLoading: (loading) => set({ loading }),
list: [],
getList: async () => {
set({ loading: true });
const res = await query.post({
path: 'prompt',
key: 'list',
});
set({ loading: false });
if (res.code === 200) {
set({ list: res.data });
} else {
message.error(res.msg || 'Request failed');
}
},
updateData: async (data) => {
const { getList } = get();
const res = await query.post({
path: 'prompt',
key: 'update',
data,
});
if (res.code === 200) {
message.success('Success');
set({ showEdit: false, formData: [] });
getList();
} else {
message.error(res.msg || 'Request failed');
}
},
deleteData: async (id) => {
const { getList } = get();
const res = await query.post({
path: 'prompt',
key: 'delete',
id,
});
if (res.code === 200) {
getList();
message.success('Success');
} else {
message.error(res.msg || 'Request failed');
}
},
runAi: async () => {
const { formData } = get();
const res = await query.post({
path: 'ai',
key: 'run',
data: {
key: formData.key,
inputs: [
{
key: 'title',
value: '根据描述生成代码',
},
{
key: 'description',
value: '我想获取一个card, 包含标题和内容标题是evision内容是这是一个测试',
},
],
data: {
title: formData.title,
description: formData.description,
},
},
});
if (res.code === 200) {
console.log(res.data);
message.success('Success');
}
},
};
});