@jaypie/llm 1.2.7 → 1.2.9
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/cjs/index.cjs +93 -12
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/operate/types.d.ts +2 -0
- package/dist/cjs/types/LlmProvider.interface.d.ts +1 -0
- package/dist/esm/index.js +93 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/operate/types.d.ts +2 -0
- package/dist/esm/types/LlmProvider.interface.d.ts +1 -0
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -911,19 +911,51 @@ class AnthropicAdapter extends BaseProviderAdapter {
|
|
|
911
911
|
//
|
|
912
912
|
buildRequest(request) {
|
|
913
913
|
// Convert messages to Anthropic format
|
|
914
|
-
//
|
|
915
|
-
const messages =
|
|
916
|
-
|
|
917
|
-
const role = msg.role;
|
|
918
|
-
return role !== "system";
|
|
919
|
-
})
|
|
920
|
-
.map((msg) => {
|
|
914
|
+
// Handle different message types: regular messages, function calls, and function outputs
|
|
915
|
+
const messages = [];
|
|
916
|
+
for (const msg of request.messages) {
|
|
921
917
|
const typedMsg = msg;
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
}
|
|
926
|
-
|
|
918
|
+
// Skip system messages - Anthropic only accepts system as a top-level field
|
|
919
|
+
if (typedMsg.role === "system") {
|
|
920
|
+
continue;
|
|
921
|
+
}
|
|
922
|
+
// Handle FunctionCall messages - convert to assistant message with tool_use
|
|
923
|
+
if (typedMsg.type === exports.LlmMessageType.FunctionCall) {
|
|
924
|
+
messages.push({
|
|
925
|
+
role: "assistant",
|
|
926
|
+
content: [
|
|
927
|
+
{
|
|
928
|
+
type: "tool_use",
|
|
929
|
+
id: typedMsg.call_id || "",
|
|
930
|
+
name: typedMsg.name || "",
|
|
931
|
+
input: JSON.parse(typedMsg.arguments || "{}"),
|
|
932
|
+
},
|
|
933
|
+
],
|
|
934
|
+
});
|
|
935
|
+
continue;
|
|
936
|
+
}
|
|
937
|
+
// Handle FunctionCallOutput messages - convert to user message with tool_result
|
|
938
|
+
if (typedMsg.type === exports.LlmMessageType.FunctionCallOutput) {
|
|
939
|
+
messages.push({
|
|
940
|
+
role: "user",
|
|
941
|
+
content: [
|
|
942
|
+
{
|
|
943
|
+
type: "tool_result",
|
|
944
|
+
tool_use_id: typedMsg.call_id || "",
|
|
945
|
+
content: typedMsg.output || "",
|
|
946
|
+
},
|
|
947
|
+
],
|
|
948
|
+
});
|
|
949
|
+
continue;
|
|
950
|
+
}
|
|
951
|
+
// Handle regular messages with role and content
|
|
952
|
+
if (typedMsg.role && typedMsg.content !== undefined) {
|
|
953
|
+
messages.push({
|
|
954
|
+
role: typedMsg.role,
|
|
955
|
+
content: convertContentToAnthropic(typedMsg.content),
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
}
|
|
927
959
|
// Append instructions to last message if provided
|
|
928
960
|
if (request.instructions && messages.length > 0) {
|
|
929
961
|
const lastMsg = messages[messages.length - 1];
|
|
@@ -960,6 +992,10 @@ class AnthropicAdapter extends BaseProviderAdapter {
|
|
|
960
992
|
if (request.providerOptions) {
|
|
961
993
|
Object.assign(anthropicRequest, request.providerOptions);
|
|
962
994
|
}
|
|
995
|
+
// First-class temperature takes precedence over providerOptions
|
|
996
|
+
if (request.temperature !== undefined) {
|
|
997
|
+
anthropicRequest.temperature = request.temperature;
|
|
998
|
+
}
|
|
963
999
|
return anthropicRequest;
|
|
964
1000
|
}
|
|
965
1001
|
formatTools(toolkit, outputSchema) {
|
|
@@ -1385,6 +1421,13 @@ class GeminiAdapter extends BaseProviderAdapter {
|
|
|
1385
1421
|
...request.providerOptions,
|
|
1386
1422
|
};
|
|
1387
1423
|
}
|
|
1424
|
+
// First-class temperature takes precedence over providerOptions
|
|
1425
|
+
if (request.temperature !== undefined) {
|
|
1426
|
+
geminiRequest.config = {
|
|
1427
|
+
...geminiRequest.config,
|
|
1428
|
+
temperature: request.temperature,
|
|
1429
|
+
};
|
|
1430
|
+
}
|
|
1388
1431
|
return geminiRequest;
|
|
1389
1432
|
}
|
|
1390
1433
|
formatTools(toolkit, outputSchema) {
|
|
@@ -2036,6 +2079,10 @@ class OpenAiAdapter extends BaseProviderAdapter {
|
|
|
2036
2079
|
if (request.providerOptions) {
|
|
2037
2080
|
Object.assign(openaiRequest, request.providerOptions);
|
|
2038
2081
|
}
|
|
2082
|
+
// First-class temperature takes precedence over providerOptions
|
|
2083
|
+
if (request.temperature !== undefined) {
|
|
2084
|
+
openaiRequest.temperature = request.temperature;
|
|
2085
|
+
}
|
|
2039
2086
|
return openaiRequest;
|
|
2040
2087
|
}
|
|
2041
2088
|
formatTools(toolkit, _outputSchema) {
|
|
@@ -2466,6 +2513,11 @@ class OpenRouterAdapter extends BaseProviderAdapter {
|
|
|
2466
2513
|
if (request.providerOptions) {
|
|
2467
2514
|
Object.assign(openRouterRequest, request.providerOptions);
|
|
2468
2515
|
}
|
|
2516
|
+
// First-class temperature takes precedence over providerOptions
|
|
2517
|
+
if (request.temperature !== undefined) {
|
|
2518
|
+
openRouterRequest.temperature =
|
|
2519
|
+
request.temperature;
|
|
2520
|
+
}
|
|
2469
2521
|
return openRouterRequest;
|
|
2470
2522
|
}
|
|
2471
2523
|
formatTools(toolkit, outputSchema) {
|
|
@@ -2911,6 +2963,31 @@ class OpenRouterAdapter extends BaseProviderAdapter {
|
|
|
2911
2963
|
});
|
|
2912
2964
|
}
|
|
2913
2965
|
}
|
|
2966
|
+
else if (message.type === exports.LlmMessageType.FunctionCall) {
|
|
2967
|
+
// Handle FunctionCall messages from StreamLoop (issue #165)
|
|
2968
|
+
openRouterMessages.push({
|
|
2969
|
+
role: "assistant",
|
|
2970
|
+
content: null,
|
|
2971
|
+
toolCalls: [
|
|
2972
|
+
{
|
|
2973
|
+
id: message.call_id,
|
|
2974
|
+
type: "function",
|
|
2975
|
+
function: {
|
|
2976
|
+
name: message.name,
|
|
2977
|
+
arguments: message.arguments || "{}",
|
|
2978
|
+
},
|
|
2979
|
+
},
|
|
2980
|
+
],
|
|
2981
|
+
});
|
|
2982
|
+
}
|
|
2983
|
+
else if (message.type === exports.LlmMessageType.FunctionCallOutput) {
|
|
2984
|
+
// Handle FunctionCallOutput messages from StreamLoop (issue #165)
|
|
2985
|
+
openRouterMessages.push({
|
|
2986
|
+
role: "tool",
|
|
2987
|
+
toolCallId: message.call_id,
|
|
2988
|
+
content: message.output || "",
|
|
2989
|
+
});
|
|
2990
|
+
}
|
|
2914
2991
|
}
|
|
2915
2992
|
return openRouterMessages;
|
|
2916
2993
|
}
|
|
@@ -3850,6 +3927,7 @@ class OperateLoop {
|
|
|
3850
3927
|
model: options.model ?? this.adapter.defaultModel,
|
|
3851
3928
|
providerOptions: options.providerOptions,
|
|
3852
3929
|
system: options.system,
|
|
3930
|
+
temperature: options.temperature,
|
|
3853
3931
|
tools: state.formattedTools,
|
|
3854
3932
|
user: options.user,
|
|
3855
3933
|
};
|
|
@@ -3929,6 +4007,7 @@ class OperateLoop {
|
|
|
3929
4007
|
model: options.model ?? this.adapter.defaultModel,
|
|
3930
4008
|
providerOptions: options.providerOptions,
|
|
3931
4009
|
system: options.system,
|
|
4010
|
+
temperature: options.temperature,
|
|
3932
4011
|
tools: state.formattedTools,
|
|
3933
4012
|
user: options.user,
|
|
3934
4013
|
};
|
|
@@ -4259,6 +4338,7 @@ class StreamLoop {
|
|
|
4259
4338
|
model: options.model ?? this.adapter.defaultModel,
|
|
4260
4339
|
providerOptions: options.providerOptions,
|
|
4261
4340
|
system: options.system,
|
|
4341
|
+
temperature: options.temperature,
|
|
4262
4342
|
tools: state.formattedTools,
|
|
4263
4343
|
user: options.user,
|
|
4264
4344
|
};
|
|
@@ -4325,6 +4405,7 @@ class StreamLoop {
|
|
|
4325
4405
|
model: options.model ?? this.adapter.defaultModel,
|
|
4326
4406
|
providerOptions: options.providerOptions,
|
|
4327
4407
|
system: options.system,
|
|
4408
|
+
temperature: options.temperature,
|
|
4328
4409
|
tools: state.formattedTools,
|
|
4329
4410
|
user: options.user,
|
|
4330
4411
|
};
|