Skip to content

Commit 8741471

Browse files
authored
test: fix tests (#528)
1 parent 2852a23 commit 8741471

2 files changed

Lines changed: 41 additions & 8 deletions

File tree

src/ChatWrapper.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ export abstract class ChatWrapper {
122122
}
123123

124124
public generateFunctionCallResult(functionName: string, functionParams: any, result: any): LlamaText {
125+
return this._generateFunctionCallResult(
126+
functionName,
127+
functionParams,
128+
result === undefined
129+
? "void"
130+
: jsonDumps(result)
131+
);
132+
}
133+
134+
/** @internal */
135+
protected _generateFunctionCallResult(functionName: string, functionParams: any, rawResult: string): LlamaText {
125136
function resolveParameters(text: string | LlamaText) {
126137
return LlamaText(text)
127138
.mapValues((value) => {
@@ -136,11 +147,7 @@ export abstract class ChatWrapper {
136147

137148
return LlamaText([
138149
resolveParameters(this.settings.functions.result.prefix),
139-
(
140-
result === undefined
141-
? "void"
142-
: jsonDumps(result)
143-
),
150+
rawResult,
144151
resolveParameters(this.settings.functions.result.suffix)
145152
]);
146153
}

src/chatWrappers/QwenChatWrapper.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class QwenChatWrapper extends ChatWrapper {
1414

1515
public readonly keepOnlyLastThought: boolean;
1616
public readonly thoughts: "auto" | "discourage";
17+
/** @internal */ private readonly _flatFunctionResultString: boolean;
1718

1819
public override readonly settings: ChatWrapperSettings;
1920

@@ -35,18 +36,23 @@ export class QwenChatWrapper extends ChatWrapper {
3536
thoughts?: "auto" | "discourage",
3637

3738
/** @internal */
38-
_lineBreakBeforeFunctionCallPrefix?: boolean
39+
_lineBreakBeforeFunctionCallPrefix?: boolean,
40+
41+
/** @internal */
42+
_flatFunctionResultString?: boolean
3943
} = {}) {
4044
super();
4145

4246
const {
4347
keepOnlyLastThought = true,
4448
thoughts = "auto",
45-
_lineBreakBeforeFunctionCallPrefix = false
49+
_lineBreakBeforeFunctionCallPrefix = false,
50+
_flatFunctionResultString = false
4651
} = options;
4752

4853
this.keepOnlyLastThought = keepOnlyLastThought;
4954
this.thoughts = thoughts;
55+
this._flatFunctionResultString = _flatFunctionResultString;
5056

5157
this.settings = {
5258
supportsSystemMessages: true,
@@ -205,6 +211,13 @@ export class QwenChatWrapper extends ChatWrapper {
205211
};
206212
}
207213

214+
public override generateFunctionCallResult(functionName: string, functionParams: any, result: any) {
215+
if (this._flatFunctionResultString && typeof result === "string")
216+
return super._generateFunctionCallResult(functionName, functionParams, result);
217+
218+
return super.generateFunctionCallResult(functionName, functionParams, result);
219+
}
220+
208221
public override generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, {documentParams = true}: {
209222
documentParams?: boolean
210223
}) {
@@ -251,7 +264,20 @@ export class QwenChatWrapper extends ChatWrapper {
251264
[{}, {}, {_requireFunctionCallSettingsExtraction: true}],
252265
[{_lineBreakBeforeFunctionCallPrefix: true}, {}, {_requireFunctionCallSettingsExtraction: true}],
253266
[{thoughts: "discourage"}, {}, {_requireFunctionCallSettingsExtraction: true}],
254-
[{thoughts: "discourage", _lineBreakBeforeFunctionCallPrefix: true}, {}, {_requireFunctionCallSettingsExtraction: true}]
267+
[{thoughts: "discourage", _lineBreakBeforeFunctionCallPrefix: true}, {}, {_requireFunctionCallSettingsExtraction: true}],
268+
269+
[{_flatFunctionResultString: true}, {}, {_requireFunctionCallSettingsExtraction: true}],
270+
[
271+
{_flatFunctionResultString: true, _lineBreakBeforeFunctionCallPrefix: true},
272+
{},
273+
{_requireFunctionCallSettingsExtraction: true}
274+
],
275+
[{_flatFunctionResultString: true, thoughts: "discourage"}, {}, {_requireFunctionCallSettingsExtraction: true}],
276+
[
277+
{_flatFunctionResultString: true, thoughts: "discourage", _lineBreakBeforeFunctionCallPrefix: true},
278+
{},
279+
{_requireFunctionCallSettingsExtraction: true}
280+
]
255281
];
256282
}
257283
}

0 commit comments

Comments
 (0)