Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(playground): update tools and schemas if name already exists (#7039)

Hassieb Pakzad945d13dac02c
diff --git a/web/src/ee/features/playground/page/components/CreateOrEditLLMSchemaDialog.tsx b/web/src/ee/features/playground/page/components/CreateOrEditLLMSchemaDialog.tsx
index 01249e43bf..2e3c2eaf44 100644
--- a/web/src/ee/features/playground/page/components/CreateOrEditLLMSchemaDialog.tsx
+++ b/web/src/ee/features/playground/page/components/CreateOrEditLLMSchemaDialog.tsx
@@ -84,14 +84,14 @@ export const CreateOrEditLLMSchemaDialog: React.FC<
// Populate form when in edit mode
useEffect(() => {
- if (existingLlmSchema) {
+ if (existingLlmSchema && !props.defaultValues) {
form.reset({
name: existingLlmSchema.name,
description: existingLlmSchema.description,
schema: JSON.stringify(existingLlmSchema.schema, null, 2),
});
}
- }, [existingLlmSchema, form]);
+ }, [existingLlmSchema, form, props.defaultValues]);
async function onSubmit(values: FormValues) {
let result;
diff --git a/web/src/ee/features/playground/page/components/CreateOrEditLLMToolDialog.tsx b/web/src/ee/features/playground/page/components/CreateOrEditLLMToolDialog.tsx
index 84ccd63af5..8f5104a50b 100644
--- a/web/src/ee/features/playground/page/components/CreateOrEditLLMToolDialog.tsx
+++ b/web/src/ee/features/playground/page/components/CreateOrEditLLMToolDialog.tsx
@@ -84,14 +84,14 @@ export const CreateOrEditLLMToolDialog: React.FC<CreateOrEditLLMToolDialog> = (
// Populate form when in edit mode
useEffect(() => {
- if (existingLlmTool) {
+ if (existingLlmTool && !props.defaultValues) {
form.reset({
name: existingLlmTool.name,
description: existingLlmTool.description,
parameters: JSON.stringify(existingLlmTool.parameters, null, 2),
});
}
- }, [existingLlmTool, form]);
+ }, [existingLlmTool, form, props.defaultValues]);
async function onSubmit(values: FormValues) {
let result;
diff --git a/web/src/ee/features/playground/page/components/JumpToPlaygroundButton.tsx b/web/src/ee/features/playground/page/components/JumpToPlaygroundButton.tsx
index ff85d10d5c..bbfd99ba3c 100644
--- a/web/src/ee/features/playground/page/components/JumpToPlaygroundButton.tsx
+++ b/web/src/ee/features/playground/page/components/JumpToPlaygroundButton.tsx
@@ -431,7 +431,13 @@ function parseStructuredOutputSchema(
},
): PlaygroundSchema | null {
try {
- const metadata = generation.metadata;
+ let metadata = generation.metadata;
+
+ try {
+ if (typeof metadata === "string") {
+ metadata = JSON.parse(metadata);
+ }
+ } catch {}
if (
typeof metadata === "object" &&
diff --git a/web/src/ee/features/playground/page/components/PlaygroundTools/index.tsx b/web/src/ee/features/playground/page/components/PlaygroundTools/index.tsx
index d063a128da..f9f4568651 100644
--- a/web/src/ee/features/playground/page/components/PlaygroundTools/index.tsx
+++ b/web/src/ee/features/playground/page/components/PlaygroundTools/index.tsx
@@ -42,7 +42,13 @@ export const PlaygroundTools = () => {
const isToolSaved = useCallback(
(tool: PlaygroundTool) => {
- return savedTools.some((savedTool) => savedTool.id === tool.id);
+ return savedTools.some(
+ (savedTool) =>
+ savedTool.id === tool.id &&
+ savedTool.description === tool.description &&
+ JSON.stringify(savedTool.parameters) ===
+ JSON.stringify(tool.parameters),
+ );
},
[savedTools],
);
@@ -51,11 +57,7 @@ export const PlaygroundTools = () => {
tools.forEach((tool, index) => {
if (!tool.existingLlmTool) {
const matchingSavedTool = savedTools.find(
- (savedTool) =>
- savedTool.name === tool.name &&
- savedTool.description === tool.description &&
- JSON.stringify(savedTool.parameters) ===
- JSON.stringify(tool.parameters),
+ (savedTool) => savedTool.name === tool.name,
);
if (matchingSavedTool) {
diff --git a/web/src/ee/features/playground/page/components/StructuredOutputSchemaSection.tsx b/web/src/ee/features/playground/page/components/StructuredOutputSchemaSection.tsx
index df4cae4ac2..6f1b0281b5 100644
--- a/web/src/ee/features/playground/page/components/StructuredOutputSchemaSection.tsx
+++ b/web/src/ee/features/playground/page/components/StructuredOutputSchemaSection.tsx
@@ -42,7 +42,12 @@ export const StructuredOutputSchemaSection = () => {
const isSchemaSaved = useCallback(
(schema: PlaygroundSchema) => {
- return savedSchemas.some((savedSchema) => savedSchema.id === schema.id);
+ return savedSchemas.some(
+ (savedSchema) =>
+ savedSchema.id === schema.id &&
+ savedSchema.description === schema.description &&
+ JSON.stringify(savedSchema.schema) === JSON.stringify(schema.schema),
+ );
},
[savedSchemas],
);
@@ -50,11 +55,7 @@ export const StructuredOutputSchemaSection = () => {
useEffect(() => {
if (structuredOutputSchema && !structuredOutputSchema.existingLlmSchema) {
const matchingSavedSchema = savedSchemas.find(
- (savedSchema) =>
- savedSchema.name === structuredOutputSchema.name &&
- savedSchema.description === structuredOutputSchema.description &&
- JSON.stringify(savedSchema.schema) ===
- JSON.stringify(structuredOutputSchema.schema),
+ (savedSchema) => savedSchema.name === structuredOutputSchema.name,
);
if (matchingSavedSchema) {