Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/onyx/server/manage/llm/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_llm_configuration(
name=test_llm_request.name, db_session=db_session
)
# if an API key is not provided, use the existing provider's API key
if existing_provider and test_api_key is None:
if existing_provider and not test_llm_request.api_key_changed:
test_api_key = existing_provider.api_key

# For this "testing" workflow, we do *not* need the actual `max_input_tokens`.
Expand Down
5 changes: 4 additions & 1 deletion backend/onyx/server/manage/llm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ class TestLLMRequest(BaseModel):
fast_default_model_name: str | None = None
deployment_name: str | None = None

model_configurations: list["ModelConfigurationUpsertRequest"] = []
model_configurations: list["ModelConfigurationUpsertRequest"]

# if try and use the existing API key
api_key_changed: bool


class LLMProviderDescriptor(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from "@/components/admin/connectors/Field";
import { useState } from "react";
import { useSWRConfig } from "swr";
import { LLMProviderView } from "./interfaces";
import { LLMProviderView, ModelConfiguration } from "./interfaces";
import { PopupSpec } from "@/components/admin/connectors/Popup";
import * as Yup from "yup";
import isEqual from "lodash/isEqual";
Expand Down Expand Up @@ -69,17 +69,16 @@ export function CustomLLMProviderUpdateForm({
model_configurations: existingLlmProvider?.model_configurations.map(
(modelConfiguration) => ({
...modelConfiguration,
max_input_tokens:
modelConfiguration.max_input_tokens ??
("" as string | number | null | undefined),
max_input_tokens: modelConfiguration.max_input_tokens ?? null,
})
) ?? [{ name: "", is_visible: true, max_input_tokens: "" }],
) ?? [{ name: "", is_visible: true, max_input_tokens: null }],
custom_config_list: existingLlmProvider?.custom_config
? Object.entries(existingLlmProvider.custom_config)
: [],
is_public: existingLlmProvider?.is_public ?? true,
groups: existingLlmProvider?.groups ?? [],
deployment_name: existingLlmProvider?.deployment_name ?? null,
api_key_changed: false,
};

// Setup validation schema if required
Expand Down Expand Up @@ -114,15 +113,20 @@ export function CustomLLMProviderUpdateForm({
onSubmit={async (values, { setSubmitting }) => {
setSubmitting(true);

values.model_configurations.forEach((modelConfiguration) => {
if (
modelConfiguration.max_input_tokens === "" ||
modelConfiguration.max_input_tokens === null ||
modelConfiguration.max_input_tokens === undefined
) {
modelConfiguration.max_input_tokens = null;
}
});
// build final payload
const finalValues = { ...values };
finalValues.model_configurations = finalValues.model_configurations.map(
(modelConfiguration) => ({
...modelConfiguration,
max_input_tokens:
modelConfiguration.max_input_tokens === null ||
modelConfiguration.max_input_tokens === undefined
? null
: modelConfiguration.max_input_tokens,
supports_image_input: false, // doesn't matter, not used
})
);
finalValues.api_key_changed = values.api_key !== initialValues.api_key;

if (values.model_configurations.length === 0) {
const fullErrorMsg = "At least one model name is required";
Expand Down
20 changes: 10 additions & 10 deletions web/src/app/admin/configuration/llm/LLMProviderUpdateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function LLMProviderUpdateForm({
),
is_public: existingLlmProvider?.is_public ?? true,
groups: existingLlmProvider?.groups ?? [],
model_configurations: [] as ModelConfiguration[],
model_configurations: existingLlmProvider?.model_configurations ?? [],
deployment_name: existingLlmProvider?.deployment_name,
api_key_changed: false,

Expand Down Expand Up @@ -136,7 +136,6 @@ export function LLMProviderUpdateForm({
max_input_tokens: Yup.number().nullable().optional(),
})
),
api_key_changed: Yup.boolean(),
});

return (
Expand All @@ -146,19 +145,19 @@ export function LLMProviderUpdateForm({
onSubmit={async (values, { setSubmitting }) => {
setSubmitting(true);

values.api_key_changed = values.api_key !== initialValues.api_key;

// build final payload
const visibleModels = new Set(values.selected_model_names);
values.model_configurations = llmProviderDescriptor.llm_names.map(
const finalValues = { ...values };
finalValues.model_configurations = llmProviderDescriptor.llm_names.map(
(name) =>
({
name,
is_visible: visibleModels.has(name),
max_input_tokens: null,
}) as ModelConfiguration
);

delete values.selected_model_names;
delete finalValues.selected_model_names;
finalValues.api_key_changed = values.api_key !== initialValues.api_key;

// test the configuration
if (!isEqual(values, initialValues)) {
Expand All @@ -171,7 +170,7 @@ export function LLMProviderUpdateForm({
},
body: JSON.stringify({
provider: llmProviderDescriptor.name,
...values,
...finalValues,
}),
});
setIsTesting(false);
Expand All @@ -194,9 +193,10 @@ export function LLMProviderUpdateForm({
},
body: JSON.stringify({
provider: llmProviderDescriptor.name,
...values,
...finalValues,
fast_default_model_name:
values.fast_default_model_name || values.default_model_name,
finalValues.fast_default_model_name ||
finalValues.default_model_name,
}),
}
);
Expand Down
Loading