@mate-academy/llm-gateway 8.11.0 → 8.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,7 +4,7 @@ exports.validateStructuredResponse = validateStructuredResponse;
|
|
|
4
4
|
function validateStructuredResponse(options) {
|
|
5
5
|
const { content, schema, usage } = options;
|
|
6
6
|
try {
|
|
7
|
-
const validation = schema._parse(
|
|
7
|
+
const validation = schema._parse(parseJsonContent(content));
|
|
8
8
|
if (validation.error) {
|
|
9
9
|
return { text: content, parseError: validation.error, usage };
|
|
10
10
|
}
|
|
@@ -18,4 +18,35 @@ function validateStructuredResponse(options) {
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* DELETE ME, together with `unwrapMarkdownFence` and their tests, once no
|
|
23
|
+
* prompt sends an LLMAPI structured call to an Anthropic-backed model.
|
|
24
|
+
*
|
|
25
|
+
* LLMAPI forwards OpenAI's `response_format`, but Anthropic has no such
|
|
26
|
+
* parameter — its own is `output_config` — so a `claude-*` model reached
|
|
27
|
+
* through LLMAPI is never schema-constrained and answers with the JSON wrapped
|
|
28
|
+
* in a markdown fence. A provider that honours `response_format` returns bare
|
|
29
|
+
* JSON and never reaches the fallback.
|
|
30
|
+
*
|
|
31
|
+
* The fallback only unwraps an envelope. It never repairs JSON syntax and
|
|
32
|
+
* never completes a truncated response, so malformed output still fails here
|
|
33
|
+
* rather than reaching the schema as something the model did not produce.
|
|
34
|
+
*/
|
|
35
|
+
function parseJsonContent(content) {
|
|
36
|
+
try {
|
|
37
|
+
return JSON.parse(content);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return JSON.parse(unwrapMarkdownFence(content));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const MARKDOWN_FENCE = /^\s*```(?:json)?\s*\n?([\s\S]*?)\n?\s*```\s*$/;
|
|
44
|
+
/**
|
|
45
|
+
* Anchored at both ends on purpose: it unwraps a response that is entirely one
|
|
46
|
+
* fenced block, and leaves anything else untouched so the original parse error
|
|
47
|
+
* is what surfaces.
|
|
48
|
+
*/
|
|
49
|
+
function unwrapMarkdownFence(content) {
|
|
50
|
+
return MARKDOWN_FENCE.exec(content)?.[1] ?? content;
|
|
51
|
+
}
|
|
21
52
|
//# sourceMappingURL=validateStructuredResponse.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateStructuredResponse.js","sourceRoot":"","sources":["../../../../src/providers/LLMAPI/utilities/validateStructuredResponse.ts"],"names":[],"mappings":";;AAUA,gEAoBC;AApBD,SAAgB,0BAA0B,CACxC,OAA0C;IAE1C,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAE3C,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"validateStructuredResponse.js","sourceRoot":"","sources":["../../../../src/providers/LLMAPI/utilities/validateStructuredResponse.ts"],"names":[],"mappings":";;AAUA,gEAoBC;AApBD,SAAgB,0BAA0B,CACxC,OAA0C;IAE1C,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAE3C,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;QAE5D,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC;YACrB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC;QAChE,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;IACzD,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,OAAO;YACL,IAAI,EAAE,OAAO;YACb,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