@purista/harness-bedrock 1.2.1 → 1.2.2
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/dist/index.js +14 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -83,9 +83,11 @@ class BedrockModelProvider extends BaseModelProvider {
|
|
|
83
83
|
req.signal.throwIfAborted();
|
|
84
84
|
const response = await this.client.send(new ConverseCommand(toConverseInput(req, true)), { abortSignal: req.signal });
|
|
85
85
|
const toolUse = response.output?.message?.content?.find((block) => block.toolUse?.name === 'harness_response')?.toolUse;
|
|
86
|
+
const toolCalls = withoutObjectTool(extractToolCalls(response, req, 'object'));
|
|
86
87
|
const object = (toolUse?.input ?? parseJson(outputText(response) || '{}', req, 'object'));
|
|
87
88
|
return {
|
|
88
89
|
object,
|
|
90
|
+
...(toolCalls ? { toolCalls } : {}),
|
|
89
91
|
usage: toUsage(response.usage?.inputTokens, response.usage?.outputTokens),
|
|
90
92
|
finishReason: toFinishReason(response.stopReason),
|
|
91
93
|
raw: response
|
|
@@ -129,17 +131,19 @@ function toConverseInput(req, forceObject) {
|
|
|
129
131
|
...(req.call?.providerOptions ?? {})
|
|
130
132
|
};
|
|
131
133
|
const { system, messages } = toBedrockMessages(req.messages);
|
|
132
|
-
const
|
|
134
|
+
const modelTools = toTools(req.tools) ?? [];
|
|
135
|
+
const tools = forceObject ? [...modelTools, toObjectTool(req)] : modelTools;
|
|
136
|
+
const forceObjectTool = forceObject && modelTools.length === 0;
|
|
133
137
|
return {
|
|
134
138
|
modelId: req.model,
|
|
135
139
|
messages,
|
|
136
140
|
...(system.length > 0 ? { system } : {}),
|
|
137
|
-
...(tools ? { toolConfig: { tools, ...(
|
|
141
|
+
...(tools.length > 0 ? { toolConfig: { tools, ...(forceObjectTool ? { toolChoice: { tool: { name: 'harness_response' } } } : {}) } } : {}),
|
|
138
142
|
inferenceConfig: {
|
|
139
|
-
...(req.call?.maxTokens ?? req.defaults?.maxTokens !== undefined ? { maxTokens: req.call?.maxTokens ?? req.defaults?.maxTokens } : {}),
|
|
140
|
-
...(req.call?.temperature ?? req.defaults?.temperature !== undefined ? { temperature: req.call?.temperature ?? req.defaults?.temperature } : {}),
|
|
141
|
-
...(req.call?.topP ?? req.defaults?.topP !== undefined ? { topP: req.call?.topP ?? req.defaults?.topP } : {}),
|
|
142
|
-
...(req.call?.stopSequences ?? req.defaults?.stopSequences ? { stopSequences: req.call?.stopSequences ?? req.defaults?.stopSequences } : {})
|
|
143
|
+
...((req.call?.maxTokens ?? req.defaults?.maxTokens) !== undefined ? { maxTokens: req.call?.maxTokens ?? req.defaults?.maxTokens } : {}),
|
|
144
|
+
...((req.call?.temperature ?? req.defaults?.temperature) !== undefined ? { temperature: req.call?.temperature ?? req.defaults?.temperature } : {}),
|
|
145
|
+
...((req.call?.topP ?? req.defaults?.topP) !== undefined ? { topP: req.call?.topP ?? req.defaults?.topP } : {}),
|
|
146
|
+
...((req.call?.stopSequences ?? req.defaults?.stopSequences) !== undefined ? { stopSequences: req.call?.stopSequences ?? req.defaults?.stopSequences } : {})
|
|
143
147
|
},
|
|
144
148
|
...providerOptions
|
|
145
149
|
};
|
|
@@ -211,6 +215,10 @@ function extractToolCalls(response, req, method) {
|
|
|
211
215
|
arguments: typeof call.input === 'string' ? parseJson(call.input, req, method) : call.input ?? {}
|
|
212
216
|
}));
|
|
213
217
|
}
|
|
218
|
+
function withoutObjectTool(calls) {
|
|
219
|
+
const filtered = calls?.filter((call) => call.name !== 'harness_response');
|
|
220
|
+
return filtered && filtered.length > 0 ? filtered : undefined;
|
|
221
|
+
}
|
|
214
222
|
function parseJson(content, req, method) {
|
|
215
223
|
try {
|
|
216
224
|
return JSON.parse(content);
|