feat: 优化界面显示,对deck添加编辑功能
This commit is contained in:
@@ -1,6 +1,19 @@
|
||||
import { query } from '@/modules';
|
||||
import { message } from 'antd';
|
||||
import { create } from 'zustand';
|
||||
type ResData = {
|
||||
created_at: string;
|
||||
done?: boolean;
|
||||
done_reason?: string;
|
||||
eval_count?: number;
|
||||
eval_duration?: number;
|
||||
load_duration?: number;
|
||||
message?: { role?: string; content?: string }[];
|
||||
model?: string;
|
||||
prompt_eval_count?: number;
|
||||
prompt_eval_duration?: number;
|
||||
total_duration?: number;
|
||||
};
|
||||
|
||||
export type AiStore = {
|
||||
open: boolean;
|
||||
@@ -12,9 +25,13 @@ export type AiStore = {
|
||||
sendMsg: (msg: string) => void;
|
||||
formData: any;
|
||||
setFormData: (data: any) => void;
|
||||
data: any;
|
||||
setData: (data: any) => void;
|
||||
runAi: () => any;
|
||||
title: string;
|
||||
setTitle: (title: string) => void;
|
||||
messages: { role: string; content: string }[];
|
||||
setMessage: (message: { role: string; content: string }[]) => void;
|
||||
};
|
||||
|
||||
export const useAiStore = create<AiStore>((set, get) => {
|
||||
@@ -28,31 +45,60 @@ export const useAiStore = create<AiStore>((set, get) => {
|
||||
},
|
||||
formData: {},
|
||||
setFormData: (data) => set({ formData: data }),
|
||||
data: {},
|
||||
setData: (data) => {
|
||||
const { key, presetData = {} } = data;
|
||||
console.log('key', presetData, data);
|
||||
if (!key) {
|
||||
console.error('key is required');
|
||||
return;
|
||||
}
|
||||
const { inputs = [] } = presetData.data || {};
|
||||
const formData = {
|
||||
key,
|
||||
inputs: inputs.map((input) => {
|
||||
return {
|
||||
key: input.key,
|
||||
value: input.value,
|
||||
type: 'string',
|
||||
};
|
||||
}),
|
||||
messages: [],
|
||||
};
|
||||
console.log('formData', formData);
|
||||
set({ key, data, formData });
|
||||
},
|
||||
runAi: async () => {
|
||||
const { formData } = get();
|
||||
const { formData, messages } = get();
|
||||
const loading = message.loading('loading');
|
||||
const res = await query.post({
|
||||
path: 'ai',
|
||||
key: 'run',
|
||||
data: {
|
||||
key: formData.key,
|
||||
inputs: [
|
||||
{
|
||||
key: 'title',
|
||||
value: '根据描述生成代码',
|
||||
},
|
||||
{
|
||||
key: 'description',
|
||||
value: '我想获取一个card, 包含标题和内容,标题是evision,内容是这是一个测试',
|
||||
},
|
||||
// {
|
||||
// key: 'title',
|
||||
// value: '根据描述生成代码',
|
||||
// },
|
||||
// {
|
||||
// key: 'description',
|
||||
// value: '我想获取一个card, 包含标题和内容,标题是evision,内容是这是一个测试',
|
||||
// },
|
||||
...formData.inputs,
|
||||
],
|
||||
},
|
||||
});
|
||||
loading();
|
||||
if (res.code === 200) {
|
||||
console.log(res.data);
|
||||
message.success('Success');
|
||||
set({ messages: [...messages, res.data.message] });
|
||||
}
|
||||
},
|
||||
title: '',
|
||||
setTitle: (title) => set({ title }),
|
||||
messages: [],
|
||||
setMessage: (messages) => set({ messages }),
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user