mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-09 22:31:41 +00:00
Properly parse json options for key generation in the UI (#12989)
This commit is contained in:
parent
9459d72096
commit
47f6984dce
2 changed files with 26 additions and 19 deletions
|
|
@ -33,9 +33,12 @@ interface SchemaFormFieldsProps {
|
|||
defaultValues?: { [key: string]: any };
|
||||
}
|
||||
|
||||
// Define which fields should be parsed as JSON
|
||||
export const jsonFields = ['metadata', 'config', 'enforced_params', 'aliases'];
|
||||
|
||||
|
||||
// Helper function to determine if a field should be treated as JSON
|
||||
const isJSONField = (key: string, property: SchemaProperty): boolean => {
|
||||
const jsonFields = ['metadata', 'config', 'enforced_params', 'aliases'];
|
||||
return jsonFields.includes(key) || property.format === 'json';
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import {
|
|||
EmailEventSettingsResponse,
|
||||
EmailEventSettingsUpdateRequest,
|
||||
} from "./email_events/types";
|
||||
import { jsonFields } from "./common_components/check_openapi_schema"
|
||||
|
||||
const isLocal = process.env.NODE_ENV === "development";
|
||||
export const defaultProxyBaseUrl = isLocal ? "http://localhost:4000" : null;
|
||||
|
|
@ -573,14 +574,16 @@ export const keyCreateServiceAccountCall = async (
|
|||
delete formValues.description;
|
||||
formValues.metadata = JSON.stringify(formValues.metadata);
|
||||
}
|
||||
// if formValues.metadata is not undefined, make it a valid dict
|
||||
if (formValues.metadata) {
|
||||
console.log("formValues.metadata:", formValues.metadata);
|
||||
// if there's an exception JSON.parse, show it in the message
|
||||
try {
|
||||
formValues.metadata = JSON.parse(formValues.metadata);
|
||||
} catch (error) {
|
||||
throw new Error("Failed to parse metadata: " + error);
|
||||
// Parse JSON fields if they exist
|
||||
for (const field of jsonFields) {
|
||||
if (formValues[field]) {
|
||||
console.log(`formValues.${field}:`, formValues[field]);
|
||||
// if there's an exception JSON.parse, show it in the message
|
||||
try {
|
||||
formValues[field] = JSON.parse(formValues[field]);
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to parse ${field}: ` + error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -624,7 +627,7 @@ export const keyCreateCall = async (
|
|||
|
||||
// check if formValues.description is not undefined, make it a string and add it to formValues.metadata
|
||||
if (formValues.description) {
|
||||
// add to formValues.metadata
|
||||
// add to formValues.metadat
|
||||
if (!formValues.metadata) {
|
||||
formValues.metadata = {};
|
||||
}
|
||||
|
|
@ -634,14 +637,16 @@ export const keyCreateCall = async (
|
|||
delete formValues.description;
|
||||
formValues.metadata = JSON.stringify(formValues.metadata);
|
||||
}
|
||||
// if formValues.metadata is not undefined, make it a valid dict
|
||||
if (formValues.metadata) {
|
||||
console.log("formValues.metadata:", formValues.metadata);
|
||||
// if there's an exception JSON.parse, show it in the message
|
||||
try {
|
||||
formValues.metadata = JSON.parse(formValues.metadata);
|
||||
} catch (error) {
|
||||
throw new Error("Failed to parse metadata: " + error);
|
||||
// Parse JSON fields if they exist
|
||||
for (const field of jsonFields) {
|
||||
if (formValues[field]) {
|
||||
console.log(`formValues.${field}:`, formValues[field]);
|
||||
// if there's an exception JSON.parse, show it in the message
|
||||
try {
|
||||
formValues[field] = JSON.parse(formValues[field]);
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to parse ${field}: ` + error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -6431,4 +6436,3 @@ export const vectorStoreSearchCall = async (
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue