Skip to content

Commit

Permalink
fix: improve logic for detecting ChatFields (#5667)
Browse files Browse the repository at this point in the history
Check the role and content properties to validate the chat field

---------

Co-authored-by: Francisco Aranda <[email protected]>
  • Loading branch information
leiyre and frascuchon committed Nov 8, 2024
1 parent 335791a commit 37807b5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
33 changes: 33 additions & 0 deletions argilla-frontend/v1/domain/entities/hub/DatasetCreation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const datasetInfo = {
dtype: "string",
_type: "Value",
},
extra: {
dtype: "int32",
_type: "Value",
},
},
],
metadata: {
Expand Down Expand Up @@ -160,6 +164,35 @@ describe("DatasetCreation", () => {
expect(chatField.required).toBeFalsy();
});

it("skip other list feature from chat fields", () => {
const builder = new DatasetCreationBuilder("FAKE", {
default: {
...datasetInfo.default,
features: {
some_list_feature: [
{
other: {
dtype: "string",
_type: "Value",
},
value: {
dtype: "string",
_type: "Value",
},
},
],
},
},
});

const datasetCreation = builder.build();

expect(
datasetCreation.fields.filter((f) => f.type.value === "no mapping")
.length
).toBe(1);
});

it("get no mapped feature", () => {
const builder = new DatasetCreationBuilder("FAKE", {
default: {
Expand Down
13 changes: 11 additions & 2 deletions argilla-frontend/v1/domain/entities/hub/Subset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { QuestionCreation } from "./QuestionCreation";
type Structure = {
name: string;
options?: string[];
role?: string;
content?: string;
structure?: Structure[];
kindObject?: "Value" | "Image" | "ClassLabel" | "Sequence";
type?: "string" | MetadataTypes;
Expand All @@ -33,6 +35,7 @@ export class Subset {

for (const [name, value] of Object.entries<Feature>(datasetInfo.features)) {
if (Array.isArray(value)) {
const { role, content } = value[0];
this.structures.push({
name,
structure: value.map((v) => {
Expand All @@ -42,6 +45,8 @@ export class Subset {
name: key,
kindObject: value._type,
type: value.dtype,
role,
content,
};
}),
});
Expand Down Expand Up @@ -134,8 +139,12 @@ export class Subset {
return "text";

if (structure.kindObject === "Image") return "image";

if (structure.structure?.length > 0) return "chat";
if (
structure.structure?.length > 0 &&
structure.structure[0].content &&
structure.structure[0].role
)
return "chat";
};

const field = FieldCreation.from(
Expand Down

0 comments on commit 37807b5

Please sign in to comment.