59 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { query } from '@/modules';
import { message } from 'antd';
import { create } from 'zustand';
export type AiStore = {
open: boolean;
setOpen: (open: boolean) => void;
type?: string;
key: string;
setKey: (key: string) => void;
setType?: (type: string) => void;
sendMsg: (msg: string) => void;
formData: any;
setFormData: (data: any) => void;
runAi: () => any;
title: string;
setTitle: (title: string) => void;
};
export const useAiStore = create<AiStore>((set, get) => {
return {
open: false,
setOpen: (open) => set({ open }),
key: '',
setKey: (key) => set({ key }),
sendMsg: (msg) => {
console.log(msg);
},
formData: {},
setFormData: (data) => set({ formData: data }),
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内容是这是一个测试',
},
],
},
});
if (res.code === 200) {
console.log(res.data);
message.success('Success');
}
},
title: '',
setTitle: (title) => set({ title }),
};
});