feat: finalize UI form new right panel thread

This commit is contained in:
Faisal Amir 2024-01-02 01:24:16 +07:00
parent 590fa67244
commit 347e47f1ce
11 changed files with 418 additions and 229 deletions

View File

@ -41,7 +41,7 @@ export default function CardSidebar({
return ( return (
<div <div
className={twMerge( className={twMerge(
'flex w-full flex-col border-t border-border bg-zinc-100 dark:bg-zinc-600/10', 'flex w-full flex-col border-t border-border bg-zinc-100 dark:bg-zinc-900',
asChild ? 'rounded-lg border' : 'border-t' asChild ? 'rounded-lg border' : 'border-t'
)} )}
> >
@ -56,7 +56,7 @@ export default function CardSidebar({
{!asChild && ( {!asChild && (
<div <div
ref={setToggle} ref={setToggle}
className="cursor-pointer rounded-lg bg-zinc-100 p-2 pr-0 dark:bg-zinc-600/10" className="cursor-pointer rounded-lg bg-zinc-100 p-2 pr-0 dark:bg-zinc-900"
onClick={() => setMore(!more)} onClick={() => setMore(!more)}
> >
<MoreVerticalIcon className="h-5 w-5" /> <MoreVerticalIcon className="h-5 w-5" />
@ -64,7 +64,7 @@ export default function CardSidebar({
)} )}
<button <button
onClick={() => setShow(!show)} onClick={() => setShow(!show)}
className="flex w-full flex-1 items-center space-x-2 rounded-lg bg-zinc-100 px-3 py-2 dark:bg-zinc-600/10" className="flex w-full flex-1 items-center space-x-2 rounded-lg bg-zinc-100 px-3 py-2 dark:bg-zinc-900"
> >
<ChevronDownIcon <ChevronDownIcon
className={twMerge( className={twMerge(

View File

@ -9,38 +9,49 @@ import {
TooltipTrigger, TooltipTrigger,
} from '@janhq/uikit' } from '@janhq/uikit'
import { useAtomValue } from 'jotai' // import { useAtomValue } from 'jotai'
import { InfoIcon } from 'lucide-react' import { InfoIcon } from 'lucide-react'
import useUpdateModelParameters from '@/hooks/useUpdateModelParameters' // import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'
import { getActiveThreadIdAtom } from '@/helpers/atoms/Thread.atom' // import { getActiveThreadIdAtom } from '@/helpers/atoms/Thread.atom'
type Props = { type Props = {
name: string name: string
title: string title: string
description: string description: string
checked: boolean value: boolean
onBlur: () => void
onChange: () => void
} }
const Checkbox: React.FC<Props> = ({ name, title, checked, description }) => { const Checkbox: React.FC<Props> = ({
const { updateModelParameter } = useUpdateModelParameters() name,
const threadId = useAtomValue(getActiveThreadIdAtom) value,
title,
description,
onChange,
onBlur,
}) => {
// const { updateModelParameter } = useUpdateModelParameters()
// const threadId = useAtomValue(getActiveThreadIdAtom)
const onCheckedChange = (checked: boolean) => { // const onCheckedChange = (checked: boolean) => {
if (!threadId) return // if (!threadId) return
updateModelParameter(threadId, name, checked) // updateModelParameter(threadId, name, checked)
} // }
return ( return (
<div className="flex justify-between"> <div className="flex justify-between">
<div className="mb-1 flex items-center gap-x-2"> <div className="mb-1 flex items-center gap-x-2">
<p className="text-sm font-semibold text-gray-600">{title}</p> <p className="text-sm font-semibold text-zinc-500 dark:text-gray-300">
{title}
</p>
<Tooltip> <Tooltip>
<TooltipTrigger asChild> <TooltipTrigger asChild>
<InfoIcon size={16} className="flex-shrink-0" /> <InfoIcon size={16} className="flex-shrink-0 dark:text-gray-500" />
</TooltipTrigger> </TooltipTrigger>
<TooltipPortal> <TooltipPortal>
<TooltipContent side="top" className="max-w-[240px]"> <TooltipContent side="top" className="max-w-[240px]">
@ -51,7 +62,13 @@ const Checkbox: React.FC<Props> = ({ name, title, checked, description }) => {
</Tooltip> </Tooltip>
</div> </div>
<Switch checked={checked} onCheckedChange={onCheckedChange} /> <Switch
name={name}
defaultChecked={value}
onCheckedChange={onChange}
onChange={onChange}
onBlur={onBlur}
/>
</div> </div>
) )
} }

View File

@ -7,13 +7,13 @@ import {
TooltipTrigger, TooltipTrigger,
} from '@janhq/uikit' } from '@janhq/uikit'
import { useAtomValue } from 'jotai' // import { useAtomValue } from 'jotai'
import { InfoIcon } from 'lucide-react' import { InfoIcon } from 'lucide-react'
import useUpdateModelParameters from '@/hooks/useUpdateModelParameters' // import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'
import { getActiveThreadIdAtom } from '@/helpers/atoms/Thread.atom' // import { getActiveThreadIdAtom } from '@/helpers/atoms/Thread.atom'
type Props = { type Props = {
title: string title: string
@ -21,6 +21,8 @@ type Props = {
description: string description: string
placeholder: string placeholder: string
value: string value: string
onBlur: () => void
onChange: () => void
} }
const ModelConfigInput: React.FC<Props> = ({ const ModelConfigInput: React.FC<Props> = ({
@ -29,23 +31,27 @@ const ModelConfigInput: React.FC<Props> = ({
value, value,
description, description,
placeholder, placeholder,
onChange,
onBlur,
}) => { }) => {
const { updateModelParameter } = useUpdateModelParameters() // const { updateModelParameter } = useUpdateModelParameters()
const threadId = useAtomValue(getActiveThreadIdAtom) // const threadId = useAtomValue(getActiveThreadIdAtom)
const onValueChanged = (e: React.ChangeEvent<HTMLTextAreaElement>) => { // const onValueChanged = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
if (!threadId) return // if (!threadId) return
updateModelParameter(threadId, name, e.target.value) // updateModelParameter(threadId, name, e.target.value)
} // }
return ( return (
<div className="flex flex-col"> <div className="flex flex-col">
<div className="mb-4 flex items-center gap-x-2"> <div className="mb-4 flex items-center gap-x-2">
<p className="text-sm font-semibold text-gray-600">{title}</p> <p className="text-sm font-semibold text-zinc-500 dark:text-gray-300">
{title}
</p>
<Tooltip> <Tooltip>
<TooltipTrigger asChild> <TooltipTrigger asChild>
<InfoIcon size={16} className="flex-shrink-0" /> <InfoIcon size={16} className="flex-shrink-0 dark:text-gray-500" />
</TooltipTrigger> </TooltipTrigger>
<TooltipPortal> <TooltipPortal>
<TooltipContent side="top" className="max-w-[240px]"> <TooltipContent side="top" className="max-w-[240px]">
@ -56,9 +62,10 @@ const ModelConfigInput: React.FC<Props> = ({
</Tooltip> </Tooltip>
</div> </div>
<Textarea <Textarea
name={name}
placeholder={placeholder} placeholder={placeholder}
onChange={onValueChanged} onChange={onChange}
value={value} onBlur={onBlur}
/> />
</div> </div>
) )

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import React from 'react' import React from 'react'
import { Slider, Input, TooltipPortal } from '@janhq/uikit' import { Slider, Input, TooltipPortal } from '@janhq/uikit'
@ -7,12 +8,12 @@ import {
TooltipTrigger, TooltipTrigger,
TooltipArrow, TooltipArrow,
} from '@janhq/uikit' } from '@janhq/uikit'
import { useAtomValue } from 'jotai' // import { useAtomValue } from 'jotai'
import { InfoIcon } from 'lucide-react' import { InfoIcon } from 'lucide-react'
import useUpdateModelParameters from '@/hooks/useUpdateModelParameters' // import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'
import { getActiveThreadIdAtom } from '@/helpers/atoms/Thread.atom' // import { getActiveThreadIdAtom } from '@/helpers/atoms/Thread.atom'
type Props = { type Props = {
name: string name: string
@ -21,7 +22,9 @@ type Props = {
min: number min: number
max: number max: number
step: number step: number
value: number value: number[]
onChange: (e: any) => void
onBlur: (e: any) => void
} }
const SliderRightPanel: React.FC<Props> = ({ const SliderRightPanel: React.FC<Props> = ({
@ -30,24 +33,28 @@ const SliderRightPanel: React.FC<Props> = ({
min, min,
max, max,
description, description,
onChange,
onBlur,
step, step,
value, value,
}) => { }) => {
const { updateModelParameter } = useUpdateModelParameters() // const { updateModelParameter } = useUpdateModelParameters()
const threadId = useAtomValue(getActiveThreadIdAtom) // const threadId = useAtomValue(getActiveThreadIdAtom)
const onValueChanged = (e: number[]) => { // const onValueChanged = (e: number[]) => {
if (!threadId) return // if (!threadId) return
updateModelParameter(threadId, name, e[0]) // updateModelParameter(threadId, name, e[0])
} // }
return ( return (
<div className="flex flex-col"> <div className="flex flex-col">
<div className="mb-4 flex items-center gap-x-2"> <div className="mb-4 flex items-center gap-x-2">
<p className="text-sm font-semibold text-gray-600">{title}</p> <p className="text-sm font-semibold text-zinc-500 dark:text-gray-300">
{title}
</p>
<Tooltip> <Tooltip>
<TooltipTrigger asChild> <TooltipTrigger asChild>
<InfoIcon size={16} className="flex-shrink-0" /> <InfoIcon size={16} className="flex-shrink-0 dark:text-gray-500" />
</TooltipTrigger> </TooltipTrigger>
<TooltipPortal> <TooltipPortal>
<TooltipContent side="top" className="max-w-[240px]"> <TooltipContent side="top" className="max-w-[240px]">
@ -60,8 +67,11 @@ const SliderRightPanel: React.FC<Props> = ({
<div className="flex items-center gap-x-4"> <div className="flex items-center gap-x-4">
<div className="relative w-full"> <div className="relative w-full">
<Slider <Slider
value={[value]} defaultValue={value}
onValueChange={onValueChanged} onValueChange={(e) => onChange(e[0])}
onChange={(e) => onChange(e)}
onBlur={onBlur}
name={name}
min={min} min={min}
max={max} max={max}
step={step} step={step}
@ -78,8 +88,10 @@ const SliderRightPanel: React.FC<Props> = ({
className="-mt-4 h-8 w-16" className="-mt-4 h-8 w-16"
min={min} min={min}
max={max} max={max}
value={String(value)} name={name}
onChange={(e) => onValueChanged([Number(e.target.value)])} value={value[0] || String(value[0])}
onChange={(e) => onChange([e.target.value])}
onBlur={onBlur}
/> />
</div> </div>
</div> </div>

View File

@ -25,11 +25,7 @@ export default function useUpdateModelParameters() {
const activeThreadState = useAtomValue(activeThreadStateAtom) const activeThreadState = useAtomValue(activeThreadStateAtom)
const activeModelParams = useAtomValue(getActiveThreadModelParamsAtom) const activeModelParams = useAtomValue(getActiveThreadModelParamsAtom)
const updateModelParameter = async ( const updateModelParameter = async (threadId: string, values: any) => {
threadId: string,
name: string,
value: number | boolean | string
) => {
const thread = threads.find((thread) => thread.id === threadId) const thread = threads.find((thread) => thread.id === threadId)
if (!thread) { if (!thread) {
console.error(`Thread ${threadId} not found`) console.error(`Thread ${threadId} not found`)
@ -40,9 +36,10 @@ export default function useUpdateModelParameters() {
console.error('No active thread') console.error('No active thread')
return return
} }
const updatedModelParams: ModelParams = { const updatedModelParams: ModelParams = {
...activeModelParams, ...activeModelParams,
[name]: value, ...values,
} }
// update the state // update the state

View File

@ -118,7 +118,6 @@ const ChatBody: React.FC = () => {
{messages.map((message, index) => ( {messages.map((message, index) => (
<div key={message.id}> <div key={message.id}>
<ChatItem {...message} key={message.id} /> <ChatItem {...message} key={message.id} />
{message.status === MessageStatus.Error && {message.status === MessageStatus.Error &&
index === messages.length - 1 && ( index === messages.length - 1 && (
<div <div

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { useAtomValue } from 'jotai' import { useAtomValue } from 'jotai'
import { selectedModelAtom } from '@/containers/DropdownListSidebar' import { selectedModelAtom } from '@/containers/DropdownListSidebar'
@ -9,7 +10,7 @@ import settingComponentBuilder from '../ModelSetting/settingComponentBuilder'
import { getActiveThreadModelParamsAtom } from '@/helpers/atoms/Thread.atom' import { getActiveThreadModelParamsAtom } from '@/helpers/atoms/Thread.atom'
const EngineSetting: React.FC = () => { const EngineSetting = (props: { form: any }) => {
const activeModelParams = useAtomValue(getActiveThreadModelParamsAtom) const activeModelParams = useAtomValue(getActiveThreadModelParamsAtom)
const selectedModel = useAtomValue(selectedModelAtom) const selectedModel = useAtomValue(selectedModelAtom)
@ -22,9 +23,9 @@ const EngineSetting: React.FC = () => {
componentData.sort((a, b) => a.title.localeCompare(b.title)) componentData.sort((a, b) => a.title.localeCompare(b.title))
return ( return (
<form className="flex flex-col"> <div className="flex flex-col">
{settingComponentBuilder(componentData)} {settingComponentBuilder(componentData, props.form)}
</form> </div>
) )
} }

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import React from 'react' import React from 'react'
import { useAtomValue } from 'jotai' import { useAtomValue } from 'jotai'
@ -11,7 +12,7 @@ import settingComponentBuilder from './settingComponentBuilder'
import { getActiveThreadModelParamsAtom } from '@/helpers/atoms/Thread.atom' import { getActiveThreadModelParamsAtom } from '@/helpers/atoms/Thread.atom'
const ModelSetting: React.FC = () => { const ModelSetting = (props: { form: any }) => {
const activeModelParams = useAtomValue(getActiveThreadModelParamsAtom) const activeModelParams = useAtomValue(getActiveThreadModelParamsAtom)
const selectedModel = useAtomValue(selectedModelAtom) const selectedModel = useAtomValue(selectedModelAtom)
@ -24,9 +25,9 @@ const ModelSetting: React.FC = () => {
componentData.sort((a, b) => a.title.localeCompare(b.title)) componentData.sort((a, b) => a.title.localeCompare(b.title))
return ( return (
<form className="flex flex-col"> <div className="flex flex-col">
{settingComponentBuilder(componentData)} {settingComponentBuilder(componentData, props.form)}
</form> </div>
) )
} }

View File

@ -1,4 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable no-case-declarations */ /* eslint-disable no-case-declarations */
import { FormControl, FormField, FormItem, FormMessage } from '@janhq/uikit'
import Checkbox from '@/containers/Checkbox' import Checkbox from '@/containers/Checkbox'
import ModelConfigInput from '@/containers/ModelConfigInput' import ModelConfigInput from '@/containers/ModelConfigInput'
import Slider from '@/containers/Slider' import Slider from '@/containers/Slider'
@ -29,51 +32,99 @@ type CheckboxData = {
checked: boolean checked: boolean
} }
const settingComponentBuilder = (componentData: SettingComponentData[]) => { const settingComponentBuilder = (
const components = componentData.map((data) => { componentData: SettingComponentData[],
switch (data.controllerType) { form?: any,
case 'slider': onlyPrompt?: boolean
const { min, max, step, value } = data.controllerData as SliderData ) => {
return ( const components = componentData
<Slider .filter((x) =>
key={data.name} onlyPrompt ? x.name === 'prompt_template' : x.name !== 'prompt_template'
title={data.title} )
description={data.description} .map((data) => {
min={min} switch (data.controllerType) {
max={max} case 'slider':
step={step} const { min, max, step, value } = data.controllerData as SliderData
value={value} return (
name={data.name} <FormField
/> key={data.title}
) control={form.control}
case 'input': name={data.name}
const { placeholder, value: textValue } = render={({ field }) => (
data.controllerData as InputData <>
return ( <FormItem>
<ModelConfigInput <FormControl>
title={data.title} <Slider
key={data.name} key={data.name}
name={data.name} title={data.title}
description={data.description} description={data.description}
placeholder={placeholder} min={min}
value={textValue} max={max}
/> step={step}
) {...field}
case 'checkbox': value={[field.value || value]}
const { checked } = data.controllerData as CheckboxData />
return ( </FormControl>
<Checkbox <FormMessage />
key={data.name} </FormItem>
name={data.name} </>
description={data.description} )}
title={data.title} />
checked={checked} )
/> case 'input':
) const { placeholder, value: textValue } =
default: data.controllerData as InputData
return null return (
} <FormField
}) key={data.title}
control={form.control}
name={data.name}
render={({ field }) => (
<FormItem>
<FormControl>
<ModelConfigInput
title={data.title}
key={data.name}
description={data.description}
placeholder={placeholder}
{...field}
value={field.value || textValue}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
)
case 'checkbox':
const { checked } = data.controllerData as CheckboxData
return (
<FormField
key={data.title}
control={form.control}
name={data.name}
render={({ field }) => (
<>
<FormItem>
<FormControl>
<Checkbox
key={data.name}
description={data.description}
title={data.title}
{...field}
value={field.value || checked}
/>
</FormControl>
<FormMessage />
</FormItem>
</>
)}
/>
)
default:
return null
}
})
return <div className="flex flex-col gap-y-4">{components}</div> return <div className="flex flex-col gap-y-4">{components}</div>
} }

View File

@ -1,8 +1,18 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import React, { useContext } from 'react' import React, { useContext } from 'react'
import { FieldValues, useForm } from 'react-hook-form'
import { getUserSpace, openFileExplorer, joinPath } from '@janhq/core' import { getUserSpace, openFileExplorer, joinPath } from '@janhq/core'
import { Input, Textarea } from '@janhq/uikit' import {
Input,
Textarea,
Form,
Button,
FormField,
FormItem,
FormControl,
} from '@janhq/uikit'
import { atom, useAtomValue } from 'jotai' import { atom, useAtomValue } from 'jotai'
@ -15,17 +25,21 @@ import DropdownListSidebar, {
selectedModelAtom, selectedModelAtom,
} from '@/containers/DropdownListSidebar' } from '@/containers/DropdownListSidebar'
import { FeatureToggleContext } from '@/context/FeatureToggle'
import { useCreateNewThread } from '@/hooks/useCreateNewThread' import { useCreateNewThread } from '@/hooks/useCreateNewThread'
import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'
import { getConfigurationsData } from '@/utils/componentSettings'
import { toSettingParams } from '@/utils/model_param' import { toSettingParams } from '@/utils/model_param'
import EngineSetting from '../EngineSetting' import EngineSetting from '../EngineSetting'
import ModelSetting from '../ModelSetting' import ModelSetting from '../ModelSetting'
import settingComponentBuilder from '../ModelSetting/settingComponentBuilder'
import { import {
activeThreadAtom, activeThreadAtom,
getActiveThreadIdAtom,
getActiveThreadModelParamsAtom, getActiveThreadModelParamsAtom,
threadStatesAtom, threadStatesAtom,
} from '@/helpers/atoms/Thread.atom' } from '@/helpers/atoms/Thread.atom'
@ -35,13 +49,15 @@ export const showRightSideBarAtom = atom<boolean>(true)
const Sidebar: React.FC = () => { const Sidebar: React.FC = () => {
const showing = useAtomValue(showRightSideBarAtom) const showing = useAtomValue(showRightSideBarAtom)
const activeThread = useAtomValue(activeThreadAtom) const activeThread = useAtomValue(activeThreadAtom)
const activeModelParams = useAtomValue(getActiveThreadModelParamsAtom)
const selectedModel = useAtomValue(selectedModelAtom) const selectedModel = useAtomValue(selectedModelAtom)
const { updateThreadMetadata } = useCreateNewThread() const { updateThreadMetadata } = useCreateNewThread()
const { updateModelParameter } = useUpdateModelParameters()
const threadStates = useAtomValue(threadStatesAtom) const threadStates = useAtomValue(threadStatesAtom)
const { experimentalFeatureEnabed } = useContext(FeatureToggleContext) const threadId = useAtomValue(getActiveThreadIdAtom)
const modelEngineParams = toSettingParams(activeModelParams)
const activeModelParams = useAtomValue(getActiveThreadModelParamsAtom) const componentDataEngineSetting = getConfigurationsData(modelEngineParams)
const modelSettingParams = toSettingParams(activeModelParams)
const onReviewInFinderClick = async (type: string) => { const onReviewInFinderClick = async (type: string) => {
if (!activeThread) return if (!activeThread) return
@ -109,6 +125,62 @@ const Sidebar: React.FC = () => {
openFileExplorer(fullPath) openFileExplorer(fullPath)
} }
const form = useForm()
const filterChangedFormFields = <T extends FieldValues>(
allFields: T,
dirtyFields: Partial<Record<keyof T, boolean | boolean[]>>
): Partial<T> => {
const changedFieldValues = Object.keys(dirtyFields).reduce(
(acc, currentField) => {
const isDirty = Array.isArray(dirtyFields[currentField])
? (dirtyFields[currentField] as boolean[]).some((value) => {
value === true
})
: dirtyFields[currentField] === true
if (isDirty) {
return {
...acc,
[currentField]: allFields[currentField],
}
}
return acc
},
{} as Partial<T>
)
return changedFieldValues
}
const onSubmit = async (values: any) => {
if (!threadId) return
if (!activeThread) return
if (Object.keys(form.formState.dirtyFields).length) {
if (
Object.keys(form.formState.dirtyFields).includes('title') ||
Object.keys(form.formState.dirtyFields).includes('instructions')
) {
updateThreadMetadata({
...activeThread,
title: values.title || activeThread.title,
assistants: [
{
...activeThread.assistants[0],
instructions:
values.instructions || activeThread?.assistants[0].instructions,
},
],
})
}
updateModelParameter(
threadId,
filterChangedFormFields(values, form.formState.dirtyFields)
)
form.reset()
}
}
return ( return (
<div <div
className={twMerge( className={twMerge(
@ -118,83 +190,102 @@ const Sidebar: React.FC = () => {
: 'w-0 translate-x-full opacity-0' : 'w-0 translate-x-full opacity-0'
)} )}
> >
<div <Form {...form}>
className={twMerge( <form onSubmit={form.handleSubmit(onSubmit)}>
'flex flex-col gap-1 delay-200', <div
showing ? 'animate-enter opacity-100' : 'opacity-0' className={twMerge(
)} 'flex flex-col gap-1 delay-200',
> showing ? 'animate-enter opacity-100' : 'opacity-0'
<div className="flex flex-col space-y-4 p-4"> )}
<div> >
<label <div className="flex flex-col space-y-4 p-4">
id="thread-title" <div>
className="mb-2 inline-block font-bold text-zinc-500 dark:text-gray-300" <label
> id="thread-title"
Title className="mb-2 inline-block font-bold text-zinc-500 dark:text-gray-300"
</label> >
<Input Title
id="thread-title" </label>
value={activeThread?.title} <FormField
onChange={(e) => { key={activeThread?.title}
if (activeThread) control={form.control}
updateThreadMetadata({ name="title"
...activeThread, render={({ field }) => (
title: e.target.value || '', <>
}) <FormItem>
}} <FormControl>
/> <Input
</div> id="thread-title"
<div className="flex flex-col"> {...field}
<label defaultValue={activeThread?.title}
id="thread-title" name="title"
className="mb-2 inline-block font-bold text-zinc-500 dark:text-gray-300" onChange={(e) => field.onChange(e)}
> value={field.value}
Threads ID />
</label> </FormControl>
<span className="text-xs text-muted-foreground"> </FormItem>
{activeThread?.id || '-'} </>
</span> )}
</div> />
</div> </div>
<div className="flex flex-col">
<label
id="thread-title"
className="mb-2 inline-block font-bold text-zinc-500 dark:text-gray-300"
>
Threads ID
</label>
<span className="text-xs text-muted-foreground">
{activeThread?.id || '-'}
</span>
</div>
</div>
<CardSidebar <CardSidebar
title="Assistant" title="Assistant"
onRevealInFinderClick={onReviewInFinderClick} onRevealInFinderClick={onReviewInFinderClick}
onViewJsonClick={onViewJsonClick} onViewJsonClick={onViewJsonClick}
> >
<div className="flex flex-col space-y-4 p-2"> <div className="flex flex-col space-y-4 p-2">
<div className="flex items-center space-x-2"> <div className="flex items-center space-x-2">
<LogoMark width={24} height={24} /> <LogoMark width={24} height={24} />
<span className="font-bold capitalize"> <span className="font-bold capitalize">
{activeThread?.assistants[0].assistant_name ?? '-'} {activeThread?.assistants[0].assistant_name ?? '-'}
</span> </span>
</div> </div>
<div> <div>
<label <label
id="thread-title" id="thread-title"
className="mb-2 inline-block font-bold text-zinc-500 dark:text-gray-300" className="mb-2 inline-block font-bold text-zinc-500 dark:text-gray-300"
> >
Instructions Instructions
</label> </label>
<Textarea <FormField
id="assistant-instructions" key={activeThread?.title}
placeholder="Eg. You are a helpful assistant." control={form.control}
value={activeThread?.assistants[0].instructions ?? ''} name="instructions"
onChange={(e) => { render={({ field }) => (
if (activeThread) <>
updateThreadMetadata({ <FormItem>
...activeThread, <FormControl>
assistants: [ <Textarea
{ id="assistant-instructions"
...activeThread.assistants[0], placeholder="Eg. You are a helpful assistant."
instructions: e.target.value || '', {...field}
}, name="instructions"
], defaultValue={
}) activeThread?.assistants[0].instructions
}} }
/> value={field.value}
</div> />
{/* <div> </FormControl>
</FormItem>
</>
)}
/>
</div>
{/* Temporary disabled */}
{/* <div>
<label <label
id="tool-title" id="tool-title"
className="mb-2 inline-block font-bold text-zinc-500 dark:text-gray-300" className="mb-2 inline-block font-bold text-zinc-500 dark:text-gray-300"
@ -208,49 +299,61 @@ const Sidebar: React.FC = () => {
<Switch name="retrieval" /> <Switch name="retrieval" />
</div> </div>
</div> */} </div> */}
</div>
</CardSidebar>
<CardSidebar
title="Model"
onRevealInFinderClick={onReviewInFinderClick}
onViewJsonClick={onViewJsonClick}
>
<div className="p-2">
<DropdownListSidebar />
<div className="mt-6">
<CardSidebar title="Inference Parameters" asChild>
<div className="p-2">
<ModelSetting />
</div>
</CardSidebar>
</div>
<div className="mt-4">
<CardSidebar title="Model Parameters" asChild>
<div className="p-2">{/* <ModelSetting /> */}</div>
</CardSidebar>
</div>
{experimentalFeatureEnabed &&
Object.keys(modelSettingParams).length ? (
<div className="mt-4">
<CardSidebar
title="Engine Parameters"
onRevealInFinderClick={onReviewInFinderClick}
onViewJsonClick={onViewJsonClick}
asChild
>
<div className="p-2">
<EngineSetting />
</div>
</CardSidebar>
</div> </div>
) : null} </CardSidebar>
<CardSidebar
title="Model"
onRevealInFinderClick={onReviewInFinderClick}
onViewJsonClick={onViewJsonClick}
>
<div className="p-2">
<DropdownListSidebar />
<div className="mt-6">
<CardSidebar title="Inference Parameters" asChild>
<div className="p-2">
<ModelSetting form={form} />
</div>
</CardSidebar>
</div>
<div className="mt-4">
<CardSidebar title="Model Parameters" asChild>
<div className="p-2">
{settingComponentBuilder(
componentDataEngineSetting,
form,
true
)}
</div>
</CardSidebar>
</div>
<div className="mt-4">
<CardSidebar
title="Engine Parameters"
onRevealInFinderClick={onReviewInFinderClick}
onViewJsonClick={onViewJsonClick}
asChild
>
<div className="p-2">
<EngineSetting form={form} />
</div>
</CardSidebar>
</div>
{Object.keys(form.formState.dirtyFields).length !== 0 && (
<div className="pt-4">
<Button type="submit" block>
Submit
</Button>
</div>
)}
</div>
</CardSidebar>
</div> </div>
</CardSidebar> </form>
</div> </Form>
</div> </div>
) )
} }

View File

@ -39,6 +39,7 @@ export const toSettingParams = (
embedding: undefined, embedding: undefined,
n_parallel: undefined, n_parallel: undefined,
cpu_threads: undefined, cpu_threads: undefined,
prompt_template: undefined,
} }
const settingParams: ModelSettingParams = {} const settingParams: ModelSettingParams = {}