Skip to content

Commit

Permalink
fix chat agent form
Browse files Browse the repository at this point in the history
  • Loading branch information
an-lee committed Aug 15, 2024
1 parent 965caa8 commit 75faa44
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
38 changes: 28 additions & 10 deletions enjoy/src/renderer/components/chats/chat-agent-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const ChatAgentForm = (props: {
language: string;
introduction: string;
config: any;
}) => void;
}) => Promise<any>;
onDestroy: () => void;
}) => {
const { agent, onSave, onDestroy } = props;
Expand All @@ -58,9 +58,9 @@ export const ChatAgentForm = (props: {
const [ttsProviders, setTtsProviders] = useState<any>(TTS_PROVIDERS);

const agentFormSchema = z.object({
name: z.string(),
introduction: z.string(),
language: z.string(),
name: z.string().min(1),
introduction: z.string().min(1),
language: z.string().min(1),
engine: z.enum(["enjoyai", "openai", "ollama"]),
model: z.string(),
prompt: z.string(),
Expand Down Expand Up @@ -95,6 +95,9 @@ export const ChatAgentForm = (props: {
language,
introduction,
config,
}).then(() => {
if (agent?.id) return;
form.reset();
});
});

Expand Down Expand Up @@ -172,7 +175,7 @@ export const ChatAgentForm = (props: {
render={({ field }) => (
<FormItem>
<FormLabel>{t("models.chatAgent.name")}</FormLabel>
<Input {...field} />
<Input required {...field} />
<FormMessage />
</FormItem>
)}
Expand All @@ -184,7 +187,7 @@ export const ChatAgentForm = (props: {
render={({ field }) => (
<FormItem>
<FormLabel>{t("models.chatAgent.introduction")}</FormLabel>
<Textarea className="max-h-36" {...field} />
<Textarea required className="max-h-36" {...field} />
<FormMessage />
</FormItem>
)}
Expand All @@ -196,7 +199,7 @@ export const ChatAgentForm = (props: {
render={({ field }) => (
<FormItem>
<FormLabel>{t("models.chatAgent.prompt")}</FormLabel>
<Textarea className="max-h-48" {...field} />
<Textarea required className="max-h-48" {...field} />
<FormMessage />
</FormItem>
)}
Expand All @@ -208,7 +211,11 @@ export const ChatAgentForm = (props: {
render={({ field }) => (
<FormItem>
<FormLabel>{t("models.chatAgent.language")}</FormLabel>
<Select value={field.value} onValueChange={field.onChange}>
<Select
required
value={field.value}
onValueChange={field.onChange}
>
<SelectTrigger className="text-xs">
<SelectValue>
{
Expand Down Expand Up @@ -240,7 +247,11 @@ export const ChatAgentForm = (props: {
render={({ field }) => (
<FormItem>
<FormLabel>{t("models.chatAgent.engine")}</FormLabel>
<Select onValueChange={field.onChange} value={field.value}>
<Select
required
onValueChange={field.onChange}
value={field.value}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder={t("selectAiEngine")} />
Expand Down Expand Up @@ -268,7 +279,11 @@ export const ChatAgentForm = (props: {
render={({ field }) => (
<FormItem>
<FormLabel>{t("models.chatAgent.model")}</FormLabel>
<Select onValueChange={field.onChange} value={field.value}>
<Select
required
onValueChange={field.onChange}
value={field.value}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder={t("selectAiModel")} />
Expand Down Expand Up @@ -321,6 +336,7 @@ export const ChatAgentForm = (props: {
<FormItem>
<FormLabel>{t("models.chatAgent.ttsEngine")}</FormLabel>
<Select
required
onValueChange={field.onChange}
defaultValue={field.value}
value={field.value}
Expand Down Expand Up @@ -349,6 +365,7 @@ export const ChatAgentForm = (props: {
<FormItem>
<FormLabel>{t("models.chatAgent.ttsModel")}</FormLabel>
<Select
required
onValueChange={field.onChange}
defaultValue={field.value}
value={field.value}
Expand Down Expand Up @@ -379,6 +396,7 @@ export const ChatAgentForm = (props: {
<FormItem>
<FormLabel>{t("models.chatAgent.ttsVoice")}</FormLabel>
<Select
required
onValueChange={field.onChange}
defaultValue={field.value}
value={field.value}
Expand Down
4 changes: 2 additions & 2 deletions enjoy/src/renderer/components/chats/chat-agents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ export const ChatAgents = () => {
agent={selected}
onSave={(data) => {
if (selected) {
updateChatAgent(selected.id, data);
return updateChatAgent(selected.id, data);
} else {
createChatAgent(data).then(() => setSelected(null));
return createChatAgent(data).then(() => setSelected(null));
}
}}
onDestroy={() => {
Expand Down

0 comments on commit 75faa44

Please sign in to comment.