Skip to content

Commit 8d19e7a

Browse files
Merge branch 'main' of github.com:Zipstack/unstract into UN-2301-ETL-Error-is-not-captured-and-added-in-logs-if-a-connector-stopped-working-suddenly
2 parents 849804f + dde2c9e commit 8d19e7a

File tree

21 files changed

+2096
-1828
lines changed

21 files changed

+2096
-1828
lines changed

backend/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dependencies = [
3535
"python-socketio==5.9.0", # For log_events
3636
"social-auth-app-django==5.3.0", # For OAuth
3737
"social-auth-core==4.4.2", # For OAuth
38-
"unstract-sdk[aws,gcs,azure]~=0.78.0",
38+
"unstract-sdk[aws,gcs,azure]~=0.79.0",
3939
"azure-identity==1.16.0",
4040
"azure-mgmt-apimanagement==3.0.0",
4141
"croniter>=3.0.3",

backend/uv.lock

Lines changed: 11 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker/scripts/uv-lock-gen/uv-lock.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ directories=(
5959
"unstract/core"
6060
"unstract/flags"
6161
"unstract/connectors"
62+
"workers"
6263
)
6364

6465
# If directories are passed as arguments, override the default

frontend/src/components/custom-tools/document-manager/DocumentManager.jsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,25 @@ function DocumentManager({ generateIndex, handleUpdateTool, handleDocChange }) {
374374
<div>
375375
<Tag color="rgb(45, 183, 245)">
376376
Confidence Score:{" "}
377-
{selectedHighlight?.confidence?.[0]?.[0]?.confidence ||
378-
(Array.isArray(selectedHighlight?.confidence?.[0]) &&
379-
selectedHighlight?.confidence?.[0]?.length === 0 &&
380-
"1") ||
381-
"NA"}
377+
{(() => {
378+
const { confidence } = selectedHighlight || {};
379+
// Handle new format: confidence is a number (average)
380+
if (typeof confidence === "number") {
381+
return confidence.toFixed(2);
382+
}
383+
// Handle old format: nested array structure
384+
if (confidence?.[0]?.[0]?.confidence) {
385+
return confidence[0][0].confidence;
386+
}
387+
// Handle old format: empty array means confidence = 1
388+
if (
389+
Array.isArray(confidence?.[0]) &&
390+
confidence[0].length === 0
391+
) {
392+
return "1";
393+
}
394+
return "NA";
395+
})()}
382396
</Tag>
383397
</div>
384398
)}

frontend/src/components/custom-tools/pdf-viewer/PdfViewer.jsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@ function PdfViewer({ fileUrl, highlightData, currentHighlightIndex }) {
2323

2424
function removeZerosAndDeleteIfAllZero(highlightData) {
2525
if (Array.isArray(highlightData))
26-
return highlightData?.filter((innerArray) => {
27-
return (
28-
Array.isArray(innerArray) && innerArray?.some((value) => value !== 0)
29-
);
30-
});
26+
return highlightData
27+
?.filter((innerArray) => {
28+
if (!Array.isArray(innerArray)) return false;
29+
// Strip 5th element (confidence) if present, keep only first 4 elements
30+
const coordsOnly =
31+
innerArray.length >= 5 ? innerArray.slice(0, 4) : innerArray;
32+
return coordsOnly.some((value) => value !== 0);
33+
})
34+
.map((innerArray) => {
35+
// Return only the first 4 elements (strip confidence)
36+
return innerArray.length >= 5 ? innerArray.slice(0, 4) : innerArray;
37+
});
3138
}
3239

3340
const processHighlightData = highlightData

frontend/src/components/custom-tools/prompt-card/PromptCard.jsx

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ const PromptCard = memo(
171171

172172
const addCoordsToFlattened = (coords, flattened) => {
173173
if (Array.isArray(coords)) {
174-
flattened.push(coords);
174+
// Strip 5th element (confidence) if present, keep only first 4 elements
175+
const coordsOnly = coords.length >= 5 ? coords.slice(0, 4) : coords;
176+
flattened.push(coordsOnly);
175177
}
176178
};
177179

@@ -211,6 +213,47 @@ const PromptCard = memo(
211213
return flattened;
212214
};
213215

216+
const extractConfidenceFromHighlightData = (data) => {
217+
if (!data) return null;
218+
219+
const confidenceValues = [];
220+
221+
const extractFromArray = (arr) => {
222+
if (Array.isArray(arr)) {
223+
for (const item of arr) {
224+
if (Array.isArray(item)) {
225+
// Check if this is a coordinate array with 5 elements
226+
if (item.length >= 5 && typeof item[4] === "number") {
227+
confidenceValues.push(item[4]);
228+
} else {
229+
// Recursively check nested arrays
230+
extractFromArray(item);
231+
}
232+
} else if (typeof item === "object" && item !== null) {
233+
// Recursively check objects
234+
for (const val of Object.values(item)) {
235+
extractFromArray(val);
236+
}
237+
}
238+
}
239+
} else if (typeof arr === "object" && arr !== null) {
240+
for (const val of Object.values(arr)) {
241+
extractFromArray(val);
242+
}
243+
}
244+
};
245+
246+
extractFromArray(data);
247+
248+
// Calculate average confidence if we found any values
249+
if (confidenceValues.length > 0) {
250+
const sum = confidenceValues.reduce((acc, val) => acc + val, 0);
251+
return sum / confidenceValues.length;
252+
}
253+
254+
return null;
255+
};
256+
214257
const handleSelectHighlight = (
215258
highlightData,
216259
highlightedPrompt,
@@ -224,12 +267,18 @@ const PromptCard = memo(
224267
!Array.isArray(highlightData)
225268
? flattenHighlightData(highlightData)
226269
: highlightData;
270+
271+
// Try to extract confidence from 5th element first, fall back to API confidenceData
272+
const extractedConfidence =
273+
extractConfidenceFromHighlightData(highlightData);
274+
const finalConfidence = extractedConfidence ?? confidenceData;
275+
227276
updateCustomTool({
228277
selectedHighlight: {
229278
highlight: processedHighlight,
230279
highlightedPrompt: highlightedPrompt,
231280
highlightedProfile: highlightedProfile,
232-
confidence: confidenceData,
281+
confidence: finalConfidence,
233282
},
234283
});
235284
}

platform-service/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies = [
1515
"redis~=5.2.1",
1616
"cryptography>=41.0.7",
1717
"requests>=2.31.0",
18-
"unstract-sdk[gcs, azure, aws]~=0.78.0", # Add version
18+
"unstract-sdk[gcs, azure, aws]~=0.79.0", # Add version
1919
"unstract-flags",
2020
"unstract-core[flask]",
2121
"unstract-sdk1[gcs, azure, aws]"

platform-service/uv.lock

Lines changed: 9 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prompt-service/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies = [
1515
"python-dotenv==1.0.1",
1616
"json-repair~=0.42.0",
1717
"requests>=2.28,<3.0",
18-
"unstract-sdk[aws,gcs,azure]~=0.78.0",
18+
"unstract-sdk[aws,gcs,azure]~=0.79.0",
1919
"redis>=5.0.3,<5.3",
2020
"unstract-core",
2121
"unstract-flags",

0 commit comments

Comments
 (0)