2023-06-15 12:52:46 +03:00
|
|
|
/* eslint-disable */
|
2023-06-12 14:15:03 +03:00
|
|
|
"use client";
|
|
|
|
|
2023-06-15 12:52:46 +03:00
|
|
|
import { UseFormRegister } from "react-hook-form";
|
|
|
|
|
2023-06-13 17:33:41 +03:00
|
|
|
import Field from "@/lib/components/ui/Field";
|
2023-06-12 14:15:03 +03:00
|
|
|
import {
|
|
|
|
BrainConfig,
|
|
|
|
Model,
|
2023-06-14 22:30:52 +03:00
|
|
|
PaidModels,
|
2023-06-12 14:15:03 +03:00
|
|
|
anthropicModels,
|
|
|
|
models,
|
|
|
|
paidModels,
|
|
|
|
} from "@/lib/context/BrainConfigProvider/types";
|
|
|
|
|
|
|
|
interface ModelConfigProps {
|
|
|
|
register: UseFormRegister<BrainConfig>;
|
2023-06-14 22:30:52 +03:00
|
|
|
model: Model | PaidModels;
|
2023-06-12 14:15:03 +03:00
|
|
|
openAiKey: string | undefined;
|
|
|
|
temperature: number;
|
|
|
|
maxTokens: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const ModelConfig = ({
|
|
|
|
register,
|
|
|
|
model,
|
|
|
|
openAiKey,
|
|
|
|
temperature,
|
|
|
|
maxTokens,
|
|
|
|
}: ModelConfigProps): JSX.Element => {
|
2023-06-14 22:30:52 +03:00
|
|
|
const defineMaxTokens = (model: Model | PaidModels): number => {
|
|
|
|
//At the moment is evaluating only models from OpenAI
|
|
|
|
switch (model) {
|
|
|
|
case "gpt-3.5-turbo-0613":
|
2023-07-01 18:22:28 +03:00
|
|
|
return 500;
|
2023-06-14 22:30:52 +03:00
|
|
|
case "gpt-3.5-turbo-16k":
|
2023-07-01 18:22:28 +03:00
|
|
|
return 2000;
|
2023-06-14 22:30:52 +03:00
|
|
|
case "gpt-4":
|
2023-07-01 18:22:28 +03:00
|
|
|
return 1000;
|
2023-06-14 22:30:52 +03:00
|
|
|
case "gpt-4-0613":
|
2023-07-01 18:22:28 +03:00
|
|
|
return 100;
|
2023-06-14 22:30:52 +03:00
|
|
|
default:
|
2023-07-01 18:22:28 +03:00
|
|
|
return 250;
|
2023-06-14 22:30:52 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-06-12 14:15:03 +03:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="border-b border-gray-300 mt-8 mb-8">
|
|
|
|
<p className="text-center text-gray-600 uppercase tracking-wide font-semibold">
|
|
|
|
Model config
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<Field
|
|
|
|
type="password"
|
|
|
|
placeholder="Open AI Key"
|
|
|
|
className="w-full"
|
|
|
|
label="Open AI Key"
|
|
|
|
{...register("openAiKey")}
|
|
|
|
/>
|
|
|
|
<fieldset className="w-full flex flex-col">
|
|
|
|
<label className="flex-1 text-sm" htmlFor="model">
|
|
|
|
Model
|
|
|
|
</label>
|
|
|
|
<select
|
|
|
|
id="model"
|
|
|
|
{...register("model")}
|
|
|
|
className="px-5 py-2 dark:bg-gray-700 bg-gray-200 rounded-md"
|
|
|
|
>
|
|
|
|
{(openAiKey ? paidModels : models).map((model) => (
|
|
|
|
<option value={model} key={model}>
|
|
|
|
{model}
|
|
|
|
</option>
|
|
|
|
))}
|
|
|
|
</select>
|
|
|
|
</fieldset>
|
|
|
|
{(anthropicModels as readonly string[]).includes(model) && (
|
|
|
|
<Field
|
|
|
|
type="text"
|
|
|
|
placeholder="Anthropic API Key"
|
|
|
|
className="w-full"
|
|
|
|
label="Anthropic API Key"
|
|
|
|
{...register("anthropicKey")}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<fieldset className="w-full flex">
|
|
|
|
<label className="flex-1" htmlFor="temp">
|
|
|
|
Temperature: {temperature}
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
id="temp"
|
|
|
|
type="range"
|
|
|
|
min="0"
|
|
|
|
max="1"
|
|
|
|
step="0.01"
|
|
|
|
value={temperature}
|
|
|
|
{...register("temperature")}
|
|
|
|
/>
|
|
|
|
</fieldset>
|
|
|
|
<fieldset className="w-full flex">
|
|
|
|
<label className="flex-1" htmlFor="tokens">
|
|
|
|
Tokens: {maxTokens}
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
type="range"
|
|
|
|
min="256"
|
2023-06-14 22:30:52 +03:00
|
|
|
max={defineMaxTokens(model)}
|
|
|
|
step="32"
|
2023-06-12 14:15:03 +03:00
|
|
|
value={maxTokens}
|
|
|
|
{...register("maxTokens")}
|
|
|
|
/>
|
|
|
|
</fieldset>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|