mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-16 23:41:43 +00:00
fix(ui): trim and drop blank tags moved out of key metadata JSON
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
0201ca60e7
commit
52a3b0ede7
2 changed files with 12 additions and 4 deletions
|
|
@ -19,6 +19,14 @@ describe("moveTagsOutOfMetadataJson", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it("trims whitespace and drops blank entries the same way the Tags control does", () => {
|
||||
expect(moveTagsOutOfMetadataJson('{"tags": [" a ", "a", " ", "", " ui-tag"]}', ["ui-tag"])).toEqual({
|
||||
metadata: "{}",
|
||||
tags: ["ui-tag", "a"],
|
||||
movedTags: ["a"],
|
||||
});
|
||||
});
|
||||
|
||||
it("strips an empty tags array while moving nothing", () => {
|
||||
expect(moveTagsOutOfMetadataJson('{"tags": []}', undefined)).toEqual({
|
||||
metadata: "{}",
|
||||
|
|
|
|||
|
|
@ -60,10 +60,10 @@ export const moveTagsOutOfMetadataJson = (
|
|||
const { tags: metadataTags, ...rest } = parsed;
|
||||
if (!Array.isArray(metadataTags)) return null;
|
||||
const existing = currentTags ?? [];
|
||||
const movedTags = metadataTags.filter(
|
||||
(tag: unknown, index: number): tag is string =>
|
||||
typeof tag === "string" && !existing.includes(tag) && metadataTags.indexOf(tag) === index,
|
||||
);
|
||||
const movedTags = metadataTags
|
||||
.filter((tag: unknown): tag is string => typeof tag === "string")
|
||||
.map((tag) => tag.trim())
|
||||
.filter((tag, index, all) => tag.length > 0 && !existing.includes(tag) && all.indexOf(tag) === index);
|
||||
return { metadata: JSON.stringify(rest, null, 2), tags: [...existing, ...movedTags], movedTags };
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue