llm-proxy 1.0.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/README.md +34 -0
- package/docs/directoryStructure.png +0 -0
- package/docs/plan.excalidraw +1758 -0
- package/docs/plan.png +0 -0
- package/jest.config.js +10 -0
- package/package.json +29 -0
- package/src/clients/AwsBedrockAnthropicClient.ts +56 -0
- package/src/clients/OpenAIClient.ts +66 -0
- package/src/index.ts +145 -0
- package/src/middleware/InputFormatAdapter.ts +51 -0
- package/src/middleware/OutputFormatAdapter.ts +83 -0
- package/src/middleware/ProviderFinder.ts +23 -0
- package/src/services/AwsBedrockAnthropicService.ts +111 -0
- package/src/services/ClientService.ts +29 -0
- package/src/services/OpenAIService.ts +68 -0
- package/src/test/AwsBedrockAnthropicClient.test.ts +98 -0
- package/src/test/AwsBedrockAnthropicStreamClient.test.ts +81 -0
- package/src/test/OpenAIClient.test.ts +58 -0
- package/src/types/index.ts +234 -0
- package/tsconfig.json +110 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { AwsBedrockAnthropicService } from "../services/AwsBedrockAnthropicService";
|
|
2
|
+
import {
|
|
3
|
+
BedrockAnthropicContentType,
|
|
4
|
+
BedrockAnthropicMessageRole,
|
|
5
|
+
BedrockAnthropicMessages,
|
|
6
|
+
BedrockAnthropicSupportedLLMs,
|
|
7
|
+
} from "../types";
|
|
8
|
+
|
|
9
|
+
describe("AwsBedrockAnthropicService", () => {
|
|
10
|
+
let client: AwsBedrockAnthropicService;
|
|
11
|
+
|
|
12
|
+
beforeAll(() => {
|
|
13
|
+
client = new AwsBedrockAnthropicService();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should generate a valid response based on input messages and system prompt", async () => {
|
|
17
|
+
const messages: BedrockAnthropicMessages = [
|
|
18
|
+
{
|
|
19
|
+
role: BedrockAnthropicMessageRole.USER,
|
|
20
|
+
content: [
|
|
21
|
+
{
|
|
22
|
+
type: BedrockAnthropicContentType.TEXT,
|
|
23
|
+
text: "Hello, I'm Ahmad, who are you?",
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
role: BedrockAnthropicMessageRole.ASSISTANT,
|
|
29
|
+
content: [
|
|
30
|
+
{
|
|
31
|
+
type: BedrockAnthropicContentType.TEXT,
|
|
32
|
+
text: "I'm Lily, your AI Assistant. Nice to meet you, Ahmad.",
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
role: BedrockAnthropicMessageRole.USER,
|
|
38
|
+
content: [
|
|
39
|
+
{
|
|
40
|
+
type: BedrockAnthropicContentType.TEXT,
|
|
41
|
+
text: "Thank you, how old are you?",
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
const systemPrompt = "You are a helpful assistant.";
|
|
48
|
+
|
|
49
|
+
const response = await client.generateCompletion(
|
|
50
|
+
messages,
|
|
51
|
+
BedrockAnthropicSupportedLLMs.CLAUDE_3_HAIKU,
|
|
52
|
+
100,
|
|
53
|
+
0.7,
|
|
54
|
+
systemPrompt
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// Validate response structure
|
|
58
|
+
expect(response).toBeDefined();
|
|
59
|
+
expect(response).toHaveProperty("id");
|
|
60
|
+
expect(response).toHaveProperty("type", "message");
|
|
61
|
+
expect(response).toHaveProperty(
|
|
62
|
+
"role",
|
|
63
|
+
BedrockAnthropicMessageRole.ASSISTANT
|
|
64
|
+
);
|
|
65
|
+
expect(response).toHaveProperty("model");
|
|
66
|
+
expect(Array.isArray(response.content)).toBe(true);
|
|
67
|
+
expect(response.content.length).toBeGreaterThan(0);
|
|
68
|
+
|
|
69
|
+
// Check the type and structure of each item in the content array
|
|
70
|
+
response.content.forEach((contentItem) => {
|
|
71
|
+
expect(contentItem).toHaveProperty("type");
|
|
72
|
+
if (contentItem.type === BedrockAnthropicContentType.TEXT) {
|
|
73
|
+
expect(contentItem).toHaveProperty("text");
|
|
74
|
+
expect(typeof contentItem.text).toBe("string");
|
|
75
|
+
} else if (contentItem.type === BedrockAnthropicContentType.IMAGE) {
|
|
76
|
+
expect(contentItem).toHaveProperty("source");
|
|
77
|
+
expect(contentItem.source).toHaveProperty("type");
|
|
78
|
+
expect(contentItem.source).toHaveProperty("media_type");
|
|
79
|
+
expect(contentItem.source).toHaveProperty("data");
|
|
80
|
+
} else if (contentItem.type === BedrockAnthropicContentType.TOOL_USE) {
|
|
81
|
+
expect(contentItem).toHaveProperty("id");
|
|
82
|
+
expect(contentItem).toHaveProperty("name");
|
|
83
|
+
expect(contentItem).toHaveProperty("input");
|
|
84
|
+
} else if (contentItem.type === BedrockAnthropicContentType.TOOL_RESULT) {
|
|
85
|
+
expect(contentItem).toHaveProperty("content");
|
|
86
|
+
expect(typeof contentItem.content).toBe("string");
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Check usage field for input and output tokens
|
|
91
|
+
if (response.usage) {
|
|
92
|
+
expect(response.usage).toHaveProperty("input_tokens");
|
|
93
|
+
expect(response.usage).toHaveProperty("output_tokens");
|
|
94
|
+
expect(typeof response.usage.input_tokens).toBe("number");
|
|
95
|
+
expect(typeof response.usage.output_tokens).toBe("number");
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// TODO: this test is fucked up and needs to be fixed
|
|
2
|
+
|
|
3
|
+
import { AwsBedrockAnthropicService } from "../services/AwsBedrockAnthropicService";
|
|
4
|
+
import {
|
|
5
|
+
BedrockAnthropicContentType,
|
|
6
|
+
BedrockAnthropicMessageRole,
|
|
7
|
+
BedrockAnthropicMessages,
|
|
8
|
+
BedrockAnthropicParsedChunk,
|
|
9
|
+
BedrockAnthropicSupportedLLMs,
|
|
10
|
+
} from "../types";
|
|
11
|
+
|
|
12
|
+
describe("AwsBedrockAnthropicService Streaming", () => {
|
|
13
|
+
let client: AwsBedrockAnthropicService;
|
|
14
|
+
|
|
15
|
+
beforeAll(() => {
|
|
16
|
+
client = new AwsBedrockAnthropicService();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should stream a valid response based on input messages and system prompt", async () => {
|
|
20
|
+
const messages: BedrockAnthropicMessages = [
|
|
21
|
+
{
|
|
22
|
+
role: BedrockAnthropicMessageRole.USER,
|
|
23
|
+
content: [
|
|
24
|
+
{
|
|
25
|
+
type: BedrockAnthropicContentType.TEXT,
|
|
26
|
+
text: "Can you assist me with a task?",
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const systemPrompt = "You are a helpful assistant.";
|
|
33
|
+
|
|
34
|
+
const stream = client.generateStreamCompletion(
|
|
35
|
+
messages,
|
|
36
|
+
BedrockAnthropicSupportedLLMs.CLAUDE_3_HAIKU,
|
|
37
|
+
100,
|
|
38
|
+
0.7,
|
|
39
|
+
systemPrompt
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
let isFirstChunk = true;
|
|
43
|
+
for await (const chunk of stream) {
|
|
44
|
+
expect(chunk).toBeDefined();
|
|
45
|
+
expect(chunk).toHaveProperty(
|
|
46
|
+
"role",
|
|
47
|
+
BedrockAnthropicMessageRole.ASSISTANT
|
|
48
|
+
);
|
|
49
|
+
expect(Array.isArray(chunk.content)).toBe(true);
|
|
50
|
+
|
|
51
|
+
chunk.content.forEach((contentItem) => {
|
|
52
|
+
expect(contentItem).toHaveProperty("type");
|
|
53
|
+
if (contentItem.type === BedrockAnthropicContentType.TEXT) {
|
|
54
|
+
expect(contentItem).toHaveProperty("text");
|
|
55
|
+
expect(typeof contentItem.text).toBe("string");
|
|
56
|
+
} else if (contentItem.type === BedrockAnthropicContentType.IMAGE) {
|
|
57
|
+
expect(contentItem).toHaveProperty("source");
|
|
58
|
+
expect(contentItem.source).toHaveProperty("type");
|
|
59
|
+
expect(contentItem.source).toHaveProperty("media_type");
|
|
60
|
+
expect(contentItem.source).toHaveProperty("data");
|
|
61
|
+
} else if (contentItem.type === BedrockAnthropicContentType.TOOL_USE) {
|
|
62
|
+
expect(contentItem).toHaveProperty("id");
|
|
63
|
+
expect(contentItem).toHaveProperty("name");
|
|
64
|
+
expect(contentItem).toHaveProperty("input");
|
|
65
|
+
} else if (
|
|
66
|
+
contentItem.type === BedrockAnthropicContentType.TOOL_RESULT
|
|
67
|
+
) {
|
|
68
|
+
expect(contentItem).toHaveProperty("content");
|
|
69
|
+
expect(typeof contentItem.content).toBe("string");
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
if (isFirstChunk) {
|
|
74
|
+
// Verify initial chunk properties
|
|
75
|
+
expect(chunk).toHaveProperty("id");
|
|
76
|
+
expect(chunk).toHaveProperty("model");
|
|
77
|
+
isFirstChunk = false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { config } from "../../src/config/config";
|
|
2
|
+
import { OpenAIService } from "../services/OpenAIService";
|
|
3
|
+
import { Messages, OpenAIMessagesRoles, OpenAISupportedLLMs } from "../types";
|
|
4
|
+
|
|
5
|
+
describe("OpenAIClient", () => {
|
|
6
|
+
let client: OpenAIService;
|
|
7
|
+
|
|
8
|
+
beforeAll(() => {
|
|
9
|
+
client = new OpenAIService(config.openaiApiKey);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("should generate text based on input messages", async () => {
|
|
13
|
+
const messages: Messages = [
|
|
14
|
+
{
|
|
15
|
+
role: OpenAIMessagesRoles.SYSTEM,
|
|
16
|
+
content: "You are a helpful assistant.",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
role: OpenAIMessagesRoles.USER,
|
|
20
|
+
content: "Hello, I'm Ahmad, who are you?",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
role: OpenAIMessagesRoles.ASSISTANT,
|
|
24
|
+
content: "I'm Lily, your AI Assistant. Nice to meet you, Ahmad.",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
role: OpenAIMessagesRoles.USER,
|
|
28
|
+
content: "Thank you, how old are you?",
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const response = await client.generateCompletion(
|
|
33
|
+
messages,
|
|
34
|
+
OpenAISupportedLLMs.GPT_4_O_MINI,
|
|
35
|
+
10,
|
|
36
|
+
0.7
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// Verify that the response is of type OpenAIResponse
|
|
40
|
+
expect(response).toBeDefined();
|
|
41
|
+
expect(response).toHaveProperty("id");
|
|
42
|
+
expect(response).toHaveProperty("object", "chat.completion");
|
|
43
|
+
expect(response).toHaveProperty("choices");
|
|
44
|
+
expect(Array.isArray(response.choices)).toBe(true);
|
|
45
|
+
expect(response.choices.length).toBeGreaterThan(0);
|
|
46
|
+
|
|
47
|
+
// Verify the content of the first choice in the response
|
|
48
|
+
const firstChoice = response.choices[0];
|
|
49
|
+
expect(firstChoice).toHaveProperty("message");
|
|
50
|
+
expect(firstChoice.message).toHaveProperty("role");
|
|
51
|
+
expect(firstChoice.message).toHaveProperty("content");
|
|
52
|
+
|
|
53
|
+
// Check if `usage` data is present and has expected structure
|
|
54
|
+
expect(response).toHaveProperty("usage");
|
|
55
|
+
expect(response.usage).toHaveProperty("total_tokens");
|
|
56
|
+
expect(typeof response.usage.total_tokens).toBe("number");
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// GENERAL
|
|
2
|
+
export enum Providers {
|
|
3
|
+
OPENAI = "OpenAI",
|
|
4
|
+
ANTHROPIC_BEDROCK = "AnthropicBedrock",
|
|
5
|
+
COHERE_BEDROCK = "CohereBedrock", // NOTE: not supported yet
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// OPENAI
|
|
9
|
+
export enum OpenAIMessagesRoles {
|
|
10
|
+
SYSTEM = "system",
|
|
11
|
+
USER = "user",
|
|
12
|
+
ASSISTANT = "assistant",
|
|
13
|
+
TOOL = "tool",
|
|
14
|
+
FUNCTION = "function",
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type OpenAISystemMessage = {
|
|
18
|
+
role: OpenAIMessagesRoles.SYSTEM;
|
|
19
|
+
content: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type OpenAIUserMessage = {
|
|
23
|
+
role: OpenAIMessagesRoles.USER;
|
|
24
|
+
content: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type OpenAIAssistantMessage = {
|
|
28
|
+
role: OpenAIMessagesRoles.ASSISTANT;
|
|
29
|
+
content: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type OpenAIToolMessage = {
|
|
33
|
+
role: OpenAIMessagesRoles.TOOL;
|
|
34
|
+
content: string;
|
|
35
|
+
tool_call_id: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type OpenAIFunctionMessage = {
|
|
39
|
+
role: OpenAIMessagesRoles.FUNCTION;
|
|
40
|
+
content: string;
|
|
41
|
+
name: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type OpenAIMessage =
|
|
45
|
+
| OpenAISystemMessage
|
|
46
|
+
| OpenAIUserMessage
|
|
47
|
+
| OpenAIAssistantMessage
|
|
48
|
+
| OpenAIToolMessage
|
|
49
|
+
| OpenAIFunctionMessage;
|
|
50
|
+
|
|
51
|
+
export type OpenAIMessages = OpenAIMessage[];
|
|
52
|
+
|
|
53
|
+
export enum OpenAISupportedLLMs {
|
|
54
|
+
GPT_4_O_LAEST = "chatgpt-4o-latest", // points to the latest version of gpt-4o
|
|
55
|
+
GPT_4_O = "gpt-4o",
|
|
56
|
+
GPT_4_O_MINI = "gpt-4o-mini",
|
|
57
|
+
GPT_4_TURBO = "gpt-4-turbo",
|
|
58
|
+
GPT_4_TURBO_PREVIEW = "gpt-4-turbo-preview", // its same as gpt-4-turbo-2024-04-09
|
|
59
|
+
GPT_3_5_TURBO = "gpt-3.5-turbo", // its same as gpt-3.5-turbo-0125
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface OpenAIChoices {
|
|
63
|
+
index: number;
|
|
64
|
+
message: any; // TODO: update this guys types as well
|
|
65
|
+
logprobs: any; // TODO: define logprobs type
|
|
66
|
+
finish_reason: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface OpenAIUsage {
|
|
70
|
+
prompt_tokens: number;
|
|
71
|
+
completion_tokens: number;
|
|
72
|
+
total_tokens: number;
|
|
73
|
+
prompt_tokens_details: any; // TODO: define type
|
|
74
|
+
completion_tokens_details: any; // TODO: define type
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface OpenAIResponse {
|
|
78
|
+
id: string;
|
|
79
|
+
object: string;
|
|
80
|
+
created: number;
|
|
81
|
+
model: string;
|
|
82
|
+
choices: Array<{
|
|
83
|
+
index: number;
|
|
84
|
+
message: {
|
|
85
|
+
role: string;
|
|
86
|
+
content: string;
|
|
87
|
+
};
|
|
88
|
+
logprobs: null | object;
|
|
89
|
+
finish_reason: string;
|
|
90
|
+
}>;
|
|
91
|
+
usage: {
|
|
92
|
+
prompt_tokens: number;
|
|
93
|
+
completion_tokens: number;
|
|
94
|
+
total_tokens: number;
|
|
95
|
+
prompt_tokens_details: { cached_tokens: number };
|
|
96
|
+
completion_tokens_details: { reasoning_tokens: number };
|
|
97
|
+
};
|
|
98
|
+
system_fingerprint: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// AWS BEDROCK
|
|
102
|
+
|
|
103
|
+
// AWS BEDROCK ANTHROPIC
|
|
104
|
+
|
|
105
|
+
export enum BedrockAnthropicSupportedLLMs {
|
|
106
|
+
CLAUDE_3_HAIKU = "anthropic.claude-3-haiku-20240307-v1:0",
|
|
107
|
+
CLAUDE_3_SONNET = "anthropic.claude-3-sonnet-20240229-v1:0",
|
|
108
|
+
CLAUDE_3_OPUS = "anthropic.claude-3-opus-20240229-v1:0",
|
|
109
|
+
CLAUDE_3_5_SONNET = "anthropic.claude-3-5-sonnet-20241022-v2:0",
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export enum BedrockAnthropicContentType {
|
|
113
|
+
TEXT = "text",
|
|
114
|
+
IMAGE = "image",
|
|
115
|
+
TOOL_USE = "tool_use",
|
|
116
|
+
TOOL_RESULT = "tool_result",
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export enum BedrockAnthropicMessageRole {
|
|
120
|
+
USER = "user",
|
|
121
|
+
ASSISTANT = "assistant",
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface BedrockAnthropicToolUseContent {
|
|
125
|
+
type: BedrockAnthropicContentType.TOOL_USE;
|
|
126
|
+
id: string;
|
|
127
|
+
name: string;
|
|
128
|
+
input: any;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface BedrockAnthropicTextContent {
|
|
132
|
+
type: BedrockAnthropicContentType.TEXT;
|
|
133
|
+
text: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
interface BedrockAnthropicImageContent {
|
|
137
|
+
type: BedrockAnthropicContentType.IMAGE;
|
|
138
|
+
source: {
|
|
139
|
+
type: string;
|
|
140
|
+
media_type: string;
|
|
141
|
+
data: string;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
export interface BedrockAnthropicToolResultContent {
|
|
145
|
+
type: BedrockAnthropicContentType.TOOL_RESULT;
|
|
146
|
+
content: string;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export type BedrockAnthropicContent =
|
|
150
|
+
| BedrockAnthropicToolUseContent
|
|
151
|
+
| BedrockAnthropicToolResultContent
|
|
152
|
+
| BedrockAnthropicTextContent
|
|
153
|
+
| BedrockAnthropicImageContent;
|
|
154
|
+
|
|
155
|
+
export interface BedrockAnthropicMessage {
|
|
156
|
+
role: BedrockAnthropicMessageRole;
|
|
157
|
+
content: BedrockAnthropicContent[];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface BedrockAnthropicFunctionCall {
|
|
161
|
+
id: string;
|
|
162
|
+
name: string;
|
|
163
|
+
arguments: string;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export type BedrockAnthropicMessages = BedrockAnthropicMessage[];
|
|
167
|
+
|
|
168
|
+
export interface BedrockAnthropicOptions {
|
|
169
|
+
outputTokenLength: number;
|
|
170
|
+
temperature: number;
|
|
171
|
+
systemPrompt: string;
|
|
172
|
+
messages: BedrockAnthropicMessages;
|
|
173
|
+
tools: any;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface BedrockAnthropicUsage {
|
|
177
|
+
input_tokens: number;
|
|
178
|
+
output_tokens: number;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface BedrockAnthropicResponse {
|
|
182
|
+
id: string;
|
|
183
|
+
type: "message";
|
|
184
|
+
role: BedrockAnthropicMessageRole;
|
|
185
|
+
model: string;
|
|
186
|
+
content: BedrockAnthropicContent[];
|
|
187
|
+
stop_reason: string;
|
|
188
|
+
stop_sequence: string;
|
|
189
|
+
usage: BedrockAnthropicUsage;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export interface BedrockAnthropicMessageChunk {
|
|
193
|
+
id: string;
|
|
194
|
+
type: "message";
|
|
195
|
+
model: string;
|
|
196
|
+
role: BedrockAnthropicMessageRole;
|
|
197
|
+
content: BedrockAnthropicContent[];
|
|
198
|
+
stop_reason: string | null;
|
|
199
|
+
stop_sequence: string | null;
|
|
200
|
+
usage: BedrockAnthropicUsage;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export interface BedrockAnthropicContentBlock {
|
|
204
|
+
type: string;
|
|
205
|
+
text: string;
|
|
206
|
+
name?: string;
|
|
207
|
+
id?: string;
|
|
208
|
+
partial_json?: string;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface BedrockAnthropicMetrics {
|
|
212
|
+
inputTokenCount: number;
|
|
213
|
+
outputTokenCount: number;
|
|
214
|
+
invocationLatency: number;
|
|
215
|
+
firstByteLatency: number;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export type BedrockAnthropicParsedChunk = {
|
|
219
|
+
type: "message_start";
|
|
220
|
+
message?: BedrockAnthropicMessageChunk;
|
|
221
|
+
content_block?: BedrockAnthropicContentBlock;
|
|
222
|
+
delta?: BedrockAnthropicContentBlock;
|
|
223
|
+
"amazon-bedrock-invocationMetrics"?: BedrockAnthropicMetrics;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// GENERAL
|
|
227
|
+
export type Messages = OpenAIMessages | BedrockAnthropicMessages;
|
|
228
|
+
export type LLMResponse = OpenAIResponse | BedrockAnthropicResponse;
|
|
229
|
+
|
|
230
|
+
// export type SupportedLLMs = OpenAISupportedLLMs | BedrockAnthropicSupportedLLMs;
|
|
231
|
+
|
|
232
|
+
export type SupportedLLMs =
|
|
233
|
+
| { type: "OpenAI"; model: OpenAISupportedLLMs }
|
|
234
|
+
| { type: "BedrockAnthropic"; model: BedrockAnthropicSupportedLLMs };
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Projects */
|
|
6
|
+
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
7
|
+
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
8
|
+
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
9
|
+
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
10
|
+
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
|
+
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
+
|
|
13
|
+
/* Language and Environment */
|
|
14
|
+
"target": "ES2015" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
|
15
|
+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
|
+
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
17
|
+
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
18
|
+
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
19
|
+
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
20
|
+
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
21
|
+
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
22
|
+
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
23
|
+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
24
|
+
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
25
|
+
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
26
|
+
|
|
27
|
+
/* Modules */
|
|
28
|
+
"module": "CommonJS" /* Specify what module code is generated. */,
|
|
29
|
+
"rootDir": "./src" /* Specify the root folder within your source files. */,
|
|
30
|
+
// "moduleResolution": "node10" /* Specify how TypeScript looks up a file from a given module specifier. */,
|
|
31
|
+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
32
|
+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
33
|
+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
34
|
+
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
35
|
+
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
36
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
37
|
+
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
38
|
+
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
39
|
+
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
40
|
+
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
41
|
+
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
42
|
+
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
|
|
43
|
+
"resolveJsonModule": true /* Enable importing .json files. */,
|
|
44
|
+
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
45
|
+
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
46
|
+
|
|
47
|
+
/* JavaScript Support */
|
|
48
|
+
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
49
|
+
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
50
|
+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
51
|
+
|
|
52
|
+
/* Emit */
|
|
53
|
+
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
54
|
+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
55
|
+
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
56
|
+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
57
|
+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
58
|
+
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
59
|
+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
60
|
+
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
|
|
61
|
+
// "removeComments": true, /* Disable emitting comments. */
|
|
62
|
+
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
63
|
+
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
64
|
+
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
65
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
66
|
+
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
67
|
+
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
68
|
+
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
69
|
+
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
70
|
+
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
71
|
+
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
72
|
+
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
73
|
+
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
74
|
+
|
|
75
|
+
/* Interop Constraints */
|
|
76
|
+
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
77
|
+
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
78
|
+
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
|
|
79
|
+
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
80
|
+
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
|
81
|
+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
82
|
+
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
|
83
|
+
|
|
84
|
+
/* Type Checking */
|
|
85
|
+
"strict": true /* Enable all strict type-checking options. */,
|
|
86
|
+
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
87
|
+
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
88
|
+
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
89
|
+
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
90
|
+
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
91
|
+
// "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
|
|
92
|
+
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
93
|
+
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
94
|
+
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
95
|
+
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
96
|
+
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
97
|
+
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
98
|
+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
99
|
+
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
100
|
+
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
101
|
+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
102
|
+
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
103
|
+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
104
|
+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
105
|
+
|
|
106
|
+
/* Completeness */
|
|
107
|
+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
108
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
109
|
+
}
|
|
110
|
+
}
|