Skip to content

Commit 0a07cf1

Browse files
committed
Removing replace rule (for now) and updating triple generation to gracefully fail when no chunks are associated
1 parent e0c2d84 commit 0a07cf1

File tree

6 files changed

+52
-26
lines changed

6 files changed

+52
-26
lines changed

backend/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
### Added
11+
12+
- Graceful failure of triple export when no chunks are found
13+
814
## [v0.1.5] - 2024-10-29
915

1016
### Changed

backend/src/app/api/v1/endpoints/graph.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,26 +106,38 @@ async def export_triples(
106106
columns_dict = {item.id: item for item in request.columns}
107107
for row in request.rows:
108108
for key, value in row.cells.items():
109-
converted_cells.append(
110-
TableCell(
111-
answer={
112-
"answer": value,
113-
"document_id": (
114-
row.sourceData.document.id
115-
if hasattr(row.sourceData, "document")
116-
and hasattr(row.sourceData.document, "id")
117-
else ""
118-
),
119-
"id": "",
120-
"prompt_id": "",
121-
"type": columns_dict[key].type,
122-
"chunks": request.chunks["-".join([row.id, key])],
123-
},
124-
columnId=key,
125-
dirty=False,
126-
rowId=row.id,
109+
# Skip if value is not a string or is "None" or "none"
110+
if not isinstance(value, str):
111+
continue
112+
113+
# Remove any surrounding quotes and whitespace before checking
114+
cleaned_value = value.strip().strip("\"'") if value else ""
115+
if cleaned_value and cleaned_value.lower() != "none":
116+
chunk_key = "-".join([row.id, key])
117+
chunks = request.chunks.get(
118+
chunk_key, []
119+
) # Use .get() with default empty list
120+
121+
converted_cells.append(
122+
TableCell(
123+
answer={
124+
"answer": value,
125+
"document_id": (
126+
row.sourceData.document.id
127+
if hasattr(row.sourceData, "document")
128+
and hasattr(row.sourceData.document, "id")
129+
else ""
130+
),
131+
"id": "",
132+
"prompt_id": "",
133+
"type": columns_dict[key].type,
134+
"chunks": chunks,
135+
},
136+
columnId=key,
137+
dirty=False,
138+
rowId=row.id,
139+
)
127140
)
128-
)
129141

130142
try:
131143
table = Table(

frontend/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
### Changed
11+
12+
- Removed replace rule as an option for now
13+
814
## [v0.1.5] - 2024-10-29
915

1016
### Added

frontend/src/components/kt/kt-controls/kt-global-rules.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ export function KTGlobalRules(props: BoxProps) {
125125
must_return,"red,blue,green",Color
126126
<br />
127127
max_length,3,
128-
<br />
129-
replace,"blue,ultramarine,sapphire",Color
128+
{/* <br />
129+
replace,"blue,ultramarine,sapphire",Color */}
130130
</Code>
131131
</Box>
132132
</Group>
@@ -247,7 +247,8 @@ export function KTGlobalRules(props: BoxProps) {
247247

248248
const csvJsonSchema = z.array(
249249
z.object({
250-
rule_type: z.enum(["must_return", "may_return", "max_length", "replace"]),
250+
// rule_type: z.enum(["must_return", "may_return", "max_length", "replace"]),
251+
rule_type: z.enum(["must_return", "may_return", "max_length"]),
251252
value: z.string(),
252253
entity_type: z.string().optional()
253254
})

frontend/src/config/store/store.types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ export interface AnswerTableGlobalRule extends AnswerTableRule {
9898
}
9999

100100
export interface AnswerTableRule {
101-
type: "must_return" | "may_return" | "max_length" | "replace";
101+
// type: "must_return" | "may_return" | "max_length" | "replace";
102+
type: "must_return" | "may_return" | "max_length";
102103
options?: string[];
103104
length?: number;
104105
}

frontend/src/config/store/store.utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const defaultRules: Record<AnswerTableRule["type"], AnswerTableRule> = {
8080
must_return: { type: "must_return", options: [] },
8181
may_return: { type: "may_return", options: [] },
8282
max_length: { type: "max_length", length: 1 },
83-
replace: { type: "replace", options: [] }
83+
// replace: { type: "replace", options: [] }
8484
};
8585

8686
export const ruleOptions: {
@@ -90,14 +90,14 @@ export const ruleOptions: {
9090
{ value: "must_return", label: "Must return" },
9191
{ value: "may_return", label: "May return" },
9292
{ value: "max_length", label: "Allowed # of responses" },
93-
{ value: "replace", label: "Replace" }
93+
// { value: "replace", label: "Replace" }
9494
];
9595

9696
export const ruleInfo: Record<AnswerTableRule["type"], string> = {
9797
must_return: "The column must return the specified values",
9898
may_return: "The column may return the specified values",
9999
max_length: "The column must return at most N values",
100-
replace: "Replace all specified values with the first one from the list"
100+
// replace: "Replace all specified values with the first one from the list"
101101
};
102102

103103
// Casting

0 commit comments

Comments
 (0)