Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Singlepass coverage issue #910

Merged
merged 12 commits into from
Dec 23, 2024
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
Loading