@jaypie/llm 1.2.7 → 1.3.0
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
|
@@ -70,6 +70,8 @@ export interface OperateRequest {
|
|
|
70
70
|
format?: JsonObject;
|
|
71
71
|
/** Provider-specific options */
|
|
72
72
|
providerOptions?: JsonObject;
|
|
73
|
+
/** Sampling temperature (0-2 for most providers) */
|
|
74
|
+
temperature?: number;
|
|
73
75
|
/** User identifier for tracking */
|
|
74
76
|
user?: string;
|
|
75
77
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -909,19 +909,51 @@ class AnthropicAdapter extends BaseProviderAdapter {
|
|
|
909
909
|
//
|
|
910
910
|
buildRequest(request) {
|
|
911
911
|
// Convert messages to Anthropic format
|
|
912
|
-
//
|
|
913
|
-
const messages =
|
|
914
|
-
|
|
915
|
-
const role = msg.role;
|
|
916
|
-
return role !== "system";
|
|
917
|
-
})
|
|
918
|
-
.map((msg) => {
|
|
912
|
+
// Handle different message types: regular messages, function calls, and function outputs
|
|
913
|
+
const messages = [];
|
|
914
|
+
for (const msg of request.messages) {
|
|
919
915
|
const typedMsg = msg;
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
}
|
|
924
|
-
|
|
916
|
+
// Skip system messages - Anthropic only accepts system as a top-level field
|
|
917
|
+
if (typedMsg.role === "system") {
|
|
918
|
+
continue;
|
|
919
|
+
}
|
|
920
|
+
// Handle FunctionCall messages - convert to assistant message with tool_use
|
|
921
|
+
if (typedMsg.type === LlmMessageType.FunctionCall) {
|
|
922
|
+
messages.push({
|
|
923
|
+
role: "assistant",
|
|
924
|
+
content: [
|
|
925
|
+
{
|
|
926
|
+
type: "tool_use",
|
|
927
|
+
id: typedMsg.call_id || "",
|
|
928
|
+
name: typedMsg.name || "",
|
|
929
|
+
input: JSON.parse(typedMsg.arguments || "{}"),
|
|
930
|
+
},
|
|
931
|
+
],
|
|
932
|
+
});
|
|
933
|
+
continue;
|
|
934
|
+
}
|
|
935
|
+
// Handle FunctionCallOutput messages - convert to user message with tool_result
|
|
936
|
+
if (typedMsg.type === LlmMessageType.FunctionCallOutput) {
|
|
937
|
+
messages.push({
|
|
938
|
+
role: "user",
|
|
939
|
+
content: [
|
|
940
|
+
{
|
|
941
|
+
type: "tool_result",
|
|
942
|
+
tool_use_id: typedMsg.call_id || "",
|
|
943
|
+
content: typedMsg.output || "",
|
|
944
|
+
},
|
|
945
|
+
],
|
|
946
|
+
});
|
|
947
|
+
continue;
|
|
948
|
+
}
|
|
949
|
+
// Handle regular messages with role and content
|
|
950
|
+
if (typedMsg.role && typedMsg.content !== undefined) {
|
|
951
|
+
messages.push({
|
|
952
|
+
role: typedMsg.role,
|
|
953
|
+
content: convertContentToAnthropic(typedMsg.content),
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
}
|
|
925
957
|
// Append instructions to last message if provided
|
|
926
958
|
if (request.instructions && messages.length > 0) {
|
|
927
959
|
const lastMsg = messages[messages.length - 1];
|
|
@@ -958,6 +990,10 @@ class AnthropicAdapter extends BaseProviderAdapter {
|
|
|
958
990
|
if (request.providerOptions) {
|
|
959
991
|
Object.assign(anthropicRequest, request.providerOptions);
|
|
960
992
|
}
|
|
993
|
+
// First-class temperature takes precedence over providerOptions
|
|
994
|
+
if (request.temperature !== undefined) {
|
|
995
|
+
anthropicRequest.temperature = request.temperature;
|
|
996
|
+
}
|
|
961
997
|
return anthropicRequest;
|
|
962
998
|
}
|
|
963
999
|
formatTools(toolkit, outputSchema) {
|
|
@@ -1383,6 +1419,13 @@ class GeminiAdapter extends BaseProviderAdapter {
|
|
|
1383
1419
|
...request.providerOptions,
|
|
1384
1420
|
};
|
|
1385
1421
|
}
|
|
1422
|
+
// First-class temperature takes precedence over providerOptions
|
|
1423
|
+
if (request.temperature !== undefined) {
|
|
1424
|
+
geminiRequest.config = {
|
|
1425
|
+
...geminiRequest.config,
|
|
1426
|
+
temperature: request.temperature,
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1386
1429
|
return geminiRequest;
|
|
1387
1430
|
}
|
|
1388
1431
|
formatTools(toolkit, outputSchema) {
|
|
@@ -2034,6 +2077,10 @@ class OpenAiAdapter extends BaseProviderAdapter {
|
|
|
2034
2077
|
if (request.providerOptions) {
|
|
2035
2078
|
Object.assign(openaiRequest, request.providerOptions);
|
|
2036
2079
|
}
|
|
2080
|
+
// First-class temperature takes precedence over providerOptions
|
|
2081
|
+
if (request.temperature !== undefined) {
|
|
2082
|
+
openaiRequest.temperature = request.temperature;
|
|
2083
|
+
}
|
|
2037
2084
|
return openaiRequest;
|
|
2038
2085
|
}
|
|
2039
2086
|
formatTools(toolkit, _outputSchema) {
|
|
@@ -2464,6 +2511,11 @@ class OpenRouterAdapter extends BaseProviderAdapter {
|
|
|
2464
2511
|
if (request.providerOptions) {
|
|
2465
2512
|
Object.assign(openRouterRequest, request.providerOptions);
|
|
2466
2513
|
}
|
|
2514
|
+
// First-class temperature takes precedence over providerOptions
|
|
2515
|
+
if (request.temperature !== undefined) {
|
|
2516
|
+
openRouterRequest.temperature =
|
|
2517
|
+
request.temperature;
|
|
2518
|
+
}
|
|
2467
2519
|
return openRouterRequest;
|
|
2468
2520
|
}
|
|
2469
2521
|
formatTools(toolkit, outputSchema) {
|
|
@@ -2909,6 +2961,31 @@ class OpenRouterAdapter extends BaseProviderAdapter {
|
|
|
2909
2961
|
});
|
|
2910
2962
|
}
|
|
2911
2963
|
}
|
|
2964
|
+
else if (message.type === LlmMessageType.FunctionCall) {
|
|
2965
|
+
// Handle FunctionCall messages from StreamLoop (issue #165)
|
|
2966
|
+
openRouterMessages.push({
|
|
2967
|
+
role: "assistant",
|
|
2968
|
+
content: null,
|
|
2969
|
+
toolCalls: [
|
|
2970
|
+
{
|
|
2971
|
+
id: message.call_id,
|
|
2972
|
+
type: "function",
|
|
2973
|
+
function: {
|
|
2974
|
+
name: message.name,
|
|
2975
|
+
arguments: message.arguments || "{}",
|
|
2976
|
+
},
|
|
2977
|
+
},
|
|
2978
|
+
],
|
|
2979
|
+
});
|
|
2980
|
+
}
|
|
2981
|
+
else if (message.type === LlmMessageType.FunctionCallOutput) {
|
|
2982
|
+
// Handle FunctionCallOutput messages from StreamLoop (issue #165)
|
|
2983
|
+
openRouterMessages.push({
|
|
2984
|
+
role: "tool",
|
|
2985
|
+
toolCallId: message.call_id,
|
|
2986
|
+
content: message.output || "",
|
|
2987
|
+
});
|
|
2988
|
+
}
|
|
2912
2989
|
}
|
|
2913
2990
|
return openRouterMessages;
|
|
2914
2991
|
}
|
|
@@ -3848,6 +3925,7 @@ class OperateLoop {
|
|
|
3848
3925
|
model: options.model ?? this.adapter.defaultModel,
|
|
3849
3926
|
providerOptions: options.providerOptions,
|
|
3850
3927
|
system: options.system,
|
|
3928
|
+
temperature: options.temperature,
|
|
3851
3929
|
tools: state.formattedTools,
|
|
3852
3930
|
user: options.user,
|
|
3853
3931
|
};
|
|
@@ -3927,6 +4005,7 @@ class OperateLoop {
|
|
|
3927
4005
|
model: options.model ?? this.adapter.defaultModel,
|
|
3928
4006
|
providerOptions: options.providerOptions,
|
|
3929
4007
|
system: options.system,
|
|
4008
|
+
temperature: options.temperature,
|
|
3930
4009
|
tools: state.formattedTools,
|
|
3931
4010
|
user: options.user,
|
|
3932
4011
|
};
|
|
@@ -4257,6 +4336,7 @@ class StreamLoop {
|
|
|
4257
4336
|
model: options.model ?? this.adapter.defaultModel,
|
|
4258
4337
|
providerOptions: options.providerOptions,
|
|
4259
4338
|
system: options.system,
|
|
4339
|
+
temperature: options.temperature,
|
|
4260
4340
|
tools: state.formattedTools,
|
|
4261
4341
|
user: options.user,
|
|
4262
4342
|
};
|
|
@@ -4323,6 +4403,7 @@ class StreamLoop {
|
|
|
4323
4403
|
model: options.model ?? this.adapter.defaultModel,
|
|
4324
4404
|
providerOptions: options.providerOptions,
|
|
4325
4405
|
system: options.system,
|
|
4406
|
+
temperature: options.temperature,
|
|
4326
4407
|
tools: state.formattedTools,
|
|
4327
4408
|
user: options.user,
|
|
4328
4409
|
};
|