ai 4.1.43 → 4.1.44
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.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
@@ -2665,10 +2665,12 @@ type Experimental_LanguageModelV1Middleware = LanguageModelV1Middleware;
|
|
2665
2665
|
*
|
2666
2666
|
* @param tagName - The name of the XML tag to extract reasoning from.
|
2667
2667
|
* @param separator - The separator to use between reasoning and text sections.
|
2668
|
+
* @param startWithReasoning - Whether to start with reasoning tokens.
|
2668
2669
|
*/
|
2669
|
-
declare function extractReasoningMiddleware({ tagName, separator, }: {
|
2670
|
+
declare function extractReasoningMiddleware({ tagName, separator, startWithReasoning, }: {
|
2670
2671
|
tagName: string;
|
2671
2672
|
separator?: string;
|
2673
|
+
startWithReasoning?: boolean;
|
2672
2674
|
}): LanguageModelV1Middleware;
|
2673
2675
|
|
2674
2676
|
/**
|
package/dist/index.d.ts
CHANGED
@@ -2665,10 +2665,12 @@ type Experimental_LanguageModelV1Middleware = LanguageModelV1Middleware;
|
|
2665
2665
|
*
|
2666
2666
|
* @param tagName - The name of the XML tag to extract reasoning from.
|
2667
2667
|
* @param separator - The separator to use between reasoning and text sections.
|
2668
|
+
* @param startWithReasoning - Whether to start with reasoning tokens.
|
2668
2669
|
*/
|
2669
|
-
declare function extractReasoningMiddleware({ tagName, separator, }: {
|
2670
|
+
declare function extractReasoningMiddleware({ tagName, separator, startWithReasoning, }: {
|
2670
2671
|
tagName: string;
|
2671
2672
|
separator?: string;
|
2673
|
+
startWithReasoning?: boolean;
|
2672
2674
|
}): LanguageModelV1Middleware;
|
2673
2675
|
|
2674
2676
|
/**
|
package/dist/index.js
CHANGED
@@ -5839,17 +5839,19 @@ function getPotentialStartIndex(text2, searchedText) {
|
|
5839
5839
|
// core/middleware/extract-reasoning-middleware.ts
|
5840
5840
|
function extractReasoningMiddleware({
|
5841
5841
|
tagName,
|
5842
|
-
separator = "\n"
|
5842
|
+
separator = "\n",
|
5843
|
+
startWithReasoning = false
|
5843
5844
|
}) {
|
5844
5845
|
const openingTag = `<${tagName}>`;
|
5845
5846
|
const closingTag = `</${tagName}>`;
|
5846
5847
|
return {
|
5847
5848
|
middlewareVersion: "v1",
|
5848
5849
|
wrapGenerate: async ({ doGenerate }) => {
|
5849
|
-
const { text:
|
5850
|
-
if (
|
5851
|
-
return { text:
|
5850
|
+
const { text: rawText, ...rest } = await doGenerate();
|
5851
|
+
if (rawText == null) {
|
5852
|
+
return { text: rawText, ...rest };
|
5852
5853
|
}
|
5854
|
+
const text2 = startWithReasoning ? openingTag + rawText : rawText;
|
5853
5855
|
const regexp = new RegExp(`${openingTag}(.*?)${closingTag}`, "gs");
|
5854
5856
|
const matches = Array.from(text2.matchAll(regexp));
|
5855
5857
|
if (!matches.length) {
|
@@ -5872,7 +5874,7 @@ function extractReasoningMiddleware({
|
|
5872
5874
|
let isFirstReasoning = true;
|
5873
5875
|
let isFirstText = true;
|
5874
5876
|
let afterSwitch = false;
|
5875
|
-
let isReasoning =
|
5877
|
+
let isReasoning = startWithReasoning;
|
5876
5878
|
let buffer = "";
|
5877
5879
|
return {
|
5878
5880
|
stream: stream.pipeThrough(
|