mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
feat: select model
feat: force to be advanced mode
This commit is contained in:
parent
059006382d
commit
bb1f8d731b
2 changed files with 86 additions and 10 deletions
54
client/src/components/Input/OpenAIOptions/ModelSelect.jsx
Normal file
54
client/src/components/Input/OpenAIOptions/ModelSelect.jsx
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
import React, { useState } from 'react';
|
||||||
|
import { Button } from '../../ui/Button.tsx';
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuLabel,
|
||||||
|
DropdownMenuRadioGroup,
|
||||||
|
DropdownMenuSeparator,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
DropdownMenuRadioItem
|
||||||
|
} from '../../ui/DropdownMenu.tsx';
|
||||||
|
|
||||||
|
const ModelSelect = ({ model, onChange, models, ...props }) => {
|
||||||
|
const [menuOpen, setMenuOpen] = useState(false);
|
||||||
|
|
||||||
|
models = ['gpt-4', 'text-davinci-003', 'gpt-3.5-turbo', 'gpt-3.5-turbo-0301'];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DropdownMenu
|
||||||
|
open={menuOpen}
|
||||||
|
onOpenChange={setMenuOpen}
|
||||||
|
>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button {...props}>
|
||||||
|
<span className="w-full text-center text-xs font-medium font-normal">Model: {model}</span>
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent
|
||||||
|
className="w-56 dark:bg-gray-700"
|
||||||
|
onCloseAutoFocus={event => event.preventDefault()}
|
||||||
|
>
|
||||||
|
<DropdownMenuLabel className="dark:text-gray-300">Select a model</DropdownMenuLabel>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
<DropdownMenuRadioGroup
|
||||||
|
value={model}
|
||||||
|
onValueChange={onChange}
|
||||||
|
className="overflow-y-auto"
|
||||||
|
>
|
||||||
|
{models.map(model => (
|
||||||
|
<DropdownMenuRadioItem
|
||||||
|
key={model}
|
||||||
|
value={model}
|
||||||
|
className="dark:font-semibold dark:text-gray-100 dark:hover:bg-gray-800"
|
||||||
|
>
|
||||||
|
{model}
|
||||||
|
</DropdownMenuRadioItem>
|
||||||
|
))}
|
||||||
|
</DropdownMenuRadioGroup>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ModelSelect;
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import React, { useState, useEffect, forwardRef } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { Tabs, TabsList, TabsTrigger } from '../../ui/Tabs.tsx';
|
import { useSetRecoilState } from 'recoil';
|
||||||
import { useRecoilValue, useRecoilState, useSetRecoilState } from 'recoil';
|
import ModelSelect from './ModelSelect';
|
||||||
import { Button } from '../../ui/Button.tsx';
|
import { Button } from '../../ui/Button.tsx';
|
||||||
|
|
||||||
import store from '~/store';
|
import store from '~/store';
|
||||||
|
|
@ -13,7 +13,6 @@ function OpenAIOptions({ conversation = {} }) {
|
||||||
const triggerAdvancedMode = () => setAdvancedMode(prev => !prev);
|
const triggerAdvancedMode = () => setAdvancedMode(prev => !prev);
|
||||||
|
|
||||||
const switchToSimpleMode = () => {
|
const switchToSimpleMode = () => {
|
||||||
setAdvancedMode(false);
|
|
||||||
setConversation(prevState => ({
|
setConversation(prevState => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
chatGptLabel: null,
|
chatGptLabel: null,
|
||||||
|
|
@ -22,8 +21,31 @@ function OpenAIOptions({ conversation = {} }) {
|
||||||
top_p: 1,
|
top_p: 1,
|
||||||
presence_penalty: 1
|
presence_penalty: 1
|
||||||
}));
|
}));
|
||||||
|
setAdvancedMode(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const setModel = newModel => {
|
||||||
|
setConversation(prevState => ({
|
||||||
|
...prevState,
|
||||||
|
model: newModel
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const { endpoint, chatGptLabel, promptPrefix, temperature, top_p, presence_penalty } = conversation;
|
||||||
|
|
||||||
|
if (endpoint !== 'openAI') return;
|
||||||
|
|
||||||
|
const mustInAdvancedMode =
|
||||||
|
chatGptLabel !== null ||
|
||||||
|
promptPrefix !== null ||
|
||||||
|
temperature !== 0.8 ||
|
||||||
|
top_p !== 1 ||
|
||||||
|
presence_penalty !== 1;
|
||||||
|
|
||||||
|
if (mustInAdvancedMode && !advancedMode) setAdvancedMode(true);
|
||||||
|
}, [conversation, advancedMode]);
|
||||||
|
|
||||||
if (endpoint !== 'openAI') return null;
|
if (endpoint !== 'openAI') return null;
|
||||||
|
|
||||||
const { model } = conversation;
|
const { model } = conversation;
|
||||||
|
|
@ -39,15 +61,15 @@ function OpenAIOptions({ conversation = {} }) {
|
||||||
(!advancedMode ? ' show' : '')
|
(!advancedMode ? ' show' : '')
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Button
|
<ModelSelect
|
||||||
|
model={model}
|
||||||
|
onChange={setModel}
|
||||||
type="button"
|
type="button"
|
||||||
className={
|
className={
|
||||||
cardStyle +
|
cardStyle +
|
||||||
' flex h-[40px] items-center justify-center px-4 hover:bg-slate-50 dark:hover:bg-gray-600'
|
' flex h-[40px] items-center justify-center px-4 hover:bg-slate-50 data-[state=open]:bg-slate-50 dark:hover:bg-gray-600 dark:data-[state=open]:bg-gray-600'
|
||||||
}
|
}
|
||||||
>
|
/>
|
||||||
<span className="w-full text-center text-xs font-medium font-normal">Model: {model}</span>
|
|
||||||
</Button>
|
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
className={
|
className={
|
||||||
|
|
@ -62,7 +84,7 @@ function OpenAIOptions({ conversation = {} }) {
|
||||||
<div
|
<div
|
||||||
className={
|
className={
|
||||||
cardStyle +
|
cardStyle +
|
||||||
' p-b-[40px] openAIOptions-advanced-container absolute left-4 right-4 bottom-[40px] flex flex-col overflow-hidden rounded-md bg-white px-0' +
|
' p-b-[40px] openAIOptions-advanced-container absolute left-4 right-4 bottom-[40px] flex flex-col overflow-hidden rounded-md bg-slate-100 bg-white px-0' +
|
||||||
(advancedMode ? ' show' : '')
|
(advancedMode ? ' show' : '')
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue