|
1 | 1 | import { z } from "zod"; |
2 | 2 |
|
| 3 | +import { getLogger } from "../common/logging.js"; |
3 | 4 | import { |
| 5 | + GuaranteedRequestFailureError, |
4 | 6 | requestGuaranteedJson, |
5 | 7 | RESPONSE_INTENT_CLASSIFIER_PROMPT_TEMPLATE, |
6 | 8 | } from "../guaranteed/index.js"; |
@@ -125,31 +127,54 @@ export class CompressionReviewer<S extends string> { |
125 | 127 | previousHistory, |
126 | 128 | ); |
127 | 129 |
|
128 | | - return await requestGuaranteedJson({ |
129 | | - messages, |
130 | | - parse: (data) => ({ |
131 | | - rawResponse: JSON.stringify(data), |
| 130 | + try { |
| 131 | + return await requestGuaranteedJson({ |
| 132 | + messages, |
| 133 | + parse: (data) => ({ |
| 134 | + rawResponse: JSON.stringify(data), |
| 135 | + review: { |
| 136 | + clueId: clueReviewer.clueId, |
| 137 | + issues: data.issues.map((issue) => ({ |
| 138 | + ...issue, |
| 139 | + severity: expectReviewSeverity(issue.severity), |
| 140 | + })), |
| 141 | + weight: clueReviewer.weight, |
| 142 | + }, |
| 143 | + }), |
| 144 | + responseIntentClassifierPrompt: this.#llm.loadSystemPrompt( |
| 145 | + RESPONSE_INTENT_CLASSIFIER_PROMPT_TEMPLATE, |
| 146 | + ), |
| 147 | + request: async (retryMessages, retryIndex, retryMax) => |
| 148 | + await this.#llm.request(retryMessages, { |
| 149 | + retryIndex, |
| 150 | + retryMax, |
| 151 | + scope: this.#reviewScope, |
| 152 | + useCache: false, |
| 153 | + }), |
| 154 | + schema: reviewResponseSchema, |
| 155 | + }); |
| 156 | + } catch (error) { |
| 157 | + if (!(error instanceof GuaranteedRequestFailureError)) { |
| 158 | + throw error; |
| 159 | + } |
| 160 | + |
| 161 | + getLogger({ |
| 162 | + clueId: clueReviewer.clueId, |
| 163 | + component: "editor-review", |
| 164 | + }).warn( |
| 165 | + { error }, |
| 166 | + "Compression reviewer failed to produce valid JSON; treating it as no issues.", |
| 167 | + ); |
| 168 | + |
| 169 | + return { |
| 170 | + rawResponse: undefined, |
132 | 171 | review: { |
133 | 172 | clueId: clueReviewer.clueId, |
134 | | - issues: data.issues.map((issue) => ({ |
135 | | - ...issue, |
136 | | - severity: expectReviewSeverity(issue.severity), |
137 | | - })), |
| 173 | + issues: [], |
138 | 174 | weight: clueReviewer.weight, |
139 | 175 | }, |
140 | | - }), |
141 | | - responseIntentClassifierPrompt: this.#llm.loadSystemPrompt( |
142 | | - RESPONSE_INTENT_CLASSIFIER_PROMPT_TEMPLATE, |
143 | | - ), |
144 | | - request: async (retryMessages, retryIndex, retryMax) => |
145 | | - await this.#llm.request(retryMessages, { |
146 | | - retryIndex, |
147 | | - retryMax, |
148 | | - scope: this.#reviewScope, |
149 | | - useCache: false, |
150 | | - }), |
151 | | - schema: reviewResponseSchema, |
152 | | - }); |
| 176 | + }; |
| 177 | + } |
153 | 178 | }), |
154 | 179 | ); |
155 | 180 | const rawResponses = Object.create(null) as Record< |
|
0 commit comments