Skip to content

Commit 146130b

Browse files
FEAT: Added "Run All Prompts" with Concurrent API Request Queuing Mechanism (Zipstack#749)
* Refactored the code to support concurrent prompt run API calls in the FE * Code quality improvement * Sonar Fix: Removed redundant jump * Optimization after load testing * Fixed sonar issues * Optimized and fixed sonar issues in usePromptRun custom hook * Fixed sonar issues * Disabled the feature to persist the prompt run details --------- Co-authored-by: Neha <115609453+nehabagdia@users.noreply.github.com>
1 parent e36941f commit 146130b

27 files changed

Lines changed: 850 additions & 819 deletions

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function DocumentManager({ generateIndex, handleUpdateTool, handleDocChange }) {
8888
const {
8989
selectedDoc,
9090
listOfDocs,
91-
disableLlmOrDocChange,
91+
isMultiPassExtractLoading,
9292
details,
9393
indexDocs,
9494
isSinglePassExtractLoading,
@@ -353,7 +353,7 @@ function DocumentManager({ generateIndex, handleUpdateTool, handleDocChange }) {
353353
size="small"
354354
disabled={
355355
!selectedDoc ||
356-
disableLlmOrDocChange?.length > 0 ||
356+
isMultiPassExtractLoading ||
357357
isSinglePassExtractLoading ||
358358
page <= 1
359359
}
@@ -366,7 +366,7 @@ function DocumentManager({ generateIndex, handleUpdateTool, handleDocChange }) {
366366
size="small"
367367
disabled={
368368
!selectedDoc ||
369-
disableLlmOrDocChange?.length > 0 ||
369+
isMultiPassExtractLoading ||
370370
isSinglePassExtractLoading ||
371371
page >= listOfDocs?.length
372372
}

‎frontend/src/components/custom-tools/editable-text/EditableText.jsx‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,13 @@ function EditableText({
1515
handleChange,
1616
isTextarea,
1717
placeHolder,
18+
isCoverageLoading,
1819
}) {
1920
const name = isTextarea ? "prompt" : "prompt_key";
2021
const [triggerHandleChange, setTriggerHandleChange] = useState(false);
2122
const [isHovered, setIsHovered] = useState(false);
2223
const divRef = useRef(null);
23-
const {
24-
disableLlmOrDocChange,
25-
indexDocs,
26-
selectedDoc,
27-
isSinglePassExtractLoading,
28-
isPublicSource,
29-
} = useCustomToolStore();
24+
const { isSinglePassExtractLoading, isPublicSource } = useCustomToolStore();
3025

3126
useEffect(() => {
3227
setText(defaultText);
@@ -91,9 +86,7 @@ function EditableText({
9186
onBlur={handleBlur}
9287
onClick={() => setIsEditing(true)}
9388
disabled={
94-
disableLlmOrDocChange.includes(promptId) ||
95-
isSinglePassExtractLoading ||
96-
isPublicSource
89+
isCoverageLoading || isSinglePassExtractLoading || isPublicSource
9790
}
9891
/>
9992
);
@@ -115,10 +108,7 @@ function EditableText({
115108
onBlur={handleBlur}
116109
onClick={() => setIsEditing(true)}
117110
disabled={
118-
disableLlmOrDocChange.includes(promptId) ||
119-
indexDocs.includes(selectedDoc?.document_id) ||
120-
isSinglePassExtractLoading ||
121-
isPublicSource
111+
isCoverageLoading || isSinglePassExtractLoading || isPublicSource
122112
}
123113
/>
124114
);
@@ -129,11 +119,12 @@ EditableText.propTypes = {
129119
setIsEditing: PropTypes.func.isRequired,
130120
text: PropTypes.string,
131121
setText: PropTypes.func.isRequired,
132-
promptId: PropTypes.string.isRequired,
133-
defaultText: PropTypes.string.isRequired,
122+
promptId: PropTypes.string,
123+
defaultText: PropTypes.string,
134124
handleChange: PropTypes.func.isRequired,
135125
isTextarea: PropTypes.bool,
136126
placeHolder: PropTypes.string,
127+
isCoverageLoading: PropTypes.bool.isRequired,
137128
};
138129

139130
export { EditableText };

‎frontend/src/components/custom-tools/manage-docs-modal/ManageDocsModal.jsx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function ManageDocsModal({
7979
updateCustomTool,
8080
details,
8181
defaultLlmProfile,
82-
disableLlmOrDocChange,
82+
isMultiPassExtractLoading,
8383
indexDocs,
8484
rawIndexStatus,
8585
summarizeIndexStatus,
@@ -392,7 +392,7 @@ function ManageDocsModal({
392392
icon={<ReloadOutlined />}
393393
onClick={() => handleReIndexBtnClick(item)}
394394
disabled={
395-
disableLlmOrDocChange?.length > 0 ||
395+
isMultiPassExtractLoading ||
396396
isSinglePassExtractLoading ||
397397
indexDocs.includes(item?.document_id) ||
398398
isUploading ||
@@ -418,7 +418,7 @@ function ManageDocsModal({
418418
size="small"
419419
className="display-flex-align-center"
420420
disabled={
421-
disableLlmOrDocChange?.length > 0 ||
421+
isMultiPassExtractLoading ||
422422
isSinglePassExtractLoading ||
423423
indexDocs.includes(item?.document_id) ||
424424
isUploading ||
@@ -435,7 +435,7 @@ function ManageDocsModal({
435435
checked={selectedDoc?.document_id === item?.document_id}
436436
onClick={() => handleDocChange(item)}
437437
disabled={
438-
disableLlmOrDocChange?.length > 0 ||
438+
isMultiPassExtractLoading ||
439439
isSinglePassExtractLoading ||
440440
indexDocs.includes(item?.document_id)
441441
}
@@ -447,7 +447,7 @@ function ManageDocsModal({
447447
}, [
448448
listOfDocs,
449449
selectedDoc,
450-
disableLlmOrDocChange,
450+
isMultiPassExtractLoading,
451451
rawIndexStatus,
452452
summarizeIndexStatus,
453453
indexDocs,
@@ -602,7 +602,7 @@ function ManageDocsModal({
602602
loading={isUploading}
603603
disabled={
604604
!defaultLlmProfile ||
605-
disableLlmOrDocChange?.length > 0 ||
605+
isMultiPassExtractLoading ||
606606
isSinglePassExtractLoading ||
607607
isPublicSource
608608
}

‎frontend/src/components/custom-tools/output-for-doc-modal/OutputForDocModal.jsx‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function OutputForDocModal({
5050
promptId,
5151
promptKey,
5252
profileManagerId,
53-
docOutputs,
53+
docOutputs = [],
5454
}) {
5555
const [promptOutputs, setPromptOutputs] = useState([]);
5656
const [rows, setRows] = useState([]);
@@ -60,7 +60,7 @@ function OutputForDocModal({
6060
details,
6161
listOfDocs,
6262
selectedDoc,
63-
disableLlmOrDocChange,
63+
isMultiPassExtractLoading,
6464
singlePassExtractMode,
6565
isSinglePassExtractLoading,
6666
isPublicSource,
@@ -89,10 +89,6 @@ function OutputForDocModal({
8989
isSinglePassExtractLoading,
9090
]);
9191

92-
useEffect(() => {
93-
updatePromptOutput(docOutputs);
94-
}, [docOutputs]);
95-
9692
useEffect(() => {
9793
handleRowsGeneration(promptOutputs);
9894
}, [promptOutputs, tokenUsage]);
@@ -360,9 +356,7 @@ function OutputForDocModal({
360356
<Button
361357
size="small"
362358
onClick={() => navigate("outputAnalyzer")}
363-
disabled={
364-
disableLlmOrDocChange?.length > 0 || isSinglePassExtractLoading
365-
}
359+
disabled={isMultiPassExtractLoading || isSinglePassExtractLoading}
366360
>
367361
View in Output Analyzer
368362
</Button>
@@ -391,8 +385,8 @@ function OutputForDocModal({
391385
OutputForDocModal.propTypes = {
392386
open: PropTypes.bool.isRequired,
393387
setOpen: PropTypes.func.isRequired,
394-
promptId: PropTypes.string.isRequired,
395-
promptKey: PropTypes.string.isRequired,
388+
promptId: PropTypes.string,
389+
promptKey: PropTypes.string,
396390
profileManagerId: PropTypes.string,
397391
docOutputs: PropTypes.object,
398392
};

‎frontend/src/components/custom-tools/prompt-card/DisplayPromptResult.jsx‎

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,41 @@
1-
import { Typography } from "antd";
1+
import { Spin, Typography } from "antd";
22
import PropTypes from "prop-types";
33
import { InfoCircleFilled } from "@ant-design/icons";
44

5-
import { displayPromptResult } from "../../../helpers/GetStaticData";
5+
import {
6+
displayPromptResult,
7+
generateApiRunStatusId,
8+
PROMPT_RUN_API_STATUSES,
9+
} from "../../../helpers/GetStaticData";
610
import "./PromptCard.css";
11+
import { useCustomToolStore } from "../../../store/custom-tool-store";
12+
import { useEffect, useState } from "react";
13+
import { SpinnerLoader } from "../../widgets/spinner-loader/SpinnerLoader";
14+
15+
function DisplayPromptResult({ output, profileId, docId, promptRunStatus }) {
16+
const [isLoading, setIsLoading] = useState(false);
17+
const { singlePassExtractMode, isSinglePassExtractLoading } =
18+
useCustomToolStore();
19+
20+
useEffect(() => {
21+
if (singlePassExtractMode && isSinglePassExtractLoading) {
22+
setIsLoading(true);
23+
return;
24+
}
25+
26+
const key = generateApiRunStatusId(docId, profileId);
27+
if (promptRunStatus?.[key] === PROMPT_RUN_API_STATUSES.RUNNING) {
28+
setIsLoading(true);
29+
return;
30+
}
31+
32+
setIsLoading(false);
33+
}, [promptRunStatus, isSinglePassExtractLoading]);
34+
35+
if (isLoading) {
36+
return <Spin indicator={<SpinnerLoader size="small" />} />;
37+
}
738

8-
function DisplayPromptResult({ output }) {
939
if (output === undefined) {
1040
return (
1141
<Typography.Text className="prompt-not-ran">
@@ -25,7 +55,10 @@ function DisplayPromptResult({ output }) {
2555
}
2656

2757
DisplayPromptResult.propTypes = {
28-
output: PropTypes.any.isRequired,
58+
output: PropTypes.any,
59+
profileId: PropTypes.string,
60+
docId: PropTypes.string,
61+
promptRunStatus: PropTypes.object,
2962
};
3063

3164
export { DisplayPromptResult };

‎frontend/src/components/custom-tools/prompt-card/Header.jsx‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import { useEffect, useState } from "react";
1111
import { Button, Checkbox, Col, Dropdown, Row, Tag, Tooltip } from "antd";
1212
import PropTypes from "prop-types";
1313

14-
import { promptStudioUpdateStatus } from "../../../helpers/GetStaticData";
14+
import {
15+
PROMPT_RUN_TYPES,
16+
promptStudioUpdateStatus,
17+
} from "../../../helpers/GetStaticData";
1518
import { ConfirmModal } from "../../widgets/confirm-modal/ConfirmModal";
1619
import { EditableText } from "../editable-text/EditableText";
1720
import { useCustomToolStore } from "../../../store/custom-tool-store";
@@ -40,13 +43,11 @@ function Header({
4043
setIsEditingTitle,
4144
expandCard,
4245
setExpandCard,
43-
enabledProfiles,
4446
spsLoading,
4547
handleSpsLoading,
4648
}) {
4749
const {
4850
selectedDoc,
49-
disableLlmOrDocChange,
5051
singlePassExtractMode,
5152
isSinglePassExtractLoading,
5253
indexDocs,
@@ -58,9 +59,9 @@ function Header({
5859

5960
const [isDisablePrompt, setIsDisablePrompt] = useState(null);
6061

61-
const handleRunBtnClick = (profileManager = null, coverAllDoc = true) => {
62+
const handleRunBtnClick = (promptRunType, docId = null) => {
6263
setExpandCard(true);
63-
handleRun(profileManager, coverAllDoc, enabledProfiles, true);
64+
handleRun(promptRunType, promptDetails?.prompt_id, null, docId);
6465
};
6566

6667
const handleDisablePrompt = (event) => {
@@ -97,7 +98,7 @@ function Header({
9798
),
9899
key: "delete",
99100
disabled:
100-
disableLlmOrDocChange?.includes(promptDetails?.prompt_id) ||
101+
isCoverageLoading ||
101102
isSinglePassExtractLoading ||
102103
indexDocs?.includes(selectedDoc?.document_id) ||
103104
isPublicSource,
@@ -122,6 +123,7 @@ function Header({
122123
defaultText={promptDetails?.prompt_key}
123124
handleChange={handleChange}
124125
placeHolder={updatePlaceHolder}
126+
isCoverageLoading={isCoverageLoading}
125127
/>
126128
</Col>
127129
<Col span={12} className="display-flex-right">
@@ -186,13 +188,16 @@ function Header({
186188
type="text"
187189
className="prompt-card-action-button"
188190
onClick={() =>
189-
handleRunBtnClick(promptDetails?.profile_manager, false)
191+
handleRunBtnClick(
192+
PROMPT_RUN_TYPES.RUN_ONE_PROMPT_ALL_LLMS_ONE_DOC,
193+
selectedDoc?.document_id
194+
)
190195
}
191196
disabled={
192197
(updateStatus?.promptId === promptDetails?.prompt_id &&
193198
updateStatus?.status ===
194199
promptStudioUpdateStatus?.isUpdating) ||
195-
disableLlmOrDocChange?.includes(promptDetails?.prompt_id) ||
200+
isCoverageLoading ||
196201
indexDocs?.includes(selectedDoc?.document_id) ||
197202
isPublicSource ||
198203
spsLoading[selectedDoc?.document_id]
@@ -206,12 +211,16 @@ function Header({
206211
size="small"
207212
type="text"
208213
className="prompt-card-action-button"
209-
onClick={handleRunBtnClick}
214+
onClick={() =>
215+
handleRunBtnClick(
216+
PROMPT_RUN_TYPES.RUN_ONE_PROMPT_ALL_LLMS_ALL_DOCS
217+
)
218+
}
210219
disabled={
211220
(updateStatus?.promptId === promptDetails?.prompt_id &&
212221
updateStatus?.status ===
213222
promptStudioUpdateStatus?.isUpdating) ||
214-
disableLlmOrDocChange?.includes(promptDetails?.prompt_id) ||
223+
isCoverageLoading ||
215224
indexDocs?.includes(selectedDoc?.document_id) ||
216225
isPublicSource
217226
}
@@ -259,7 +268,6 @@ Header.propTypes = {
259268
setIsEditingTitle: PropTypes.func.isRequired,
260269
expandCard: PropTypes.bool.isRequired,
261270
setExpandCard: PropTypes.func.isRequired,
262-
enabledProfiles: PropTypes.array.isRequired,
263271
spsLoading: PropTypes.object,
264272
handleSpsLoading: PropTypes.func.isRequired,
265273
};

0 commit comments

Comments
 (0)