-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding model params (janhq#886)
* feat: adding model params Signed-off-by: James <[email protected]> * chore: inference request parameter * Improve ui right panel model params * Remove unused import * Update slider track for darkmode --------- Signed-off-by: James <[email protected]> Co-authored-by: James <[email protected]> Co-authored-by: Louis <[email protected]> Co-authored-by: Faisal Amir <[email protected]>
- Loading branch information
1 parent
5f7001d
commit 121dc11
Showing
36 changed files
with
758 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use client' | ||
|
||
import * as React from 'react' | ||
import * as SliderPrimitive from '@radix-ui/react-slider' | ||
|
||
import { twMerge } from 'tailwind-merge' | ||
|
||
const Slider = React.forwardRef< | ||
React.ElementRef<typeof SliderPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof SliderPrimitive.Root> | ||
>(({ className, ...props }, ref) => ( | ||
<SliderPrimitive.Root | ||
ref={ref} | ||
className={twMerge('slider', className)} | ||
{...props} | ||
> | ||
<SliderPrimitive.Track className="slider-track"> | ||
<SliderPrimitive.Range className="slider-range" /> | ||
</SliderPrimitive.Track> | ||
<SliderPrimitive.Thumb className="slider-thumb" /> | ||
</SliderPrimitive.Root> | ||
)) | ||
Slider.displayName = SliderPrimitive.Root.displayName | ||
|
||
export { Slider } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.slider { | ||
@apply relative flex w-full touch-none select-none items-center; | ||
|
||
&-track { | ||
@apply relative h-1.5 w-full grow overflow-hidden rounded-full bg-gray-200 dark:bg-gray-800; | ||
} | ||
|
||
&-range { | ||
@apply absolute h-full bg-blue-600; | ||
} | ||
|
||
&-thumb { | ||
@apply border-primary/50 bg-background focus-visible:ring-ring block h-4 w-4 rounded-full border shadow transition-colors focus-visible:outline-none focus-visible:ring-1 disabled:pointer-events-none disabled:opacity-50; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { useEffect, useState } from 'react' | ||
|
||
import { Switch } from '@janhq/uikit' | ||
|
||
import { useAtomValue } from 'jotai' | ||
|
||
import useUpdateModelParameters from '@/hooks/useUpdateModelParameters' | ||
|
||
import { | ||
getActiveThreadIdAtom, | ||
getActiveThreadModelRuntimeParamsAtom, | ||
} from '@/helpers/atoms/Thread.atom' | ||
|
||
type Props = { | ||
name: string | ||
title: string | ||
checked: boolean | ||
register: any | ||
} | ||
|
||
const Checkbox: React.FC<Props> = ({ name, title, checked, register }) => { | ||
const [currentChecked, setCurrentChecked] = useState<boolean>(checked) | ||
const { updateModelParameter } = useUpdateModelParameters() | ||
const threadId = useAtomValue(getActiveThreadIdAtom) | ||
const activeModelParams = useAtomValue(getActiveThreadModelRuntimeParamsAtom) | ||
|
||
useEffect(() => { | ||
setCurrentChecked(checked) | ||
}, [checked]) | ||
|
||
useEffect(() => { | ||
updateSetting() | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [currentChecked]) | ||
|
||
const updateValue = [name].reduce((accumulator, value) => { | ||
return { ...accumulator, [value]: currentChecked } | ||
}, {}) | ||
|
||
const updateSetting = () => { | ||
return updateModelParameter(String(threadId), { | ||
...activeModelParams, | ||
...updateValue, | ||
}) | ||
} | ||
|
||
return ( | ||
<div className="flex justify-between"> | ||
<label>{title}</label> | ||
<Switch | ||
checked={currentChecked} | ||
{...register(name)} | ||
onCheckedChange={(e) => { | ||
setCurrentChecked(e) | ||
}} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default Checkbox |
Oops, something went wrong.