|
24 | 24 | const usePromptOutput = () => {
|
25 | 25 | const { sessionDetails } = useSessionStore();
|
26 | 26 | const { setTokenUsage, updateTokenUsage } = useTokenUsageStore();
|
27 |
| - const { setPromptOutput, updatePromptOutput, promptOutputs } = |
28 |
| - usePromptOutputStore(); |
| 27 | + const { setPromptOutput, updatePromptOutput } = usePromptOutputStore(); |
29 | 28 | const { isSimplePromptStudio, isPublicSource, selectedDoc } =
|
30 | 29 | useCustomToolStore();
|
31 | 30 | const axiosPrivate = useAxiosPrivate();
|
@@ -154,32 +153,35 @@ const usePromptOutput = () => {
|
154 | 153 | setPromptOutput(outputs);
|
155 | 154 | setTokenUsage(tokenUsageDetails);
|
156 | 155 | } else {
|
157 |
| - let updatedPromptOutputs = promptOutputs; |
158 |
| - Object.keys(outputs).forEach((key) => { |
159 |
| - const [keyPromptId, keyDoctId, keyLlmProfile, keyIsSinglePass] = |
160 |
| - key.split("__"); |
161 |
| - // only add output of selected document |
162 |
| - if (keyDoctId === selectedDoc?.document_id) { |
163 |
| - const currentOutput = { [key]: outputs[key] }; |
164 |
| - updatedPromptOutputs = { ...promptOutputs, ...currentOutput }; |
165 |
| - } |
166 |
| - Object.keys(updatedPromptOutputs).forEach((innerKey) => { |
167 |
| - const [existingPromptId, , existingLlmProfile, existingIsSinglePass] = |
168 |
| - innerKey.split("__"); // Extract promptId from key |
169 |
| - if ( |
170 |
| - keyPromptId === existingPromptId && |
171 |
| - keyLlmProfile === existingLlmProfile && |
172 |
| - keyIsSinglePass === existingIsSinglePass |
173 |
| - ) { |
174 |
| - updatedPromptOutputs[innerKey].coverage = outputs[key]?.coverage; |
175 |
| - } |
176 |
| - }); |
177 |
| - }); |
178 |
| - updatePromptOutput(updatedPromptOutputs); |
| 156 | + const prevOutputs = usePromptOutputStore.getState().promptOutputs; |
| 157 | + updatePromptOutput(updateCoverage(prevOutputs, outputs)); |
179 | 158 | updateTokenUsage(tokenUsageDetails);
|
180 | 159 | }
|
181 | 160 | };
|
182 | 161 |
|
| 162 | + const updateCoverage = (promptOutputs, outputs) => { |
| 163 | + let updatedPromptOutputs = promptOutputs; |
| 164 | + Object.keys(outputs).forEach((key) => { |
| 165 | + const [keyPromptId, keyDoctId, , keyIsSinglePass] = key.split("__"); |
| 166 | + // only add output of selected document |
| 167 | + if (keyDoctId === selectedDoc?.document_id) { |
| 168 | + const currentOutput = { [key]: outputs[key] }; |
| 169 | + updatedPromptOutputs = { ...promptOutputs, ...currentOutput }; |
| 170 | + } |
| 171 | + Object.keys(updatedPromptOutputs).forEach((innerKey) => { |
| 172 | + const [existingPromptId, , , existingIsSinglePass] = |
| 173 | + innerKey.split("__"); // Extract promptId from key |
| 174 | + if ( |
| 175 | + keyPromptId === existingPromptId && |
| 176 | + keyIsSinglePass === existingIsSinglePass |
| 177 | + ) { |
| 178 | + updatedPromptOutputs[innerKey].coverage = outputs[key]?.coverage; |
| 179 | + } |
| 180 | + }); |
| 181 | + }); |
| 182 | + return updatedPromptOutputs; |
| 183 | + }; |
| 184 | + |
183 | 185 | const promptOutputApi = async (
|
184 | 186 | toolId,
|
185 | 187 | docId = null,
|
|
0 commit comments