llm-proxy 1.0.20 → 1.0.22
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.
|
@@ -9,26 +9,24 @@ class OutputFormatAdapter {
|
|
|
9
9
|
case types_1.Providers.OPENAI:
|
|
10
10
|
return response;
|
|
11
11
|
case types_1.Providers.ANTHROPIC_BEDROCK:
|
|
12
|
-
// Only use stream adaptation for streaming responses
|
|
13
12
|
if (response.type === "message_start") {
|
|
14
13
|
return this.adaptAnthropicBedrockStreamResponse(response);
|
|
15
14
|
}
|
|
16
|
-
// Keep existing non-streaming logic
|
|
17
15
|
return this.adaptAnthropicBedrockResponse(response);
|
|
18
16
|
default:
|
|
19
17
|
throw new Error(`Unsupported provider: ${provider}`);
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
20
|
catch (error) {
|
|
23
|
-
// Enhance error with context
|
|
24
21
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
25
22
|
throw new Error(`Failed to adapt response: ${errorMessage}`);
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
25
|
static adaptAnthropicBedrockResponse(response) {
|
|
29
26
|
var _a, _b, _c, _d;
|
|
27
|
+
// TODO: define type
|
|
30
28
|
if (!response || !response.id || !response.model || !response.content) {
|
|
31
|
-
throw new Error(
|
|
29
|
+
throw new Error(`Invalid Anthropic Bedrock response structure: ${JSON.stringify(response)}`);
|
|
32
30
|
}
|
|
33
31
|
return {
|
|
34
32
|
id: response.id,
|
|
@@ -57,59 +55,59 @@ class OutputFormatAdapter {
|
|
|
57
55
|
}
|
|
58
56
|
static adaptAnthropicBedrockStreamResponse(chunk) {
|
|
59
57
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
58
|
+
// TODO: define type
|
|
60
59
|
try {
|
|
61
|
-
//
|
|
62
|
-
if (chunk.
|
|
60
|
+
// For message start chunks
|
|
61
|
+
if (chunk.message) {
|
|
63
62
|
return {
|
|
64
|
-
id: "stream_chunk",
|
|
63
|
+
id: chunk.message.id || "stream_chunk",
|
|
65
64
|
object: "chat.completion.chunk",
|
|
66
65
|
created: Date.now(),
|
|
67
|
-
model:
|
|
66
|
+
model: chunk.message.model || "anthropic_stream",
|
|
68
67
|
choices: [
|
|
69
68
|
{
|
|
70
69
|
index: 0,
|
|
71
70
|
delta: {
|
|
72
|
-
content: ((_b = chunk.
|
|
71
|
+
content: ((_b = (_a = chunk.message.content) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.type) === "text"
|
|
72
|
+
? chunk.message.content[0]
|
|
73
|
+
.text
|
|
74
|
+
: "",
|
|
73
75
|
},
|
|
74
76
|
logprobs: null,
|
|
75
|
-
finish_reason: null,
|
|
77
|
+
finish_reason: chunk.message.stop_reason || null,
|
|
76
78
|
},
|
|
77
79
|
],
|
|
78
80
|
usage: {
|
|
79
|
-
prompt_tokens: 0,
|
|
80
|
-
completion_tokens:
|
|
81
|
-
total_tokens:
|
|
81
|
+
prompt_tokens: ((_c = chunk.message.usage) === null || _c === void 0 ? void 0 : _c.input_tokens) || 0,
|
|
82
|
+
completion_tokens: ((_d = chunk.message.usage) === null || _d === void 0 ? void 0 : _d.output_tokens) || 0,
|
|
83
|
+
total_tokens: (((_e = chunk.message.usage) === null || _e === void 0 ? void 0 : _e.input_tokens) || 0) +
|
|
84
|
+
(((_f = chunk.message.usage) === null || _f === void 0 ? void 0 : _f.output_tokens) || 0),
|
|
82
85
|
prompt_tokens_details: { cached_tokens: 0 },
|
|
83
86
|
completion_tokens_details: { reasoning_tokens: 0 },
|
|
84
87
|
},
|
|
85
88
|
system_fingerprint: "anthropic_translation",
|
|
86
89
|
};
|
|
87
90
|
}
|
|
88
|
-
//
|
|
89
|
-
if (!chunk.message) {
|
|
90
|
-
throw new Error("Invalid stream chunk: missing message and content");
|
|
91
|
-
}
|
|
91
|
+
// For content chunks
|
|
92
92
|
return {
|
|
93
|
-
id:
|
|
93
|
+
id: "stream_chunk",
|
|
94
94
|
object: "chat.completion.chunk",
|
|
95
95
|
created: Date.now(),
|
|
96
|
-
model:
|
|
97
|
-
choices:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
index,
|
|
96
|
+
model: "anthropic_stream",
|
|
97
|
+
choices: [
|
|
98
|
+
{
|
|
99
|
+
index: 0,
|
|
101
100
|
delta: {
|
|
102
|
-
content:
|
|
101
|
+
content: ((_g = chunk.content_block) === null || _g === void 0 ? void 0 : _g.text) || "",
|
|
103
102
|
},
|
|
104
103
|
logprobs: null,
|
|
105
|
-
finish_reason:
|
|
106
|
-
}
|
|
107
|
-
|
|
104
|
+
finish_reason: null,
|
|
105
|
+
},
|
|
106
|
+
],
|
|
108
107
|
usage: {
|
|
109
|
-
prompt_tokens:
|
|
110
|
-
completion_tokens:
|
|
111
|
-
total_tokens:
|
|
112
|
-
(((_g = chunk.message.usage) === null || _g === void 0 ? void 0 : _g.output_tokens) || 0),
|
|
108
|
+
prompt_tokens: 0,
|
|
109
|
+
completion_tokens: 1,
|
|
110
|
+
total_tokens: 1,
|
|
113
111
|
prompt_tokens_details: { cached_tokens: 0 },
|
|
114
112
|
completion_tokens_details: { reasoning_tokens: 0 },
|
|
115
113
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OutputFormatAdapter.js","sourceRoot":"","sources":["../../src/middleware/OutputFormatAdapter.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"OutputFormatAdapter.js","sourceRoot":"","sources":["../../src/middleware/OutputFormatAdapter.ts"],"names":[],"mappings":";;;AAAA,oCAYkB;AAElB,MAAa,mBAAmB;IAC9B,MAAM,CAAC,aAAa,CAAC,QAAa,EAAE,QAAmB;QACrD,IAAI,CAAC;YACH,QAAQ,QAAQ,EAAE,CAAC;gBACjB,KAAK,iBAAS,CAAC,MAAM;oBACnB,OAAO,QAA0B,CAAC;gBACpC,KAAK,iBAAS,CAAC,iBAAiB;oBAC9B,IAAI,QAAQ,CAAC,IAAI,KAAK,eA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xy",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.22",
|
|
4
4
|
"description": "An LLM Proxy that allows the user to interact with different language models from different providers using unified request and response formats.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|