@ampt/ai 1.0.0 → 1.0.1
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/index.cjs +27 -9
- package/dist/index.d.ts +13 -5
- package/dist/index.js +23 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -15137,9 +15137,12 @@ var init_dist_es53 = __esm({
|
|
|
15137
15137
|
// src/index.ts
|
|
15138
15138
|
var src_exports = {};
|
|
15139
15139
|
__export(src_exports, {
|
|
15140
|
+
ChatMessage: () => ChatMessage,
|
|
15141
|
+
bedrock: () => bedrock,
|
|
15140
15142
|
buildPrompt: () => buildPrompt,
|
|
15141
15143
|
chat: () => chat,
|
|
15142
|
-
|
|
15144
|
+
invoke: () => invoke2,
|
|
15145
|
+
models: () => models
|
|
15143
15146
|
});
|
|
15144
15147
|
module.exports = __toCommonJS(src_exports);
|
|
15145
15148
|
|
|
@@ -24887,11 +24890,13 @@ function credentialsProvider() {
|
|
|
24887
24890
|
};
|
|
24888
24891
|
}
|
|
24889
24892
|
|
|
24890
|
-
// src/
|
|
24893
|
+
// src/bedrock.ts
|
|
24891
24894
|
var region = process.env.AWS_REGION ?? "us-east-1";
|
|
24892
24895
|
var bedrockRegion = region.startsWith("us-west") ? "us-west-2" : region.startsWith("ap-south") ? "ap-southeast-1" : region.startsWith("ap-north") ? "ap-northeast-1" : region.startsWith("eu-") ? "eu-central-1" : "us-east-1";
|
|
24893
24896
|
var bedrock = new BedrockRuntime({ credentialDefaultProvider: credentialsProvider, region: bedrockRegion });
|
|
24894
|
-
|
|
24897
|
+
|
|
24898
|
+
// src/invoke.ts
|
|
24899
|
+
async function invoke2(options) {
|
|
24895
24900
|
const body = {
|
|
24896
24901
|
prompt: options.prompt,
|
|
24897
24902
|
max_tokens_to_sample: options.maxTokens ?? 50
|
|
@@ -24905,7 +24910,6 @@ async function invokeModel(options) {
|
|
|
24905
24910
|
if (!result.body) {
|
|
24906
24911
|
throw new Error("Failed to invoke model");
|
|
24907
24912
|
}
|
|
24908
|
-
const decoder = new TextDecoder();
|
|
24909
24913
|
const iterator = result.body[Symbol.asyncIterator]();
|
|
24910
24914
|
return new ReadableStream({
|
|
24911
24915
|
async pull(controller) {
|
|
@@ -24917,11 +24921,13 @@ async function invokeModel(options) {
|
|
|
24917
24921
|
console.warn("Error in LLM response stream:", value);
|
|
24918
24922
|
return;
|
|
24919
24923
|
}
|
|
24920
|
-
controller.enqueue(
|
|
24924
|
+
controller.enqueue(value.chunk.bytes);
|
|
24921
24925
|
}
|
|
24922
24926
|
}
|
|
24923
24927
|
});
|
|
24924
24928
|
}
|
|
24929
|
+
|
|
24930
|
+
// src/chat.ts
|
|
24925
24931
|
var ChatMessage = class {
|
|
24926
24932
|
role;
|
|
24927
24933
|
content;
|
|
@@ -24942,24 +24948,36 @@ function buildPrompt(messages) {
|
|
|
24942
24948
|
|
|
24943
24949
|
${titleCase(message.role)}: ${message.content}`).join("");
|
|
24944
24950
|
}
|
|
24951
|
+
var decoder = new TextDecoder();
|
|
24945
24952
|
async function chat(messages, options = {}) {
|
|
24946
24953
|
const transformer = new TransformStream({
|
|
24947
|
-
transform(
|
|
24954
|
+
transform(chunk, controller) {
|
|
24955
|
+
const event = JSON.parse(decoder.decode(chunk));
|
|
24948
24956
|
if (event.completion) {
|
|
24949
24957
|
controller.enqueue(event.completion);
|
|
24950
24958
|
}
|
|
24951
24959
|
}
|
|
24952
24960
|
});
|
|
24953
24961
|
const prompt = buildPrompt(messages);
|
|
24954
|
-
const response = await
|
|
24962
|
+
const response = await invoke2({ prompt, maxTokens: options.maxTokens ?? 1e3, modelId: options.modelId });
|
|
24955
24963
|
return response.pipeThrough(transformer);
|
|
24956
24964
|
}
|
|
24957
|
-
chat.models =
|
|
24965
|
+
chat.models = async () => {
|
|
24966
|
+
return ["anthropic.claude-v1", "anthropic.claude-instant-v1", "anthropic.claude-v2"];
|
|
24967
|
+
};
|
|
24968
|
+
|
|
24969
|
+
// src/models.ts
|
|
24970
|
+
async function models() {
|
|
24971
|
+
return ["anthropic.claude-v1", "anthropic.claude-instant-v1", "anthropic.claude-v2"];
|
|
24972
|
+
}
|
|
24958
24973
|
// Annotate the CommonJS export names for ESM import in node:
|
|
24959
24974
|
0 && (module.exports = {
|
|
24975
|
+
ChatMessage,
|
|
24976
|
+
bedrock,
|
|
24960
24977
|
buildPrompt,
|
|
24961
24978
|
chat,
|
|
24962
|
-
|
|
24979
|
+
invoke,
|
|
24980
|
+
models
|
|
24963
24981
|
});
|
|
24964
24982
|
/*! Bundled license information:
|
|
24965
24983
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import { BedrockRuntime } from '@aws-sdk/client-bedrock-runtime';
|
|
2
|
+
|
|
3
|
+
interface InvokeOptions {
|
|
2
4
|
prompt: string;
|
|
3
5
|
maxTokens?: number;
|
|
4
6
|
modelId?: string;
|
|
5
7
|
}
|
|
6
|
-
type ModelId = 'anthropic.claude-v2' | 'anthropic.claude-instant-v1' | 'anthropic.claude-v1';
|
|
7
8
|
/**
|
|
8
9
|
* Invoke model and return events as a ReadableStream.
|
|
9
10
|
* @param options
|
|
10
11
|
* @returns
|
|
11
12
|
*/
|
|
12
|
-
declare function
|
|
13
|
+
declare function invoke(options: InvokeOptions): Promise<ReadableStream<any>>;
|
|
14
|
+
|
|
15
|
+
type ModelId = 'anthropic.claude-v2' | 'anthropic.claude-instant-v1' | 'anthropic.claude-v1';
|
|
16
|
+
declare function models(): Promise<ModelId[]>;
|
|
17
|
+
|
|
13
18
|
type MessageRole = 'assistant' | 'human';
|
|
14
19
|
/**
|
|
15
20
|
* A message to send to the model
|
|
@@ -27,6 +32,7 @@ declare class ChatMessage {
|
|
|
27
32
|
declare function buildPrompt(messages: ChatMessage[]): string;
|
|
28
33
|
interface ChatOptions {
|
|
29
34
|
modelId?: ModelId;
|
|
35
|
+
maxTokens?: number;
|
|
30
36
|
}
|
|
31
37
|
/**
|
|
32
38
|
* Send messages to the model and return the completion
|
|
@@ -35,7 +41,9 @@ interface ChatOptions {
|
|
|
35
41
|
*/
|
|
36
42
|
declare function chat(messages: ChatMessage[], options?: ChatOptions): Promise<ReadableStream<any>>;
|
|
37
43
|
declare namespace chat {
|
|
38
|
-
var models: ModelId[]
|
|
44
|
+
var models: () => Promise<ModelId[]>;
|
|
39
45
|
}
|
|
40
46
|
|
|
41
|
-
|
|
47
|
+
declare const bedrock: BedrockRuntime;
|
|
48
|
+
|
|
49
|
+
export { ChatMessage, ChatOptions, InvokeOptions, MessageRole, ModelId, bedrock, buildPrompt, chat, invoke, models };
|
package/dist/index.js
CHANGED
|
@@ -12223,11 +12223,13 @@ function credentialsProvider() {
|
|
|
12223
12223
|
};
|
|
12224
12224
|
}
|
|
12225
12225
|
|
|
12226
|
-
// src/
|
|
12226
|
+
// src/bedrock.ts
|
|
12227
12227
|
var region = process.env.AWS_REGION ?? "us-east-1";
|
|
12228
12228
|
var bedrockRegion = region.startsWith("us-west") ? "us-west-2" : region.startsWith("ap-south") ? "ap-southeast-1" : region.startsWith("ap-north") ? "ap-northeast-1" : region.startsWith("eu-") ? "eu-central-1" : "us-east-1";
|
|
12229
12229
|
var bedrock = new BedrockRuntime({ credentialDefaultProvider: credentialsProvider, region: bedrockRegion });
|
|
12230
|
-
|
|
12230
|
+
|
|
12231
|
+
// src/invoke.ts
|
|
12232
|
+
async function invoke2(options) {
|
|
12231
12233
|
const body = {
|
|
12232
12234
|
prompt: options.prompt,
|
|
12233
12235
|
max_tokens_to_sample: options.maxTokens ?? 50
|
|
@@ -12241,7 +12243,6 @@ async function invokeModel(options) {
|
|
|
12241
12243
|
if (!result.body) {
|
|
12242
12244
|
throw new Error("Failed to invoke model");
|
|
12243
12245
|
}
|
|
12244
|
-
const decoder = new TextDecoder();
|
|
12245
12246
|
const iterator = result.body[Symbol.asyncIterator]();
|
|
12246
12247
|
return new ReadableStream({
|
|
12247
12248
|
async pull(controller) {
|
|
@@ -12253,11 +12254,13 @@ async function invokeModel(options) {
|
|
|
12253
12254
|
console.warn("Error in LLM response stream:", value);
|
|
12254
12255
|
return;
|
|
12255
12256
|
}
|
|
12256
|
-
controller.enqueue(
|
|
12257
|
+
controller.enqueue(value.chunk.bytes);
|
|
12257
12258
|
}
|
|
12258
12259
|
}
|
|
12259
12260
|
});
|
|
12260
12261
|
}
|
|
12262
|
+
|
|
12263
|
+
// src/chat.ts
|
|
12261
12264
|
var ChatMessage = class {
|
|
12262
12265
|
role;
|
|
12263
12266
|
content;
|
|
@@ -12278,23 +12281,35 @@ function buildPrompt(messages) {
|
|
|
12278
12281
|
|
|
12279
12282
|
${titleCase(message.role)}: ${message.content}`).join("");
|
|
12280
12283
|
}
|
|
12284
|
+
var decoder = new TextDecoder();
|
|
12281
12285
|
async function chat(messages, options = {}) {
|
|
12282
12286
|
const transformer = new TransformStream({
|
|
12283
|
-
transform(
|
|
12287
|
+
transform(chunk, controller) {
|
|
12288
|
+
const event = JSON.parse(decoder.decode(chunk));
|
|
12284
12289
|
if (event.completion) {
|
|
12285
12290
|
controller.enqueue(event.completion);
|
|
12286
12291
|
}
|
|
12287
12292
|
}
|
|
12288
12293
|
});
|
|
12289
12294
|
const prompt = buildPrompt(messages);
|
|
12290
|
-
const response = await
|
|
12295
|
+
const response = await invoke2({ prompt, maxTokens: options.maxTokens ?? 1e3, modelId: options.modelId });
|
|
12291
12296
|
return response.pipeThrough(transformer);
|
|
12292
12297
|
}
|
|
12293
|
-
chat.models =
|
|
12298
|
+
chat.models = async () => {
|
|
12299
|
+
return ["anthropic.claude-v1", "anthropic.claude-instant-v1", "anthropic.claude-v2"];
|
|
12300
|
+
};
|
|
12301
|
+
|
|
12302
|
+
// src/models.ts
|
|
12303
|
+
async function models() {
|
|
12304
|
+
return ["anthropic.claude-v1", "anthropic.claude-instant-v1", "anthropic.claude-v2"];
|
|
12305
|
+
}
|
|
12294
12306
|
export {
|
|
12307
|
+
ChatMessage,
|
|
12308
|
+
bedrock,
|
|
12295
12309
|
buildPrompt,
|
|
12296
12310
|
chat,
|
|
12297
|
-
|
|
12311
|
+
invoke2 as invoke,
|
|
12312
|
+
models
|
|
12298
12313
|
};
|
|
12299
12314
|
/*! Bundled license information:
|
|
12300
12315
|
|