feat: add interface params

This commit is contained in:
Swayam 2025-10-07 04:59:01 +05:30
parent 22de2f2045
commit b7c68277f6
4 changed files with 204 additions and 0 deletions

View file

@ -0,0 +1,40 @@
"""add litellm_params to searchspaces
Revision ID: fd3f2e543873
Revises: eb0c978da8fd
Create Date: 2025-10-07 04:11:50.392338
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = 'fd3f2e543873'
down_revision: Union[str, None] = 'eb0c978da8fd'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('chucks_search_index'), table_name='chunks', postgresql_using='gin')
op.drop_index(op.f('chucks_vector_index'), table_name='chunks', postgresql_using='hnsw')
op.drop_index(op.f('document_search_index'), table_name='documents', postgresql_using='gin')
op.drop_index(op.f('document_vector_index'), table_name='documents', postgresql_using='hnsw')
op.drop_column('searchspaces', 'inference_params')
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('searchspaces', sa.Column('inference_params', postgresql.JSON(astext_type=sa.Text()), autoincrement=False, nullable=True))
op.create_index(op.f('document_vector_index'), 'documents', ['embedding'], unique=False, postgresql_using='hnsw')
op.create_index(op.f('document_search_index'), 'documents', [sa.literal_column("to_tsvector('english'::regconfig, content)")], unique=False, postgresql_using='gin')
op.create_index(op.f('chucks_vector_index'), 'chunks', ['embedding'], unique=False, postgresql_using='hnsw')
op.create_index(op.f('chucks_search_index'), 'chunks', [sa.literal_column("to_tsvector('english'::regconfig, content)")], unique=False, postgresql_using='gin')
# ### end Alembic commands ###

View file

@ -0,0 +1,138 @@
"use client";
import { useState } from "react";
import { Plus, Trash2 } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
interface InferenceParamsEditorProps {
params: Record<string, number | string>;
setParams: (newParams: Record<string, number | string>) => void;
}
const PARAM_KEYS = ["temperature", "max_tokens", "top_k", "top_p"] as const;
export default function InferenceParamsEditor({
params,
setParams,
}: InferenceParamsEditorProps) {
const [selectedKey, setSelectedKey] = useState<string>("");
const [value, setValue] = useState<string>("");
const handleAdd = () => {
if (!selectedKey || value === "") return;
if (params[selectedKey]) {
alert(`${selectedKey} already exists`);
return;
}
const numericValue = Number(value);
if ((selectedKey === "temperature" || selectedKey === "top_p") && (isNaN(numericValue) || numericValue < 0 || numericValue > 1)) {
alert("Value must be a number between 0 and 1");
return;
}
if ((selectedKey === "max_tokens" || selectedKey === "top_k") && (!Number.isInteger(numericValue) || numericValue < 0)) {
alert("Value must be a non-negative integer");
return;
}
setParams({
...params,
[selectedKey]: isNaN(numericValue) ? value : numericValue,
});
setSelectedKey("");
setValue("");
};
const handleDelete = (key: string) => {
const newParams = { ...params };
delete newParams[key];
setParams(newParams);
};
return (
<div className="space-y-6 p-2 sm:p-0">
<div className="grid grid-cols-1 gap-4 md:grid-cols-[1fr_1fr_auto] md:gap-3 items-end">
<div className="flex flex-col space-y-1">
<Label htmlFor="param-key" className="text-sm font-medium">Parameter Key</Label>
<Select value={selectedKey} onValueChange={setSelectedKey}>
<SelectTrigger id="param-key" className="w-full">
<SelectValue placeholder="Select parameter" />
</SelectTrigger>
<SelectContent>
{PARAM_KEYS.map((key) => (
<SelectItem key={key} value={key}>{key}</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className="flex flex-col space-y-1">
<Label htmlFor="param-value" className="text-sm font-medium">Value</Label>
<Input
id="param-value"
placeholder="Enter value (e.g., 0.7 or 512)"
value={value}
onChange={(e) => setValue(e.target.value)}
className="w-full"
/>
</div>
<Button
className="w-full md:w-auto h-10 mt-0"
onClick={handleAdd}
disabled={!selectedKey || value === ""}
>
<Plus className="w-4 h-4 mr-2" /> Add Parameter
</Button>
</div>
<hr className="my-4" />
{Object.keys(params).length > 0 && (
<div className="border rounded-lg shadow-sm overflow-x-auto">
<table className="min-w-full text-left text-sm divide-y divide-gray-200">
<thead className="bg-black dark:bg-black">
<tr>
<th className="px-4 py-3 text-xs font-semibold uppercase tracking-wider text-gray-600 dark:text-gray-300">Key</th>
<th className="px-4 py-3 text-xs font-semibold uppercase tracking-wider text-gray-600 dark:text-gray-300">Value</th>
<th className="px-4 py-3 text-xs font-semibold uppercase tracking-wider text-gray-600 dark:text-gray-300 sr-only md:not-sr-only">Actions</th>
</tr>
</thead>
<tbody className="divide-y divide-gray-200 bg-black dark:bg-black">
{Object.entries(params).map(([key, val]) => (
<tr key={key} className="hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors">
<td className="px-4 py-3 font-medium text-gray-900 dark:text-white">{key}</td>
<td className="px-4 py-3 text-gray-700 dark:text-gray-300">{val.toString()}</td>
<td className="px-4 py-3">
<Button
variant="ghost"
size="icon"
className="text-red-600 hover:bg-red-50 dark:hover:bg-red-900/20 hover:text-red-700 dark:text-red-500"
onClick={() => handleDelete(key)}
aria-label={`Delete parameter ${key}`}
>
<Trash2 className="w-4 h-4" />
</Button>
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</div>
);
}

View file

@ -20,6 +20,8 @@ import {
import { LLM_PROVIDERS } from "@/contracts/enums/llm-providers";
import { type CreateLLMConfig, useLLMConfigs } from "@/hooks/use-llm-configs";
import InferenceParamsEditor from "../inference-params-editor";
interface AddProviderStepProps {
onConfigCreated?: () => void;
onConfigDeleted?: () => void;
@ -72,6 +74,10 @@ export function AddProviderStep({ onConfigCreated, onConfigDeleted }: AddProvide
const selectedProvider = LLM_PROVIDERS.find((p) => p.value === formData.provider);
const handleParamsChange = (newParams: Record<string, number | string>) => {
setFormData((prev) => ({ ...prev, litellm_params: newParams }));
};
return (
<div className="space-y-6">
{/* Info Alert */}
@ -239,6 +245,15 @@ export function AddProviderStep({ onConfigCreated, onConfigDeleted }: AddProvide
/>
</div>
{/* Optional Inference Parameters */}
<div className="pt-4">
<InferenceParamsEditor
params={formData.litellm_params || {}}
setParams={handleParamsChange}
/>
</div>
<div className="flex gap-2 pt-4">
<Button type="submit" disabled={isSubmitting}>
{isSubmitting ? "Adding..." : "Add Provider"}

View file

@ -39,6 +39,7 @@ import {
} from "@/components/ui/select";
import { LLM_PROVIDERS } from "@/contracts/enums/llm-providers";
import { type CreateLLMConfig, type LLMConfig, useLLMConfigs } from "@/hooks/use-llm-configs";
import InferenceParamsEditor from "../inference-params-editor";
export function ModelConfigManager() {
const {
@ -543,6 +544,16 @@ export function ModelConfigManager() {
/>
</div>
{/* Optional Inference Parameters */}
<div className="pt-4">
<InferenceParamsEditor
params={formData.litellm_params || {}}
setParams={(newParams) =>
setFormData((prev) => ({ ...prev, litellm_params: newParams }))
}
/>
</div>
<div className="flex gap-2 pt-4">
<Button type="submit" disabled={isSubmitting}>
{isSubmitting