Skip to content

Commit

Permalink
Plug model list into model select menu
Browse files Browse the repository at this point in the history
  • Loading branch information
cybermaggedon committed Oct 11, 2024
1 parent 8447cc8 commit 91c1841
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 47 deletions.
9 changes: 6 additions & 3 deletions src/simple-editor/ModelDeployment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import {
} from '@mui/material';

interface ModelDeploymentProps {
value: string;
onChange: (value: string) => void;
value : string;
onChange: (value: string) => void;
}

const ModelDeployment: React.FC<ModelDeploymentProps> = ({ value, onChange }) => {
const ModelDeployment: React.FC<ModelDeploymentProps> = ({
value, onChange
}) => {

return (

<FormControl fullWidth>
Expand Down
152 changes: 110 additions & 42 deletions src/simple-editor/ModelParameters.tsx
Original file line number Diff line number Diff line change
@@ -1,52 +1,120 @@
import React from 'react';
import { TextField, Slider } from '@mui/material';
import {
FormControl, InputLabel, Select, MenuItem, TextField, Slider
} from '@mui/material';

import modelsRaw from './models.json';
const models = modelsRaw as { [ix : string ] : string[] };

interface ModelParametersProps {
modelName: string;
temperature: number;
maxOutputTokens: number;
onModelNameChange: (value: string) => void;
onTemperatureChange: (value: number) => void;
onMaxOutputTokensChange: (value: number) => void;
modelName: string;
temperature: number;
maxOutputTokens: number;
onModelNameChange: (value: string) => void;
onTemperatureChange: (value: number) => void;
onMaxOutputTokensChange: (value: number) => void;
modelDeployment : string;
}

const ModelParameters: React.FC<ModelParametersProps> = ({
modelName,
temperature,
maxOutputTokens,
onModelNameChange,
onTemperatureChange,
onMaxOutputTokensChange,
modelName,
temperature,
modelDeployment,
maxOutputTokens,
onModelNameChange,
onTemperatureChange,
onMaxOutputTokensChange,
}) => {
return (
<div>
<TextField
fullWidth
label="Model Name"
value={modelName}
onChange={(e) => onModelNameChange(e.target.value)}
margin="normal"
/>
<div>
<p>Temperature: {temperature}</p>
<Slider
value={temperature}
onChange={(_, value) => onTemperatureChange(value as number)}
min={0}
max={1}
step={0.1}
/>
</div>
<TextField
fullWidth
label="Max Output Tokens"
type="number"
value={maxOutputTokens}
onChange={(e) => onMaxOutputTokensChange(parseInt(e.target.value))}
margin="normal"
/>
</div>
);

const availModels = models[modelDeployment];

const ModelList : React.FC<{
modelName : string;
availModels : string[];
onModelNameChange : (value: string) => void;
}> = ({ modelName, availModels, onModelNameChange}) => {

const readOnly = (availModels.length == 0);

if (availModels.length == 0) {
return (
<FormControl fullWidth disabled>

<InputLabel id="model-name-label">Model</InputLabel>

<Select
labelId="model-name-label"
id="model-name-select"
value="n/a"
label="Model deployment"
>
<MenuItem key="n/a" value="n/a">n/a</MenuItem>
</Select>
</FormControl>
);

}

return (
<FormControl fullWidth>

<InputLabel id="model-name-label">Model</InputLabel>

<Select
labelId="model-name-label"
id="model-name-select"
value={modelName}
label="Model deployment"
onChange={(e) => onModelNameChange(e.target.value)}
inputProps={{ readOnly: readOnly }}
>
{
availModels.map(
(v) => (
<MenuItem key={v}
value={v}>
{v}
</MenuItem>
))
}
</Select>

</FormControl>

);
}

return (
<div>

<ModelList modelName={modelName} availModels={availModels}
onModelNameChange={onModelNameChange}
/>

<div>
<p>Temperature: {temperature}</p>
<Slider
value={temperature}
onChange={
(_, value) => onTemperatureChange(value as number)
}
min={0}
max={1}
step={0.1}
/>
</div>
<TextField
fullWidth
label="Max Output Tokens"
type="number"
value={maxOutputTokens}
onChange={
(e) => onMaxOutputTokensChange(parseInt(e.target.value))
}
margin="normal"
/>
</div>
);
};

export default ModelParameters;
Expand Down
18 changes: 18 additions & 0 deletions src/simple-editor/ParamsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import ModelParameters from './ModelParameters';
import { useModelParamsStore } from './state/ModelParams';
import { useDeploymentStore } from './state/Deployment';

import modelsRaw from './models.json';
const models = modelsRaw as { [ix : string ] : string[] };

interface ParamsFormProps {
}

Expand Down Expand Up @@ -79,6 +82,20 @@ const ParamsForm: React.FC<ParamsFormProps> = ({
const setMaxOutputTokens
= useModelParamsStore((state) => state.setMaxOutputTokens);

useModelParamsStore.subscribe(
(n, o) => {

if (n.modelDeployment == o.modelDeployment) return;

if (n.modelName in models[n.modelDeployment]) return;

if (models[n.modelDeployment].length == 0)
setModelName("");
else
setModelName(models[n.modelDeployment][0]);

}
);

return (

Expand Down Expand Up @@ -119,6 +136,7 @@ const ParamsForm: React.FC<ParamsFormProps> = ({
onModelNameChange={setModelName}
onTemperatureChange={setTemperature}
onMaxOutputTokensChange={setMaxOutputTokens}
modelDeployment={modelDeployment}
/>
</Box>

Expand Down
8 changes: 6 additions & 2 deletions src/simple-editor/models.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"anthropic": [
"claude": [
"claude-3-5-sonnet-20240620",
"claude-3-opus-20240229",
"claude-3-sonnet-20240229",
Expand Down Expand Up @@ -94,5 +94,9 @@
"gemini-flash-experimental",
"gemini-pro-experimental",
"gemini-experimental"
],
"llamafile": [
],
"azure": [
]
}
}

0 comments on commit 91c1841

Please sign in to comment.