Skip to content

Commit

Permalink
[Fix] Singlepass coverage issue (#910)
Browse files Browse the repository at this point in the history
* fixes for prompt sudio coverage

* fixed prompt studio local variable issue

* updated return type

* added optional chaining

* added missing type

* added comment for error suppression

* handled edge cases

* added fix on run all prompt coverage issue

* added optional chaining
  • Loading branch information
jagadeeswaran-zipstack authored Dec 23, 2024
1 parent bd7ec42 commit c04ed2a
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions frontend/src/hooks/usePromptOutput.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ try {
const usePromptOutput = () => {
const { sessionDetails } = useSessionStore();
const { setTokenUsage, updateTokenUsage } = useTokenUsageStore();
const { setPromptOutput, updatePromptOutput } = usePromptOutputStore();
const { isSimplePromptStudio, isPublicSource } = useCustomToolStore();
const { setPromptOutput, updatePromptOutput, promptOutputs } =
usePromptOutputStore();
const { isSimplePromptStudio, isPublicSource, selectedDoc } =
useCustomToolStore();
const axiosPrivate = useAxiosPrivate();
const { id } = useParams();

Expand Down Expand Up @@ -152,7 +154,28 @@ const usePromptOutput = () => {
setPromptOutput(outputs);
setTokenUsage(tokenUsageDetails);
} else {
updatePromptOutput(outputs);
let updatedPromptOutputs = promptOutputs;
Object.keys(outputs).forEach((key) => {
const [keyPromptId, keyDoctId, keyLlmProfile, keyIsSinglePass] =
key.split("__");
// only add output of selected document
if (keyDoctId === selectedDoc?.document_id) {
const currentOutput = { [key]: outputs[key] };
updatedPromptOutputs = { ...promptOutputs, ...currentOutput };
}
Object.keys(updatedPromptOutputs).forEach((innerKey) => {
const [existingPromptId, , existingLlmProfile, existingIsSinglePass] =
innerKey.split("__"); // Extract promptId from key
if (
keyPromptId === existingPromptId &&
keyLlmProfile === existingLlmProfile &&
keyIsSinglePass === existingIsSinglePass
) {
updatedPromptOutputs[innerKey].coverage = outputs[key]?.coverage;
}
});
});
updatePromptOutput(updatedPromptOutputs);
updateTokenUsage(tokenUsageDetails);
}
};
Expand Down

0 comments on commit c04ed2a

Please sign in to comment.