LibreChat/client/src/components/Endpoints/BingAI/Settings.jsx

142 lines
6.4 KiB
React
Raw Normal View History

2023-04-06 06:07:16 -07:00
import { useEffect, useState } from 'react';
import TextareaAutosize from 'react-textarea-autosize';
import { Label } from '~/components/ui/Label.tsx';
import { Checkbox } from '~/components/ui/Checkbox.tsx';
import SelectDropDown from '../../ui/SelectDropDown';
import { cn } from '~/utils/';
2023-04-06 08:55:25 -07:00
import useDebounce from '~/hooks/useDebounce';
import { useUpdateTokenCountMutation } from '~/data-provider';
const defaultTextProps =
'rounded-md border border-gray-200 focus:border-slate-400 focus:bg-gray-50 bg-transparent text-sm shadow-[0_0_10px_rgba(0,0,0,0.05)] outline-none placeholder:text-gray-400 focus:outline-none focus:ring-gray-400 focus:ring-opacity-20 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-gray-500 dark:bg-gray-700 focus:dark:bg-gray-600 dark:text-gray-50 dark:shadow-[0_0_15px_rgba(0,0,0,0.10)] dark:focus:border-gray-400 dark:focus:outline-none dark:focus:ring-0 dark:focus:ring-gray-400 dark:focus:ring-offset-0';
function Settings(props) {
2023-04-05 02:30:14 +08:00
const { readonly, context, systemMessage, jailbreak, toneStyle, setOption } = props;
const [tokenCount, setTokenCount] = useState(0);
const showSystemMessage = jailbreak;
const setContext = setOption('context');
const setSystemMessage = setOption('systemMessage');
const setJailbreak = setOption('jailbreak');
2023-04-05 02:30:14 +08:00
const setToneStyle = value => setOption('toneStyle')(value.toLowerCase());
2023-04-06 08:55:25 -07:00
const debouncedContext = useDebounce(context, 250);
const updateTokenCountMutation = useUpdateTokenCountMutation();
useEffect(() => {
2023-04-06 08:55:25 -07:00
if (!debouncedContext || debouncedContext.trim() === '') {
setTokenCount(0);
return;
}
const handleTextChange = (context) => {
updateTokenCountMutation.mutate(
{ text: context },
{
onSuccess: (data) => {
setTokenCount(data.count);
}
}
);
};
2023-04-06 08:55:25 -07:00
handleTextChange(debouncedContext);
}, [debouncedContext]);
return (
Feat: PaLM 2 (#262) * feat(api): add googleapis package to package.json feat(api): add reqDemo.js file to make a request to Google Cloud AI Platform API to get a response from a chatbot model. * feat: add PaLM2 support * feat(conversationPreset.js): add support for topP and topK for google endpoint feat(askGoogle.js): add support for topP and topK for google endpoint feat(ask/index.js): add google endpoint feat(endpoints.js): add google endpoint feat(MessageHeader.jsx): add support for modelLabel for google endpoint feat(PresetItem.jsx): add support for modelLabel for google endpoint feat(HoverButtons.jsx): add support for google endpoint feat(createPayload.ts): add google endpoint feat(types.ts): add google endpoint feat(store/endpoints.js): add google endpoint feat(cleanupPreset.js): add support for topP and topK for google endpoint feat(getDefaultConversation.js): add support for topP and topK for google endpoint feat(handleSubmit.js): add support for topP and topK for google endpoint * fix: messages payload * refactor(GoogleClient.js): set maxContextTokens based on isTextModel value feat(GoogleClient.js): add delay option to TextStream constructor feat(getIcon.jsx): add support for google endpoint and PaLM2 model label * feat: palm frontend changes * feat(askGoogle.js): set default example to empty input and output feat(Examples.jsx): add ability to add and remove examples refactor(Settings.jsx): remove examples from props and setOption function style(GoogleOptions): remove unnecessary whitespace after Settings2 import feat(GoogleOptions): add addExample and removeExample functions to manage examples fix(cleanupPreset): set default example to [{ input: '', output: ''}] fix(getDefaultConversation): set default example to [{ input: '', output: ''}] fix(handleSubmit): set default example to [{ input: '', output: ''}] * style(client): adjust height of settings and examples components to 350px fix(client): fix path to palm.png image in getIcon.jsx file * style(EndpointOptionsPopover.jsx, Examples.jsx, Settings.jsx): improve button styles and update input placeholders * feat (palm): finalize examples on the frontend * feat(GoogleClient.js): filter out empty examples in options feat(GoogleClient.js): add support for promptPrefix in buildPayload method feat(GoogleClient.js): add support for examples in buildPayload method feat(conversationPreset.js): add maxOutputTokens field to conversation preset schema feat(presetSchema.js): add examples field to preset schema feat(askGoogle.js): add support for examples and promptPrefix in endpointOption feat(EditPresetDialog.jsx): add Examples component for Google endpoint feat(EditPresetDialog.jsx): add button to show/hide Examples component feat(EditPresetDialog.jsx): add functionality to add, remove, and edit examples in Examples component feat(EndpointOptionsDialog.jsx): change endpoint name to PaLM for Google endpoint feat(Settings.jsx): add maxHeight prop to limit height of Settings component in EditPresetDialog and EndpointOptionsDialog fix(Settings.jsx): add examples prop to ChatGPTBrowser component fix(EndpointItem.jsx): add alternate name for google endpoint fix(MessageHeader.jsx): change title for google endpoint to PaLM feat(endpoints.js): add google endpoint to endpointsConfig fix(cleanupPreset.js): add missing comma in examples array * chore: change endpoint order * feat(PaLM 2): complete for testing * fix(PaLM): handle blocked messages
2023-05-13 16:29:06 -04:00
<div className="max-h-[350px] overflow-y-auto">
<div className="grid gap-6 sm:grid-cols-2">
<div className="col-span-1 flex flex-col items-center justify-start gap-6">
<div className="grid w-full items-center gap-2">
<Label htmlFor="toneStyle-dropdown" className="text-left text-sm font-medium">
2023-04-05 03:07:46 +08:00
Tone Style <small className="opacity-40">(default: fast)</small>
</Label>
<SelectDropDown
id="toneStyle-dropdown"
2023-04-05 03:07:46 +08:00
title={null}
value={`${toneStyle.charAt(0).toUpperCase()}${toneStyle.slice(1)}`}
2023-04-05 03:07:46 +08:00
setValue={setToneStyle}
availableValues={['Creative', 'Fast', 'Balanced', 'Precise']}
disabled={readonly}
className={cn(
defaultTextProps,
2023-04-05 03:07:46 +08:00
'flex w-full resize-none focus:outline-none focus:ring-0 focus:ring-opacity-0 focus:ring-offset-0'
)}
containerClassName="flex w-full resize-none"
/>
2023-04-05 03:07:46 +08:00
</div>
<div className="grid w-full items-center gap-2">
<Label htmlFor="context" className="text-left text-sm font-medium">
Context <small className="opacity-40">(default: blank)</small>
</Label>
<TextareaAutosize
id="context"
disabled={readonly}
value={context || ''}
onChange={e => setContext(e.target.value || null)}
placeholder="Bing can use up to 7k tokens for 'context', which it can reference for the conversation. The specific limit is not known but may run into errors exceeding 7k tokens"
className={cn(
defaultTextProps,
'flex max-h-[300px] min-h-[100px] w-full resize-none px-3 py-2'
)}
/>
2023-04-05 02:30:14 +08:00
<small className="mb-5 text-black dark:text-white">{`Token count: ${tokenCount}`}</small>
</div>
</div>
<div className="col-span-1 flex flex-col items-center justify-start gap-6">
<div className="grid w-full items-center gap-2">
<Label htmlFor="jailbreak" className="text-left text-sm font-medium">
2023-04-05 03:07:46 +08:00
Enable Sydney <small className="opacity-40">(default: false)</small>
</Label>
<div className="flex h-[40px] w-full items-center space-x-3">
<Checkbox
id="jailbreak"
disabled={readonly}
checked={jailbreak}
className="focus:ring-opacity-20 dark:border-gray-500 dark:bg-gray-700 dark:text-gray-50 dark:focus:ring-gray-600 dark:focus:ring-opacity-50 dark:focus:ring-offset-0"
onCheckedChange={setJailbreak}
/>
<label
htmlFor="jailbreak"
className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 dark:text-gray-50"
>
2023-04-05 03:07:46 +08:00
Jailbreak <small>To enable Sydney</small>
</label>
2023-04-05 03:07:46 +08:00
</div>
</div>
{showSystemMessage && (
<div className="grid w-full items-center gap-2">
<Label
htmlFor="systemMessage"
2023-04-05 03:07:46 +08:00
className="text-left text-sm font-medium"
style={{ opacity: showSystemMessage ? '1' : '0' }}
>
<a
href="https://github.com/danny-avila/chatgpt-clone/blob/main/client/defaultSystemMessage.md"
target="_blank"
className="text-blue-500 transition-colors duration-200 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-500"
>
System Message
</a>{' '}
2023-04-05 03:07:46 +08:00
<small className="opacity-40 dark:text-gray-50">(default: blank)</small>
</Label>
2023-04-05 03:07:46 +08:00
<TextareaAutosize
id="systemMessage"
disabled={readonly}
value={systemMessage || ''}
onChange={e => setSystemMessage(e.target.value || null)}
placeholder="WARNING: Misuse of this feature can get you BANNED from using Bing! Click on 'System Message' for full instructions and the default message if omitted, which is the 'Sydney' preset that is considered safe."
className={cn(
defaultTextProps,
'flex max-h-[300px] min-h-[100px] w-full resize-none px-3 py-2 placeholder:text-red-400'
)}
/>
</div>
2023-04-05 03:07:46 +08:00
)}
</div>
</div>
Feat: PaLM 2 (#262) * feat(api): add googleapis package to package.json feat(api): add reqDemo.js file to make a request to Google Cloud AI Platform API to get a response from a chatbot model. * feat: add PaLM2 support * feat(conversationPreset.js): add support for topP and topK for google endpoint feat(askGoogle.js): add support for topP and topK for google endpoint feat(ask/index.js): add google endpoint feat(endpoints.js): add google endpoint feat(MessageHeader.jsx): add support for modelLabel for google endpoint feat(PresetItem.jsx): add support for modelLabel for google endpoint feat(HoverButtons.jsx): add support for google endpoint feat(createPayload.ts): add google endpoint feat(types.ts): add google endpoint feat(store/endpoints.js): add google endpoint feat(cleanupPreset.js): add support for topP and topK for google endpoint feat(getDefaultConversation.js): add support for topP and topK for google endpoint feat(handleSubmit.js): add support for topP and topK for google endpoint * fix: messages payload * refactor(GoogleClient.js): set maxContextTokens based on isTextModel value feat(GoogleClient.js): add delay option to TextStream constructor feat(getIcon.jsx): add support for google endpoint and PaLM2 model label * feat: palm frontend changes * feat(askGoogle.js): set default example to empty input and output feat(Examples.jsx): add ability to add and remove examples refactor(Settings.jsx): remove examples from props and setOption function style(GoogleOptions): remove unnecessary whitespace after Settings2 import feat(GoogleOptions): add addExample and removeExample functions to manage examples fix(cleanupPreset): set default example to [{ input: '', output: ''}] fix(getDefaultConversation): set default example to [{ input: '', output: ''}] fix(handleSubmit): set default example to [{ input: '', output: ''}] * style(client): adjust height of settings and examples components to 350px fix(client): fix path to palm.png image in getIcon.jsx file * style(EndpointOptionsPopover.jsx, Examples.jsx, Settings.jsx): improve button styles and update input placeholders * feat (palm): finalize examples on the frontend * feat(GoogleClient.js): filter out empty examples in options feat(GoogleClient.js): add support for promptPrefix in buildPayload method feat(GoogleClient.js): add support for examples in buildPayload method feat(conversationPreset.js): add maxOutputTokens field to conversation preset schema feat(presetSchema.js): add examples field to preset schema feat(askGoogle.js): add support for examples and promptPrefix in endpointOption feat(EditPresetDialog.jsx): add Examples component for Google endpoint feat(EditPresetDialog.jsx): add button to show/hide Examples component feat(EditPresetDialog.jsx): add functionality to add, remove, and edit examples in Examples component feat(EndpointOptionsDialog.jsx): change endpoint name to PaLM for Google endpoint feat(Settings.jsx): add maxHeight prop to limit height of Settings component in EditPresetDialog and EndpointOptionsDialog fix(Settings.jsx): add examples prop to ChatGPTBrowser component fix(EndpointItem.jsx): add alternate name for google endpoint fix(MessageHeader.jsx): change title for google endpoint to PaLM feat(endpoints.js): add google endpoint to endpointsConfig fix(cleanupPreset.js): add missing comma in examples array * chore: change endpoint order * feat(PaLM 2): complete for testing * fix(PaLM): handle blocked messages
2023-05-13 16:29:06 -04:00
</div>
);
}
export default Settings;