Skip to content

Commit

Permalink
🇬 refactor: Update default Google Models and Parameters (#2782)
Browse files Browse the repository at this point in the history
* Update Google default model and parameters

* Update .env.example Vertex AI Models to reflect latest version and deprecate bison family

* Update Vertex AI model list in .env.example
  • Loading branch information
achhabra2 authored and danny-avila committed May 27, 2024
1 parent 2c84f28 commit c0221a5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ GOOGLE_KEY=user_provided
# GOOGLE_MODELS=gemini-1.5-flash-latest,gemini-1.0-pro,gemini-1.0-pro-001,gemini-1.0-pro-latest,gemini-1.0-pro-vision-latest,gemini-1.5-pro-latest,gemini-pro,gemini-pro-vision

# Vertex AI
# GOOGLE_MODELS=gemini-1.5-flash-preview-0514,gemini-1.5-pro-preview-0409,gemini-1.0-pro-vision-001,gemini-pro,gemini-pro-vision,chat-bison,chat-bison-32k,codechat-bison,codechat-bison-32k,text-bison,text-bison-32k,text-unicorn,code-gecko,code-bison,code-bison-32k
# GOOGLE_MODELS=gemini-1.5-flash-preview-0514,gemini-1.5-pro-preview-0514,gemini-1.0-pro-vision-001,gemini-1.0-pro-002,gemini-1.0-pro-001,gemini-pro-vision,gemini-1.0-pro

# Google Gemini Safety Settings
# NOTE (Vertex AI): You do not have access to the BLOCK_NONE setting by default.
Expand Down
32 changes: 6 additions & 26 deletions client/src/components/Endpoints/Settings/Google.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useEffect } from 'react';
import TextareaAutosize from 'react-textarea-autosize';
import { EModelEndpoint, endpointSettings } from 'librechat-data-provider';
import type { TModelSelectProps, OnInputNumberChange } from '~/common';
Expand Down Expand Up @@ -31,25 +30,6 @@ export default function Settings({ conversation, setOption, models, readonly }:
maxOutputTokens,
} = conversation ?? {};

const isGemini = model?.toLowerCase()?.includes('gemini');

const maxOutputTokensMax = isGemini
? google.maxOutputTokens.maxGemini
: google.maxOutputTokens.max;
const maxOutputTokensDefault = isGemini
? google.maxOutputTokens.defaultGemini
: google.maxOutputTokens.default;

useEffect(
() => {
if (model) {
setOption('maxOutputTokens')(Math.min(Number(maxOutputTokens) ?? 0, maxOutputTokensMax));
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[model],
);

const [setMaxContextTokens, maxContextTokensValue] = useDebouncedInput<number | null | undefined>(
{
setOption,
Expand Down Expand Up @@ -281,15 +261,15 @@ export default function Settings({ conversation, setOption, models, readonly }:
<Label htmlFor="max-tokens-int" className="text-left text-sm font-medium">
{localize('com_endpoint_max_output_tokens')}{' '}
<small className="opacity-40">
({localize('com_endpoint_default_with_num', maxOutputTokensDefault + '')})
({localize('com_endpoint_default_with_num', google.maxOutputTokens.default + '')})
</small>
</Label>
<InputNumber
id="max-tokens-int"
disabled={readonly}
value={maxOutputTokens}
onChange={(value) => setMaxOutputTokens(value ?? maxOutputTokensDefault)}
max={maxOutputTokensMax}
onChange={(value) => setMaxOutputTokens(Number(value))}
max={google.maxOutputTokens.max}
min={google.maxOutputTokens.min}
step={google.maxOutputTokens.step}
controls={false}
Expand All @@ -304,10 +284,10 @@ export default function Settings({ conversation, setOption, models, readonly }:
</div>
<Slider
disabled={readonly}
value={[maxOutputTokens ?? maxOutputTokensDefault]}
value={[maxOutputTokens ?? google.maxOutputTokens.default]}
onValueChange={(value) => setMaxOutputTokens(value[0])}
doubleClickHandler={() => setMaxOutputTokens(maxOutputTokensDefault)}
max={maxOutputTokensMax}
doubleClickHandler={() => setMaxOutputTokens(google.maxOutputTokens.default)}
max={google.maxOutputTokens.max}
min={google.maxOutputTokens.min}
step={google.maxOutputTokens.step}
className="flex h-4 w-full"
Expand Down
14 changes: 1 addition & 13 deletions packages/data-provider/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,26 +555,14 @@ export const generateGoogleSchema = (customGoogle: GoogleSettings) => {
maxContextTokens: true,
})
.transform((obj) => {
const isGemini = obj?.model?.toLowerCase()?.includes('gemini');

const maxOutputTokensMax = isGemini
? defaults.maxOutputTokens.maxGemini
: defaults.maxOutputTokens.max;
const maxOutputTokensDefault = isGemini
? defaults.maxOutputTokens.defaultGemini
: defaults.maxOutputTokens.default;

let maxOutputTokens = obj.maxOutputTokens ?? maxOutputTokensDefault;
maxOutputTokens = Math.min(maxOutputTokens, maxOutputTokensMax);

return {
...obj,
model: obj.model ?? defaults.model.default,
modelLabel: obj.modelLabel ?? null,
promptPrefix: obj.promptPrefix ?? null,
examples: obj.examples ?? [{ input: { content: '' }, output: { content: '' } }],
temperature: obj.temperature ?? defaults.temperature.default,
maxOutputTokens,
maxOutputTokens: obj.maxOutputTokens ?? defaults.maxOutputTokens.default,
topP: obj.topP ?? defaults.topP.default,
topK: obj.topK ?? defaults.topK.default,
maxContextTokens: obj.maxContextTokens ?? undefined,
Expand Down
28 changes: 7 additions & 21 deletions packages/data-provider/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,25 @@ export const openAISettings = {

export const googleSettings = {
model: {
default: 'chat-bison',
default: 'gemini-1.5-flash-latest',
},
maxOutputTokens: {
min: 1,
max: 2048,
max: 8192,
step: 1,
default: 1024,
maxGemini: 8192,
defaultGemini: 8192,
default: 8192,
},
temperature: {
min: 0,
max: 1,
max: 2,
step: 0.01,
default: 0.2,
default: 1,
},
topP: {
min: 0,
max: 1,
step: 0.01,
default: 0.8,
default: 0.95,
},
topK: {
min: 1,
Expand Down Expand Up @@ -484,26 +482,14 @@ export const googleSchema = tConversationSchema
maxContextTokens: true,
})
.transform((obj) => {
const isGemini = obj?.model?.toLowerCase()?.includes('gemini');

const maxOutputTokensMax = isGemini
? google.maxOutputTokens.maxGemini
: google.maxOutputTokens.max;
const maxOutputTokensDefault = isGemini
? google.maxOutputTokens.defaultGemini
: google.maxOutputTokens.default;

let maxOutputTokens = obj.maxOutputTokens ?? maxOutputTokensDefault;
maxOutputTokens = Math.min(maxOutputTokens, maxOutputTokensMax);

return {
...obj,
model: obj.model ?? google.model.default,
modelLabel: obj.modelLabel ?? null,
promptPrefix: obj.promptPrefix ?? null,
examples: obj.examples ?? [{ input: { content: '' }, output: { content: '' } }],
temperature: obj.temperature ?? google.temperature.default,
maxOutputTokens,
maxOutputTokens: obj.maxOutputTokens ?? google.maxOutputTokens.default,
topP: obj.topP ?? google.topP.default,
topK: obj.topK ?? google.topK.default,
iconURL: obj.iconURL ?? undefined,
Expand Down

0 comments on commit c0221a5

Please sign in to comment.