llm-proxy 1.0.16 → 1.0.18
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.
|
@@ -4,9 +4,6 @@ exports.OutputFormatAdapter = void 0;
|
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
class OutputFormatAdapter {
|
|
6
6
|
static adaptResponse(response, provider) {
|
|
7
|
-
if (!response) {
|
|
8
|
-
throw new Error("Response object is undefined");
|
|
9
|
-
}
|
|
10
7
|
switch (provider) {
|
|
11
8
|
case types_1.Providers.OPENAI:
|
|
12
9
|
return response;
|
|
@@ -17,20 +14,6 @@ class OutputFormatAdapter {
|
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
16
|
static adaptAnthropicBedrockResponse(response) {
|
|
20
|
-
// Validate required fields
|
|
21
|
-
if (!(response === null || response === void 0 ? void 0 : response.model)) {
|
|
22
|
-
throw new Error(`Missing required field: model, and the response is ${JSON.stringify(response)}`);
|
|
23
|
-
}
|
|
24
|
-
if (!(response === null || response === void 0 ? void 0 : response.usage)) {
|
|
25
|
-
throw new Error("Missing required field: usage");
|
|
26
|
-
}
|
|
27
|
-
// Validate content array
|
|
28
|
-
if (!response.content) {
|
|
29
|
-
throw new Error("Missing required field: content");
|
|
30
|
-
}
|
|
31
|
-
if (!Array.isArray(response.content)) {
|
|
32
|
-
throw new Error("Content must be an array");
|
|
33
|
-
}
|
|
34
17
|
const openAIResponse = {
|
|
35
18
|
id: response.id,
|
|
36
19
|
object: "text_completion",
|
|
@@ -43,13 +26,12 @@ class OutputFormatAdapter {
|
|
|
43
26
|
content: this.extractContent(contentBlock),
|
|
44
27
|
},
|
|
45
28
|
logprobs: null,
|
|
46
|
-
finish_reason: response.stop_reason
|
|
29
|
+
finish_reason: response.stop_reason,
|
|
47
30
|
})),
|
|
48
31
|
usage: {
|
|
49
|
-
prompt_tokens: response.usage.input_tokens
|
|
50
|
-
completion_tokens: response.usage.output_tokens
|
|
51
|
-
total_tokens:
|
|
52
|
-
(response.usage.output_tokens || 0),
|
|
32
|
+
prompt_tokens: response.usage.input_tokens,
|
|
33
|
+
completion_tokens: response.usage.output_tokens,
|
|
34
|
+
total_tokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
53
35
|
prompt_tokens_details: { cached_tokens: 0 },
|
|
54
36
|
completion_tokens_details: { reasoning_tokens: 0 },
|
|
55
37
|
},
|
|
@@ -58,9 +40,6 @@ class OutputFormatAdapter {
|
|
|
58
40
|
return openAIResponse;
|
|
59
41
|
}
|
|
60
42
|
static mapRole(content) {
|
|
61
|
-
if (!(content === null || content === void 0 ? void 0 : content.type)) {
|
|
62
|
-
throw new Error("Content block missing required field: type");
|
|
63
|
-
}
|
|
64
43
|
switch (content.type) {
|
|
65
44
|
case types_1.BedrockAnthropicContentType.TOOL_USE:
|
|
66
45
|
case types_1.BedrockAnthropicContentType.TOOL_RESULT:
|
|
@@ -68,34 +47,19 @@ class OutputFormatAdapter {
|
|
|
68
47
|
case types_1.BedrockAnthropicContentType.TEXT:
|
|
69
48
|
return "assistant";
|
|
70
49
|
default:
|
|
71
|
-
|
|
50
|
+
return "unknown";
|
|
72
51
|
}
|
|
73
52
|
}
|
|
74
53
|
static extractContent(content) {
|
|
75
|
-
if (!(content === null || content === void 0 ? void 0 : content.type)) {
|
|
76
|
-
throw new Error("Content block missing required field: type");
|
|
77
|
-
}
|
|
78
54
|
switch (content.type) {
|
|
79
55
|
case types_1.BedrockAnthropicContentType.TEXT:
|
|
80
|
-
|
|
81
|
-
if (!textContent.text) {
|
|
82
|
-
throw new Error("Text content missing required field: text");
|
|
83
|
-
}
|
|
84
|
-
return textContent.text;
|
|
56
|
+
return content.text;
|
|
85
57
|
case types_1.BedrockAnthropicContentType.TOOL_RESULT:
|
|
86
|
-
|
|
87
|
-
if (!toolResultContent.content) {
|
|
88
|
-
throw new Error("Tool result content missing required field: content");
|
|
89
|
-
}
|
|
90
|
-
return toolResultContent.content;
|
|
58
|
+
return content.content || "";
|
|
91
59
|
case types_1.BedrockAnthropicContentType.TOOL_USE:
|
|
92
|
-
|
|
93
|
-
if (!toolUseContent.id) {
|
|
94
|
-
throw new Error("Tool use content missing required field: id");
|
|
95
|
-
}
|
|
96
|
-
return toolUseContent.id;
|
|
60
|
+
return content.id || "";
|
|
97
61
|
default:
|
|
98
|
-
|
|
62
|
+
return "";
|
|
99
63
|
}
|
|
100
64
|
}
|
|
101
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OutputFormatAdapter.js","sourceRoot":"","sources":["../../src/middleware/OutputFormatAdapter.ts"],"names":[],"mappings":";;;AAAA,oCAUkB;AAElB,MAAa,mBAAmB;IAC9B,MAAM,CAAC,aAAa,CAAC,QAAa,EAAE,QAAmB;QACrD,
|
|
1
|
+
{"version":3,"file":"OutputFormatAdapter.js","sourceRoot":"","sources":["../../src/middleware/OutputFormatAdapter.ts"],"names":[],"mappings":";;;AAAA,oCAUkB;AAElB,MAAa,mBAAmB;IAC9B,MAAM,CAAC,aAAa,CAAC,QAAa,EAAE,QAAmB;QACrD,QAAQ,QAAQ,EAAE,CAAC;YACjB,KAAK,iBAAS,CAAC,MAAM;gBACnB,OAAO,QAA0B,CAAC;YAEpC,KAAK,iBAAS,CAAC,iBAAiB;gBAC9B,OAAO,IAAI,CAAC,6BAA6B,CACvC,QAAoC,CACrC,CAAC;YAEJ;gBACE,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,6BAA6B,CAC1C,QAAkC;QAElC,MAAM,cAAc,GAAmB;YACrC,EAAE,EAAE,QAAQ,CAAC,EAAE;YACf,MAAM,EAAE,iBAAiB;YACzB,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE;YACnB,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,KAAK,EAAE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,CAAC,EAAE,IAAI,EAAE,CAAC;YAC9D;gBACE,OAAO,EAAE,CAAC;QACd,CAAC;IACH,CAAC;CACF;AAtED,kDAsEC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -56,7 +56,7 @@ export interface OpenAIUsage {
|
|
|
56
56
|
completion_tokens_details: any;
|
|
57
57
|
}
|
|
58
58
|
export interface OpenAIResponse {
|
|
59
|
-
id
|
|
59
|
+
id: string;
|
|
60
60
|
object: string;
|
|
61
61
|
created: number;
|
|
62
62
|
model: string;
|
|
@@ -143,7 +143,7 @@ export interface BedrockAnthropicUsage {
|
|
|
143
143
|
output_tokens: number;
|
|
144
144
|
}
|
|
145
145
|
export interface BedrockAnthropicResponse {
|
|
146
|
-
id
|
|
146
|
+
id: string;
|
|
147
147
|
type: "message";
|
|
148
148
|
role: BedrockAnthropicMessageRole;
|
|
149
149
|
model: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "llm-proxy",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18",
|
|
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",
|