@ampt/ai 2.0.6 → 2.1.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/index.cjs +255 -43
- package/dist/index.d.cts +5 -59
- package/dist/index.d.ts +5 -59
- package/dist/index.js +255 -43
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20196,7 +20196,7 @@ function request(url, options) {
|
|
|
20196
20196
|
resolve(result);
|
|
20197
20197
|
}
|
|
20198
20198
|
};
|
|
20199
|
-
const req = import_https.default.request(url, { agent }, (res) => {
|
|
20199
|
+
const req = import_https.default.request(url, { agent, headers: options.headers }, (res) => {
|
|
20200
20200
|
const bufs = [];
|
|
20201
20201
|
res.on("data", (data) => bufs.push(data));
|
|
20202
20202
|
res.on("end", () => {
|
|
@@ -44548,6 +44548,66 @@ var modelInfoMap = {
|
|
|
44548
44548
|
return (json?.inputTextTokenCount ?? 0) * 10;
|
|
44549
44549
|
}
|
|
44550
44550
|
},
|
|
44551
|
+
"amazon.titan-embed-text-v2:0": {
|
|
44552
|
+
name: "Amazon Titan Embeddings V2",
|
|
44553
|
+
type: "embeddings" /* Embeddings */,
|
|
44554
|
+
streaming: false,
|
|
44555
|
+
provider: "Amazon",
|
|
44556
|
+
description: "",
|
|
44557
|
+
version: "v2",
|
|
44558
|
+
inferenceUsage: (body) => {
|
|
44559
|
+
const json = JSON.parse(Buffer.from(body).toString());
|
|
44560
|
+
return (json?.inputTextTokenCount ?? 0) * 2;
|
|
44561
|
+
}
|
|
44562
|
+
},
|
|
44563
|
+
"amazon.titan-text-express-v1": {
|
|
44564
|
+
name: "Amazon Titan Text Express",
|
|
44565
|
+
type: "language" /* Language */,
|
|
44566
|
+
streaming: true,
|
|
44567
|
+
provider: "Amazon",
|
|
44568
|
+
description: "",
|
|
44569
|
+
version: "v1.x",
|
|
44570
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
44571
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 20 + outputSize / AVERAGE_BYTES_PER_TOKEN * 60);
|
|
44572
|
+
}
|
|
44573
|
+
},
|
|
44574
|
+
"amazon.titan-text-lite-v1": {
|
|
44575
|
+
name: "Amazon Titan Text Lite",
|
|
44576
|
+
type: "language" /* Language */,
|
|
44577
|
+
streaming: true,
|
|
44578
|
+
provider: "Amazon",
|
|
44579
|
+
description: "",
|
|
44580
|
+
version: "v1.x",
|
|
44581
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
44582
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 15 + outputSize / AVERAGE_BYTES_PER_TOKEN * 20);
|
|
44583
|
+
}
|
|
44584
|
+
},
|
|
44585
|
+
"amazon.titan-text-premier-v1:0": {
|
|
44586
|
+
name: "Amazon Titan Text Premier",
|
|
44587
|
+
type: "language" /* Language */,
|
|
44588
|
+
streaming: true,
|
|
44589
|
+
provider: "Amazon",
|
|
44590
|
+
description: "",
|
|
44591
|
+
version: "v1.x",
|
|
44592
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
44593
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 50 + outputSize / AVERAGE_BYTES_PER_TOKEN * 150);
|
|
44594
|
+
}
|
|
44595
|
+
},
|
|
44596
|
+
// WIP: Need to change the interface
|
|
44597
|
+
// 'amazon.titan-image-generator-v1': {
|
|
44598
|
+
// name: 'Amazon: Titan Image Generator G1',
|
|
44599
|
+
// type: ModelType.Image,
|
|
44600
|
+
// streaming: false,
|
|
44601
|
+
// provider: 'Amazon',
|
|
44602
|
+
// description:
|
|
44603
|
+
// '',
|
|
44604
|
+
// version: '1.x',
|
|
44605
|
+
// inferenceUsage: (width: number, height: number, steps: number) => {
|
|
44606
|
+
// const large = width * height > 512 * 512
|
|
44607
|
+
// const highQuality = steps > 50
|
|
44608
|
+
// return Math.round((large ? 3600000 : 1800000) * (highQuality ? 2 : 1))
|
|
44609
|
+
// }
|
|
44610
|
+
// },
|
|
44551
44611
|
"anthropic.claude-instant-v1": {
|
|
44552
44612
|
name: "Claude Instant",
|
|
44553
44613
|
type: "language" /* Language */,
|
|
@@ -44556,29 +44616,64 @@ var modelInfoMap = {
|
|
|
44556
44616
|
description: "A faster and cheaper yet still very capable model, which can handle a range of tasks including casual dialogue, text analysis, summarization, and document question-answering.",
|
|
44557
44617
|
version: "v1.2",
|
|
44558
44618
|
inferenceUsage: (inputSize, outputSize) => {
|
|
44559
|
-
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN *
|
|
44619
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 80 + outputSize / AVERAGE_BYTES_PER_TOKEN * 240);
|
|
44560
44620
|
}
|
|
44561
44621
|
},
|
|
44562
|
-
"anthropic.claude-
|
|
44622
|
+
"anthropic.claude-v2": {
|
|
44563
44623
|
name: "Claude",
|
|
44564
44624
|
type: "language" /* Language */,
|
|
44565
44625
|
streaming: true,
|
|
44566
44626
|
provider: "Anthropic",
|
|
44567
|
-
description: "
|
|
44568
|
-
version: "
|
|
44627
|
+
description: "Anthropic's most powerful model, which excels at a wide range of tasks from sophisticated dialogue and creative content generation to detailed instruction following.",
|
|
44628
|
+
version: "v2.0",
|
|
44569
44629
|
inferenceUsage: (inputSize, outputSize) => {
|
|
44570
|
-
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN *
|
|
44630
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 800 + outputSize / AVERAGE_BYTES_PER_TOKEN * 2400);
|
|
44571
44631
|
}
|
|
44572
44632
|
},
|
|
44573
|
-
"anthropic.claude-v2": {
|
|
44633
|
+
"anthropic.claude-v2:1": {
|
|
44574
44634
|
name: "Claude",
|
|
44575
44635
|
type: "language" /* Language */,
|
|
44576
44636
|
streaming: true,
|
|
44577
44637
|
provider: "Anthropic",
|
|
44578
44638
|
description: "Anthropic's most powerful model, which excels at a wide range of tasks from sophisticated dialogue and creative content generation to detailed instruction following.",
|
|
44579
|
-
version: "v2",
|
|
44639
|
+
version: "v2.1",
|
|
44640
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
44641
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 800 + outputSize / AVERAGE_BYTES_PER_TOKEN * 2400);
|
|
44642
|
+
}
|
|
44643
|
+
},
|
|
44644
|
+
"anthropic.claude-3-sonnet-20240229-v1:0": {
|
|
44645
|
+
name: "Claude 3 Sonnet",
|
|
44646
|
+
type: "language" /* Language */,
|
|
44647
|
+
streaming: true,
|
|
44648
|
+
provider: "Anthropic",
|
|
44649
|
+
description: "",
|
|
44650
|
+
version: "v1.0",
|
|
44651
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
44652
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 300 + outputSize / AVERAGE_BYTES_PER_TOKEN * 1500);
|
|
44653
|
+
}
|
|
44654
|
+
},
|
|
44655
|
+
"anthropic.claude-3-haiku-20240307-v1:0": {
|
|
44656
|
+
name: "Claude 3 Haiku",
|
|
44657
|
+
type: "language" /* Language */,
|
|
44658
|
+
streaming: true,
|
|
44659
|
+
provider: "Anthropic",
|
|
44660
|
+
description: "",
|
|
44661
|
+
version: "v1.0",
|
|
44662
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
44663
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 25 + outputSize / AVERAGE_BYTES_PER_TOKEN * 125);
|
|
44664
|
+
}
|
|
44665
|
+
},
|
|
44666
|
+
"anthropic.claude-3-opus-20240229-v1:0": {
|
|
44667
|
+
name: "Claude 3 Opus",
|
|
44668
|
+
region: "us-west-2",
|
|
44669
|
+
// as of 5/10/2024, this is the only region that supports this model
|
|
44670
|
+
type: "language" /* Language */,
|
|
44671
|
+
streaming: true,
|
|
44672
|
+
provider: "Anthropic",
|
|
44673
|
+
description: "",
|
|
44674
|
+
version: "v1.0",
|
|
44580
44675
|
inferenceUsage: (inputSize, outputSize) => {
|
|
44581
|
-
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN *
|
|
44676
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 1500 + outputSize / AVERAGE_BYTES_PER_TOKEN * 7500);
|
|
44582
44677
|
}
|
|
44583
44678
|
},
|
|
44584
44679
|
"cohere.command-text-v14": {
|
|
@@ -44638,25 +44733,56 @@ var modelInfoMap = {
|
|
|
44638
44733
|
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 75 + outputSize / AVERAGE_BYTES_PER_TOKEN * 100);
|
|
44639
44734
|
}
|
|
44640
44735
|
},
|
|
44641
|
-
"
|
|
44736
|
+
"meta.llama2-70b-chat-v1": {
|
|
44737
|
+
name: "Meta Llama 2 Chat (70B)",
|
|
44738
|
+
type: "language" /* Language */,
|
|
44739
|
+
streaming: true,
|
|
44740
|
+
provider: "Meta",
|
|
44741
|
+
description: "",
|
|
44742
|
+
version: "v1",
|
|
44743
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
44744
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 195 + outputSize / AVERAGE_BYTES_PER_TOKEN * 256);
|
|
44745
|
+
}
|
|
44746
|
+
},
|
|
44747
|
+
"meta.llama3-8b-instruct-v1:0": {
|
|
44748
|
+
name: "Meta Llama 3 Instruct (8B)",
|
|
44749
|
+
type: "language" /* Language */,
|
|
44750
|
+
streaming: true,
|
|
44751
|
+
provider: "Meta",
|
|
44752
|
+
description: "",
|
|
44753
|
+
version: "v1.x",
|
|
44754
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
44755
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 40 + outputSize / AVERAGE_BYTES_PER_TOKEN * 60);
|
|
44756
|
+
}
|
|
44757
|
+
},
|
|
44758
|
+
"meta.llama3-70b-instruct-v1:0": {
|
|
44759
|
+
name: "Meta Llama 3 Instruct (70B)",
|
|
44760
|
+
type: "language" /* Language */,
|
|
44761
|
+
streaming: true,
|
|
44762
|
+
provider: "Meta",
|
|
44763
|
+
description: "",
|
|
44764
|
+
version: "v1.x",
|
|
44765
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
44766
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 265 + outputSize / AVERAGE_BYTES_PER_TOKEN * 350);
|
|
44767
|
+
}
|
|
44768
|
+
},
|
|
44769
|
+
"stability.stable-diffusion-xl-v1": {
|
|
44642
44770
|
name: "Stable Diffusion XL",
|
|
44643
44771
|
type: "image" /* Image */,
|
|
44644
44772
|
streaming: false,
|
|
44645
44773
|
provider: "Stability AI",
|
|
44646
44774
|
description: "Deep learning, text-to-image model used to generate detailed images conditioned on text descriptions, inpainting, outpainting, and generating image-to-image translations.",
|
|
44647
|
-
version: "
|
|
44775
|
+
version: "v1.x",
|
|
44648
44776
|
inferenceUsage: (width, height, steps) => {
|
|
44649
|
-
const large = width * height > 512 * 512;
|
|
44650
44777
|
const highQuality = steps > 50;
|
|
44651
|
-
return Math.round(
|
|
44778
|
+
return Math.round(4e6 * (highQuality ? 2 : 1));
|
|
44652
44779
|
}
|
|
44653
44780
|
},
|
|
44654
44781
|
"mistral.mistral-7b-instruct-v0:2": {
|
|
44655
44782
|
name: "Mistral Instruct (7B)",
|
|
44656
|
-
region:
|
|
44657
|
-
// at time of writing, this is the only region that supports this model
|
|
44783
|
+
// region: 'us-west-2',
|
|
44658
44784
|
type: "language" /* Language */,
|
|
44659
|
-
streaming:
|
|
44785
|
+
streaming: true,
|
|
44660
44786
|
provider: "Mistral",
|
|
44661
44787
|
description: "First foundation model from MistralAI. Ideal for text summarization, question and answering, text classification, text completion, and code generation.",
|
|
44662
44788
|
version: "v0.2",
|
|
@@ -44666,16 +44792,27 @@ var modelInfoMap = {
|
|
|
44666
44792
|
},
|
|
44667
44793
|
"mistral.mixtral-8x7b-instruct-v0:1": {
|
|
44668
44794
|
name: "MixTral Instruct (8x7B)",
|
|
44669
|
-
region:
|
|
44670
|
-
// at time of writing, this is the only region that supports this model
|
|
44795
|
+
// region: 'us-west-2',
|
|
44671
44796
|
type: "language" /* Language */,
|
|
44672
|
-
streaming:
|
|
44797
|
+
streaming: true,
|
|
44673
44798
|
provider: "Mistral",
|
|
44674
44799
|
description: "Ideal for text summarization, question and answering, text classification, text completion, and code generation.",
|
|
44675
44800
|
version: "v0.1",
|
|
44676
44801
|
inferenceUsage: (inputSize, outputSize) => {
|
|
44677
44802
|
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 45 + outputSize / AVERAGE_BYTES_PER_TOKEN * 70);
|
|
44678
44803
|
}
|
|
44804
|
+
},
|
|
44805
|
+
"mistral.mistral-large-2402-v1:0": {
|
|
44806
|
+
name: "Mistral Large",
|
|
44807
|
+
// region: 'us-west-2',
|
|
44808
|
+
type: "language" /* Language */,
|
|
44809
|
+
streaming: true,
|
|
44810
|
+
provider: "Mistral",
|
|
44811
|
+
description: "Ideal for text summarization, question and answering, text classification, text completion, and code generation.",
|
|
44812
|
+
version: "v0.1",
|
|
44813
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
44814
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 800 + outputSize / AVERAGE_BYTES_PER_TOKEN * 2400);
|
|
44815
|
+
}
|
|
44679
44816
|
}
|
|
44680
44817
|
};
|
|
44681
44818
|
function getModelInfo(id) {
|
|
@@ -44807,8 +44944,39 @@ var AnthropicClaudeChatAdapter = class {
|
|
|
44807
44944
|
}
|
|
44808
44945
|
};
|
|
44809
44946
|
|
|
44810
|
-
// src/chat/adapters/
|
|
44947
|
+
// src/chat/adapters/anthropic.claude.sonnet.ts
|
|
44811
44948
|
var decoder2 = new TextDecoder();
|
|
44949
|
+
var AnthropicClaudeSonnetChatAdapter = class {
|
|
44950
|
+
async buildInput(messages, options) {
|
|
44951
|
+
return {
|
|
44952
|
+
system: "You are a helpful virtual assistant. Please answer the user's questions and/or carry the conversation forward, abiding by the user's instructions.",
|
|
44953
|
+
messages: messages.map((message) => ({
|
|
44954
|
+
// Sonnet uses `user` instead of `human` for the user role.
|
|
44955
|
+
role: message.role === "human" ? "user" : message.role,
|
|
44956
|
+
content: message.content
|
|
44957
|
+
})),
|
|
44958
|
+
max_tokens: options.maxTokens ?? 1e3,
|
|
44959
|
+
anthropic_version: "bedrock-2023-05-31"
|
|
44960
|
+
};
|
|
44961
|
+
}
|
|
44962
|
+
formatResponse(response) {
|
|
44963
|
+
if (!response.body) {
|
|
44964
|
+
throw new Error("No response from model");
|
|
44965
|
+
}
|
|
44966
|
+
const transformer = new TransformStream({
|
|
44967
|
+
transform(chunk2, controller) {
|
|
44968
|
+
const event = JSON.parse(decoder2.decode(chunk2));
|
|
44969
|
+
if (event.type === "content_block_delta" && event.delta.type === "text_delta" && event.delta.text) {
|
|
44970
|
+
controller.enqueue(Buffer.from(event.delta.text, "utf8"));
|
|
44971
|
+
}
|
|
44972
|
+
}
|
|
44973
|
+
});
|
|
44974
|
+
return response.body.pipeThrough(transformer);
|
|
44975
|
+
}
|
|
44976
|
+
};
|
|
44977
|
+
|
|
44978
|
+
// src/chat/adapters/ai21.jurassic.ts
|
|
44979
|
+
var decoder3 = new TextDecoder();
|
|
44812
44980
|
function buildPrompt2(messages) {
|
|
44813
44981
|
const messagesCopy = [...messages];
|
|
44814
44982
|
if (messagesCopy.length === 0 || messagesCopy[messagesCopy.length - 1].role !== "assistant") {
|
|
@@ -44865,7 +45033,7 @@ var Ai21JurassicChatAdapter = class {
|
|
|
44865
45033
|
}
|
|
44866
45034
|
const transformer = new TransformStream({
|
|
44867
45035
|
transform(chunk2, controller) {
|
|
44868
|
-
const event = JSON.parse(
|
|
45036
|
+
const event = JSON.parse(decoder3.decode(chunk2));
|
|
44869
45037
|
for (const completion of event.completions) {
|
|
44870
45038
|
controller.enqueue(Buffer.from(completion.data.text, "utf8"));
|
|
44871
45039
|
}
|
|
@@ -44876,7 +45044,7 @@ var Ai21JurassicChatAdapter = class {
|
|
|
44876
45044
|
};
|
|
44877
45045
|
|
|
44878
45046
|
// src/chat/adapters/cohere.command.ts
|
|
44879
|
-
var
|
|
45047
|
+
var decoder4 = new TextDecoder();
|
|
44880
45048
|
function buildPrompt3(messages) {
|
|
44881
45049
|
const messagesCopy = [...messages];
|
|
44882
45050
|
if (messagesCopy.length === 0 || messagesCopy[messagesCopy.length - 1].role !== "assistant") {
|
|
@@ -44903,7 +45071,7 @@ var CohereCommandChatAdapter = class {
|
|
|
44903
45071
|
}
|
|
44904
45072
|
const transformer = new TransformStream({
|
|
44905
45073
|
transform(chunk2, controller) {
|
|
44906
|
-
const event = JSON.parse(
|
|
45074
|
+
const event = JSON.parse(decoder4.decode(chunk2));
|
|
44907
45075
|
if (event.text) {
|
|
44908
45076
|
controller.enqueue(Buffer.from(event.text, "utf8"));
|
|
44909
45077
|
}
|
|
@@ -44914,7 +45082,7 @@ var CohereCommandChatAdapter = class {
|
|
|
44914
45082
|
};
|
|
44915
45083
|
|
|
44916
45084
|
// src/chat/adapters/meta.llama.ts
|
|
44917
|
-
var
|
|
45085
|
+
var decoder5 = new TextDecoder();
|
|
44918
45086
|
function buildPrompt4(messages) {
|
|
44919
45087
|
const messagesCopy = [...messages];
|
|
44920
45088
|
if (messagesCopy.length === 0 || messagesCopy[messagesCopy.length - 1].role !== "assistant") {
|
|
@@ -44940,7 +45108,7 @@ var MetaLlamaChatAdapter = class {
|
|
|
44940
45108
|
}
|
|
44941
45109
|
const transformer = new TransformStream({
|
|
44942
45110
|
transform(chunk2, controller) {
|
|
44943
|
-
const event = JSON.parse(
|
|
45111
|
+
const event = JSON.parse(decoder5.decode(chunk2));
|
|
44944
45112
|
if (event.generation) {
|
|
44945
45113
|
controller.enqueue(Buffer.from(event.generation, "utf8"));
|
|
44946
45114
|
}
|
|
@@ -44951,7 +45119,7 @@ var MetaLlamaChatAdapter = class {
|
|
|
44951
45119
|
};
|
|
44952
45120
|
|
|
44953
45121
|
// src/chat/adapters/mixtral.ts
|
|
44954
|
-
var
|
|
45122
|
+
var decoder6 = new TextDecoder();
|
|
44955
45123
|
function buildPrompt5(messages) {
|
|
44956
45124
|
const messagesCopy = [...messages];
|
|
44957
45125
|
if (messagesCopy.length === 0 || messagesCopy[messagesCopy.length - 1].role !== "assistant") {
|
|
@@ -44979,7 +45147,7 @@ var MixtralAIChatAdapter = class {
|
|
|
44979
45147
|
}
|
|
44980
45148
|
const transformer = new TransformStream({
|
|
44981
45149
|
transform(chunk2, controller) {
|
|
44982
|
-
const event = JSON.parse(
|
|
45150
|
+
const event = JSON.parse(decoder6.decode(chunk2));
|
|
44983
45151
|
if (event.outputs?.length) {
|
|
44984
45152
|
const output = event.outputs.map((o18) => o18.text).join("");
|
|
44985
45153
|
controller.enqueue(Buffer.from(output, "utf8"));
|
|
@@ -45001,15 +45169,21 @@ var ChatMessage = class {
|
|
|
45001
45169
|
};
|
|
45002
45170
|
var adapters = {
|
|
45003
45171
|
"anthropic.claude-instant-v1": AnthropicClaudeChatAdapter,
|
|
45004
|
-
"anthropic.claude-v1": AnthropicClaudeChatAdapter,
|
|
45005
45172
|
"anthropic.claude-v2": AnthropicClaudeChatAdapter,
|
|
45173
|
+
"anthropic.claude-3-sonnet-20240229-v1:0": AnthropicClaudeSonnetChatAdapter,
|
|
45174
|
+
"anthropic.claude-3-haiku-20240307-v1:0": AnthropicClaudeSonnetChatAdapter,
|
|
45175
|
+
"anthropic.claude-3-opus-20240229-v1:0": AnthropicClaudeSonnetChatAdapter,
|
|
45006
45176
|
"ai21.j2-mid-v1": Ai21JurassicChatAdapter,
|
|
45007
45177
|
"ai21.j2-ultra-v1": Ai21JurassicChatAdapter,
|
|
45008
45178
|
"cohere.command-text-v14": CohereCommandChatAdapter,
|
|
45009
45179
|
"cohere.command-light-text-v14": CohereCommandChatAdapter,
|
|
45010
45180
|
"meta.llama2-13b-chat-v1": MetaLlamaChatAdapter,
|
|
45181
|
+
"meta.llama2-70b-chat-v1": MetaLlamaChatAdapter,
|
|
45182
|
+
"meta.llama3-8b-instruct-v1:0": MetaLlamaChatAdapter,
|
|
45183
|
+
"meta.llama3-70b-instruct-v1:0": MetaLlamaChatAdapter,
|
|
45011
45184
|
"mistral.mistral-7b-instruct-v0:2": MixtralAIChatAdapter,
|
|
45012
|
-
"mistral.mixtral-8x7b-instruct-v0:1": MixtralAIChatAdapter
|
|
45185
|
+
"mistral.mixtral-8x7b-instruct-v0:1": MixtralAIChatAdapter,
|
|
45186
|
+
"mistral.mistral-large-2402-v1:0": MixtralAIChatAdapter
|
|
45013
45187
|
};
|
|
45014
45188
|
async function chat(messages, options = {}) {
|
|
45015
45189
|
const modelId = options.modelId ?? "anthropic.claude-instant-v1";
|
|
@@ -45025,15 +45199,21 @@ async function chat(messages, options = {}) {
|
|
|
45025
45199
|
chat.models = async () => {
|
|
45026
45200
|
return [
|
|
45027
45201
|
"anthropic.claude-instant-v1",
|
|
45028
|
-
"anthropic.claude-v1",
|
|
45029
45202
|
"anthropic.claude-v2",
|
|
45203
|
+
"anthropic.claude-3-sonnet-20240229-v1:0",
|
|
45204
|
+
"anthropic.claude-3-haiku-20240307-v1:0",
|
|
45205
|
+
"anthropic.claude-3-opus-20240229-v1:0",
|
|
45030
45206
|
"ai21.j2-mid-v1",
|
|
45031
45207
|
"ai21.j2-ultra-v1",
|
|
45032
45208
|
"cohere.command-text-v14",
|
|
45033
45209
|
"cohere.command-light-text-v14",
|
|
45034
45210
|
"meta.llama2-13b-chat-v1",
|
|
45211
|
+
"meta.llama2-70b-chat-v1",
|
|
45212
|
+
"meta.llama3-8b-instruct-v1:0",
|
|
45213
|
+
"meta.llama3-70b-instruct-v1:0",
|
|
45035
45214
|
"mistral.mistral-7b-instruct-v0:2",
|
|
45036
|
-
"mistral.mixtral-8x7b-instruct-v0:1"
|
|
45215
|
+
"mistral.mixtral-8x7b-instruct-v0:1",
|
|
45216
|
+
"mistral.mistral-large-2402-v1:0"
|
|
45037
45217
|
];
|
|
45038
45218
|
};
|
|
45039
45219
|
|
|
@@ -45067,11 +45247,12 @@ var CohereEmbedAdapter = class {
|
|
|
45067
45247
|
// src/embed/index.ts
|
|
45068
45248
|
var adapters2 = {
|
|
45069
45249
|
"amazon.titan-embed-text-v1": AmazonTitanEmbedTextAdapter,
|
|
45250
|
+
"amazon.titan-embed-text-v2:0": AmazonTitanEmbedTextAdapter,
|
|
45070
45251
|
"cohere.embed-english-v3": CohereEmbedAdapter,
|
|
45071
45252
|
"cohere.embed-multilingual-v3": CohereEmbedAdapter
|
|
45072
45253
|
};
|
|
45073
45254
|
async function embed(input, options = {}) {
|
|
45074
|
-
const modelId = options.modelId ?? "amazon.titan-embed-text-
|
|
45255
|
+
const modelId = options.modelId ?? "amazon.titan-embed-text-v2:0";
|
|
45075
45256
|
const AdapterClass = adapters2[modelId];
|
|
45076
45257
|
if (!AdapterClass) {
|
|
45077
45258
|
throw new Error(`No adapter found for model ${modelId}`);
|
|
@@ -45087,7 +45268,7 @@ embed.models = async () => {
|
|
|
45087
45268
|
|
|
45088
45269
|
// src/render.ts
|
|
45089
45270
|
async function render(prompt, options = {}) {
|
|
45090
|
-
const modelId = options.modelId ?? "stability.stable-diffusion-xl-
|
|
45271
|
+
const modelId = options.modelId ?? "stability.stable-diffusion-xl-v1";
|
|
45091
45272
|
const body = {
|
|
45092
45273
|
text_prompts: [
|
|
45093
45274
|
{
|
|
@@ -45097,8 +45278,8 @@ async function render(prompt, options = {}) {
|
|
|
45097
45278
|
cfg_scale: options.scale ?? 10,
|
|
45098
45279
|
seed: options.seed ?? 20,
|
|
45099
45280
|
steps: options.steps ?? 50,
|
|
45100
|
-
width: options.width ??
|
|
45101
|
-
height: options.height ??
|
|
45281
|
+
width: options.width ?? 1024,
|
|
45282
|
+
height: options.height ?? 1024
|
|
45102
45283
|
};
|
|
45103
45284
|
const response = await invoke2({ body, modelId });
|
|
45104
45285
|
if (!response.body) {
|
|
@@ -45114,11 +45295,40 @@ async function render(prompt, options = {}) {
|
|
|
45114
45295
|
return new Response(responseBody, { headers: { "Content-Type": "image/png" } });
|
|
45115
45296
|
}
|
|
45116
45297
|
render.models = async () => {
|
|
45117
|
-
return ["stability.stable-diffusion-xl-
|
|
45298
|
+
return ["stability.stable-diffusion-xl-v1"];
|
|
45299
|
+
};
|
|
45300
|
+
|
|
45301
|
+
// src/summarize/adapters/anthropic.claude.sonnet.ts
|
|
45302
|
+
var decoder7 = new TextDecoder();
|
|
45303
|
+
var AnthropicClaudeSonnetSummarizeAdapter = class {
|
|
45304
|
+
async buildInput(input, options) {
|
|
45305
|
+
return {
|
|
45306
|
+
// Sonnet varies from the original Claude model in that it does not take a prompt argument.
|
|
45307
|
+
// see https://github.com/langchain-ai/langchain/issues/18513
|
|
45308
|
+
system: "You are a helpful virtual assistant. Please summarize the bodies of text provided to you. Write only one or two paragraphs, and only include the summary, without any preamble or other text.",
|
|
45309
|
+
messages: [{ role: "user", content: input }],
|
|
45310
|
+
anthropic_version: "bedrock-2023-05-31",
|
|
45311
|
+
max_tokens: options.maxTokens ?? 1e3
|
|
45312
|
+
};
|
|
45313
|
+
}
|
|
45314
|
+
formatResponse(response) {
|
|
45315
|
+
if (!response.body) {
|
|
45316
|
+
throw new Error("No response from model");
|
|
45317
|
+
}
|
|
45318
|
+
const transformer = new TransformStream({
|
|
45319
|
+
transform(chunk2, controller) {
|
|
45320
|
+
const event = JSON.parse(decoder7.decode(chunk2));
|
|
45321
|
+
if (event.type === "content_block_delta" && event.delta.type === "text_delta" && event.delta.text) {
|
|
45322
|
+
controller.enqueue(Buffer.from(event.delta.text, "utf8"));
|
|
45323
|
+
}
|
|
45324
|
+
}
|
|
45325
|
+
});
|
|
45326
|
+
return response.body.pipeThrough(transformer);
|
|
45327
|
+
}
|
|
45118
45328
|
};
|
|
45119
45329
|
|
|
45120
45330
|
// src/summarize/adapters/anthropic.claude.ts
|
|
45121
|
-
var
|
|
45331
|
+
var decoder8 = new TextDecoder();
|
|
45122
45332
|
function buildPrompt6(input) {
|
|
45123
45333
|
return `Human: I'm going to give you a document. Then I'm going to ask you to summarize it. Here is the document:
|
|
45124
45334
|
|
|
@@ -45141,7 +45351,7 @@ var AnthropicClaudeSummarizeAdapter = class {
|
|
|
45141
45351
|
}
|
|
45142
45352
|
const transformer = new TransformStream({
|
|
45143
45353
|
transform(chunk2, controller) {
|
|
45144
|
-
const event = JSON.parse(
|
|
45354
|
+
const event = JSON.parse(decoder8.decode(chunk2));
|
|
45145
45355
|
if (event.completion) {
|
|
45146
45356
|
controller.enqueue(Buffer.from(event.completion, "utf8"));
|
|
45147
45357
|
}
|
|
@@ -45152,7 +45362,7 @@ var AnthropicClaudeSummarizeAdapter = class {
|
|
|
45152
45362
|
};
|
|
45153
45363
|
|
|
45154
45364
|
// src/summarize/adapters/mixtral.ts
|
|
45155
|
-
var
|
|
45365
|
+
var decoder9 = new TextDecoder();
|
|
45156
45366
|
function buildPrompt7(input) {
|
|
45157
45367
|
return `Human: I'm going to give you a document. Then I'm going to ask you to summarize it. Here is the document:
|
|
45158
45368
|
|
|
@@ -45177,7 +45387,7 @@ var MixtralAISummarizeAdapter = class {
|
|
|
45177
45387
|
}
|
|
45178
45388
|
const transformer = new TransformStream({
|
|
45179
45389
|
transform(chunk2, controller) {
|
|
45180
|
-
const event = JSON.parse(
|
|
45390
|
+
const event = JSON.parse(decoder9.decode(chunk2));
|
|
45181
45391
|
if (event.outputs?.length) {
|
|
45182
45392
|
const output = event.outputs.map((o18) => o18.text).join("");
|
|
45183
45393
|
controller.enqueue(Buffer.from(output, "utf8"));
|
|
@@ -45191,8 +45401,9 @@ var MixtralAISummarizeAdapter = class {
|
|
|
45191
45401
|
// src/summarize/index.ts
|
|
45192
45402
|
var adapters3 = {
|
|
45193
45403
|
"anthropic.claude-instant-v1": AnthropicClaudeSummarizeAdapter,
|
|
45194
|
-
|
|
45404
|
+
// 'anthropic.claude-v1': AnthropicClaudeSummarizeAdapter,
|
|
45195
45405
|
"anthropic.claude-v2": AnthropicClaudeSummarizeAdapter,
|
|
45406
|
+
"anthropic.claude-3-sonnet-20240229-v1:0": AnthropicClaudeSonnetSummarizeAdapter,
|
|
45196
45407
|
"mistral.mistral-7b-instruct-v0:2": MixtralAISummarizeAdapter,
|
|
45197
45408
|
"mistral.mixtral-8x7b-instruct-v0:1": MixtralAISummarizeAdapter
|
|
45198
45409
|
};
|
|
@@ -45210,8 +45421,9 @@ async function summarize(input, options = {}) {
|
|
|
45210
45421
|
summarize.models = async () => {
|
|
45211
45422
|
return [
|
|
45212
45423
|
"anthropic.claude-instant-v1",
|
|
45213
|
-
|
|
45424
|
+
// 'anthropic.claude-v1',
|
|
45214
45425
|
"anthropic.claude-v2",
|
|
45426
|
+
"anthropic.claude-3-sonnet-20240229-v1:0",
|
|
45215
45427
|
"mistral.mistral-7b-instruct-v0:2",
|
|
45216
45428
|
"mistral.mixtral-8x7b-instruct-v0:1"
|
|
45217
45429
|
];
|
|
@@ -55475,7 +55687,7 @@ async function translate(input, options) {
|
|
|
55475
55687
|
// src/index.ts
|
|
55476
55688
|
if (process.env.AMPT_RUNTIME_NAME === "nodejs18-beta") {
|
|
55477
55689
|
console.error(
|
|
55478
|
-
'@ampt/ai requires the nodejs18 runtime. Please add "runtime": "
|
|
55690
|
+
'@ampt/ai requires the nodejs18 runtime or higher. Please add "runtime": "nodejs20" to the "ampt" section of your package.json.'
|
|
55479
55691
|
);
|
|
55480
55692
|
}
|
|
55481
55693
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Translate } from '@aws-sdk/client-translate';
|
|
2
2
|
|
|
3
|
-
type ModelId = '
|
|
3
|
+
type ModelId = 'amazon.titan-text-express-v1' | 'amazon.titan-text-lite-v1' | 'amazon.titan-text-premier-v1:0' | 'amazon.titan-embed-text-v1' | 'amazon.titan-embed-text-v2:0' | 'anthropic.claude-v2' | 'anthropic.claude-v2:1' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'anthropic.claude-instant-v1' | 'ai21.j2-mid-v1' | 'ai21.j2-ultra-v1' | 'cohere.command-text-v14' | 'cohere.command-light-text-v14' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3' | 'meta.llama2-13b-chat-v1' | 'meta.llama2-70b-chat-v1' | 'meta.llama3-8b-instruct-v1:0' | 'meta.llama3-70b-instruct-v1:0' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1' | 'mistral.mistral-large-2402-v1:0' | 'stability.stable-diffusion-xl-v1';
|
|
4
4
|
declare function models(): Promise<string[]>;
|
|
5
5
|
declare enum ModelType {
|
|
6
6
|
Embeddings = "embeddings",
|
|
@@ -42,60 +42,6 @@ type ModelInfoMap = {
|
|
|
42
42
|
* Note: we track usage in micro-cents/uc (1,000,000ths of a cent, or 100,000,000ths of a dollar) because
|
|
43
43
|
* the quota system only works with integers.
|
|
44
44
|
*
|
|
45
|
-
* AI21 Jurassic-2 Mid:
|
|
46
|
-
* - $0.0125 per 1000 input tokens: 1250 uc per token
|
|
47
|
-
* - $0.0125 per 1000 output tokens: 1250 uc per token
|
|
48
|
-
*
|
|
49
|
-
* AI21 Jurassic-2 Ultra:
|
|
50
|
-
* - $0.0188 per 1000 input tokens: 1880 uc per token
|
|
51
|
-
* - $0.0188 per 1000 output tokens: 1880 uc per token
|
|
52
|
-
*
|
|
53
|
-
* Claude Instant:
|
|
54
|
-
* - $0.00163 per 1000 input tokens: 163 uc per token
|
|
55
|
-
* - $0.00551 per 1000 output tokens: 551 uc per token
|
|
56
|
-
*
|
|
57
|
-
* Claude:
|
|
58
|
-
* - $0.01102 per 1000 input tokens: 1102 uc per token
|
|
59
|
-
* - $0.03268 per 1000 output tokens: 3268 uc per token
|
|
60
|
-
*
|
|
61
|
-
* Cohere Command:
|
|
62
|
-
* - $0.0015 per 1000 input tokens: 150 uc per token
|
|
63
|
-
* - $0.0020 per 1000 output tokens: 200 uc per token
|
|
64
|
-
*
|
|
65
|
-
* Cohere Command Light:
|
|
66
|
-
* - $0.0003 per 1000 input tokens: 30 uc per token
|
|
67
|
-
* - $0.0006 per 1000 output tokens: 60 uc per token
|
|
68
|
-
*
|
|
69
|
-
* Cohere Embed - English:
|
|
70
|
-
* - $0.0001 for 1000 input tokens: 10 uc per token
|
|
71
|
-
*
|
|
72
|
-
* Cohere Embed - Multilingual:
|
|
73
|
-
* - $0.0001 for 1000 input tokens: 10 uc per token
|
|
74
|
-
*
|
|
75
|
-
* Meta Llama 2 Chat (13B):
|
|
76
|
-
* - $0.00075 per 1000 input tokens: 75 uc per token
|
|
77
|
-
* - $0.001 per 1000 output tokens: 100 uc per token
|
|
78
|
-
*
|
|
79
|
-
* Mistral 7B:
|
|
80
|
-
* - $.00015 per 1000 input tokens: 15 uc per token
|
|
81
|
-
* - $.0002 per 1000 output tokens: 20 uc per token
|
|
82
|
-
*
|
|
83
|
-
* MixTral 8x7B:
|
|
84
|
-
* - $0.00045 per 1000 input tokens: 45 uc per token
|
|
85
|
-
* - $0.0007 per 1000 output tokens: 70 uc per token
|
|
86
|
-
*
|
|
87
|
-
* Stable Diffusion XL:
|
|
88
|
-
*
|
|
89
|
-
* small format (512x512 or smaller):
|
|
90
|
-
* - standard quality: 1800000 per image
|
|
91
|
-
* - high quality: 3600000 per image
|
|
92
|
-
*
|
|
93
|
-
* large format (larger than 512x512):
|
|
94
|
-
* - standard quality: 3600000 per image (2x more expensive than small format)
|
|
95
|
-
* - high quality: 7200000 per image (2x more expensive than small format)
|
|
96
|
-
*
|
|
97
|
-
* Amazon Titan Embeddings:
|
|
98
|
-
* - $0.0001 for 1000 input tokens: 10 uc per token
|
|
99
45
|
*/
|
|
100
46
|
declare const modelInfoMap: ModelInfoMap;
|
|
101
47
|
declare function getModelInfo(id: ModelId): EmbeddingsModelInfo | LanguageModelInfo | ImageModelInfo;
|
|
@@ -113,7 +59,7 @@ interface InvokeOptions {
|
|
|
113
59
|
*/
|
|
114
60
|
declare function invoke(options: InvokeOptions): Promise<Response>;
|
|
115
61
|
|
|
116
|
-
type MessageRole = 'assistant' | 'human';
|
|
62
|
+
type MessageRole = 'assistant' | 'human' | 'user';
|
|
117
63
|
interface ResponseWithBody extends Response {
|
|
118
64
|
body: ReadableStream<any>;
|
|
119
65
|
}
|
|
@@ -134,7 +80,7 @@ interface ChatOptions {
|
|
|
134
80
|
modelId?: ChatModelId;
|
|
135
81
|
maxTokens?: number;
|
|
136
82
|
}
|
|
137
|
-
type ChatModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v1' | 'anthropic.claude-
|
|
83
|
+
type ChatModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v2' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'ai21.j2-mid-v1' | 'ai21.j2-ultra-v1' | 'cohere.command-text-v14' | 'cohere.command-light-text-v14' | 'meta.llama2-13b-chat-v1' | 'meta.llama2-70b-chat-v1' | 'meta.llama3-8b-instruct-v1:0' | 'meta.llama3-70b-instruct-v1:0' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1' | 'mistral.mistral-large-2402-v1:0';
|
|
138
84
|
/**
|
|
139
85
|
* Send messages to the model and return the completion
|
|
140
86
|
* @param messages Array of messages to send to the model
|
|
@@ -145,7 +91,7 @@ declare namespace chat {
|
|
|
145
91
|
var models: () => Promise<ModelId[]>;
|
|
146
92
|
}
|
|
147
93
|
|
|
148
|
-
type EmbedModelId = 'amazon.titan-embed-text-v1' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3';
|
|
94
|
+
type EmbedModelId = 'amazon.titan-embed-text-v1' | 'amazon.titan-embed-text-v2:0' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3';
|
|
149
95
|
type Embedding = number[];
|
|
150
96
|
interface EmbedOptions {
|
|
151
97
|
modelId?: EmbedModelId;
|
|
@@ -172,7 +118,7 @@ interface SummarizeOptions {
|
|
|
172
118
|
modelId?: SummarizeModelId;
|
|
173
119
|
maxTokens?: number;
|
|
174
120
|
}
|
|
175
|
-
type SummarizeModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-
|
|
121
|
+
type SummarizeModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v2' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1';
|
|
176
122
|
declare function summarize(input: string, options?: SummarizeOptions): Promise<Response>;
|
|
177
123
|
declare namespace summarize {
|
|
178
124
|
var models: () => Promise<ModelId[]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Translate } from '@aws-sdk/client-translate';
|
|
2
2
|
|
|
3
|
-
type ModelId = '
|
|
3
|
+
type ModelId = 'amazon.titan-text-express-v1' | 'amazon.titan-text-lite-v1' | 'amazon.titan-text-premier-v1:0' | 'amazon.titan-embed-text-v1' | 'amazon.titan-embed-text-v2:0' | 'anthropic.claude-v2' | 'anthropic.claude-v2:1' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'anthropic.claude-instant-v1' | 'ai21.j2-mid-v1' | 'ai21.j2-ultra-v1' | 'cohere.command-text-v14' | 'cohere.command-light-text-v14' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3' | 'meta.llama2-13b-chat-v1' | 'meta.llama2-70b-chat-v1' | 'meta.llama3-8b-instruct-v1:0' | 'meta.llama3-70b-instruct-v1:0' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1' | 'mistral.mistral-large-2402-v1:0' | 'stability.stable-diffusion-xl-v1';
|
|
4
4
|
declare function models(): Promise<string[]>;
|
|
5
5
|
declare enum ModelType {
|
|
6
6
|
Embeddings = "embeddings",
|
|
@@ -42,60 +42,6 @@ type ModelInfoMap = {
|
|
|
42
42
|
* Note: we track usage in micro-cents/uc (1,000,000ths of a cent, or 100,000,000ths of a dollar) because
|
|
43
43
|
* the quota system only works with integers.
|
|
44
44
|
*
|
|
45
|
-
* AI21 Jurassic-2 Mid:
|
|
46
|
-
* - $0.0125 per 1000 input tokens: 1250 uc per token
|
|
47
|
-
* - $0.0125 per 1000 output tokens: 1250 uc per token
|
|
48
|
-
*
|
|
49
|
-
* AI21 Jurassic-2 Ultra:
|
|
50
|
-
* - $0.0188 per 1000 input tokens: 1880 uc per token
|
|
51
|
-
* - $0.0188 per 1000 output tokens: 1880 uc per token
|
|
52
|
-
*
|
|
53
|
-
* Claude Instant:
|
|
54
|
-
* - $0.00163 per 1000 input tokens: 163 uc per token
|
|
55
|
-
* - $0.00551 per 1000 output tokens: 551 uc per token
|
|
56
|
-
*
|
|
57
|
-
* Claude:
|
|
58
|
-
* - $0.01102 per 1000 input tokens: 1102 uc per token
|
|
59
|
-
* - $0.03268 per 1000 output tokens: 3268 uc per token
|
|
60
|
-
*
|
|
61
|
-
* Cohere Command:
|
|
62
|
-
* - $0.0015 per 1000 input tokens: 150 uc per token
|
|
63
|
-
* - $0.0020 per 1000 output tokens: 200 uc per token
|
|
64
|
-
*
|
|
65
|
-
* Cohere Command Light:
|
|
66
|
-
* - $0.0003 per 1000 input tokens: 30 uc per token
|
|
67
|
-
* - $0.0006 per 1000 output tokens: 60 uc per token
|
|
68
|
-
*
|
|
69
|
-
* Cohere Embed - English:
|
|
70
|
-
* - $0.0001 for 1000 input tokens: 10 uc per token
|
|
71
|
-
*
|
|
72
|
-
* Cohere Embed - Multilingual:
|
|
73
|
-
* - $0.0001 for 1000 input tokens: 10 uc per token
|
|
74
|
-
*
|
|
75
|
-
* Meta Llama 2 Chat (13B):
|
|
76
|
-
* - $0.00075 per 1000 input tokens: 75 uc per token
|
|
77
|
-
* - $0.001 per 1000 output tokens: 100 uc per token
|
|
78
|
-
*
|
|
79
|
-
* Mistral 7B:
|
|
80
|
-
* - $.00015 per 1000 input tokens: 15 uc per token
|
|
81
|
-
* - $.0002 per 1000 output tokens: 20 uc per token
|
|
82
|
-
*
|
|
83
|
-
* MixTral 8x7B:
|
|
84
|
-
* - $0.00045 per 1000 input tokens: 45 uc per token
|
|
85
|
-
* - $0.0007 per 1000 output tokens: 70 uc per token
|
|
86
|
-
*
|
|
87
|
-
* Stable Diffusion XL:
|
|
88
|
-
*
|
|
89
|
-
* small format (512x512 or smaller):
|
|
90
|
-
* - standard quality: 1800000 per image
|
|
91
|
-
* - high quality: 3600000 per image
|
|
92
|
-
*
|
|
93
|
-
* large format (larger than 512x512):
|
|
94
|
-
* - standard quality: 3600000 per image (2x more expensive than small format)
|
|
95
|
-
* - high quality: 7200000 per image (2x more expensive than small format)
|
|
96
|
-
*
|
|
97
|
-
* Amazon Titan Embeddings:
|
|
98
|
-
* - $0.0001 for 1000 input tokens: 10 uc per token
|
|
99
45
|
*/
|
|
100
46
|
declare const modelInfoMap: ModelInfoMap;
|
|
101
47
|
declare function getModelInfo(id: ModelId): EmbeddingsModelInfo | LanguageModelInfo | ImageModelInfo;
|
|
@@ -113,7 +59,7 @@ interface InvokeOptions {
|
|
|
113
59
|
*/
|
|
114
60
|
declare function invoke(options: InvokeOptions): Promise<Response>;
|
|
115
61
|
|
|
116
|
-
type MessageRole = 'assistant' | 'human';
|
|
62
|
+
type MessageRole = 'assistant' | 'human' | 'user';
|
|
117
63
|
interface ResponseWithBody extends Response {
|
|
118
64
|
body: ReadableStream<any>;
|
|
119
65
|
}
|
|
@@ -134,7 +80,7 @@ interface ChatOptions {
|
|
|
134
80
|
modelId?: ChatModelId;
|
|
135
81
|
maxTokens?: number;
|
|
136
82
|
}
|
|
137
|
-
type ChatModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v1' | 'anthropic.claude-
|
|
83
|
+
type ChatModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v2' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'ai21.j2-mid-v1' | 'ai21.j2-ultra-v1' | 'cohere.command-text-v14' | 'cohere.command-light-text-v14' | 'meta.llama2-13b-chat-v1' | 'meta.llama2-70b-chat-v1' | 'meta.llama3-8b-instruct-v1:0' | 'meta.llama3-70b-instruct-v1:0' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1' | 'mistral.mistral-large-2402-v1:0';
|
|
138
84
|
/**
|
|
139
85
|
* Send messages to the model and return the completion
|
|
140
86
|
* @param messages Array of messages to send to the model
|
|
@@ -145,7 +91,7 @@ declare namespace chat {
|
|
|
145
91
|
var models: () => Promise<ModelId[]>;
|
|
146
92
|
}
|
|
147
93
|
|
|
148
|
-
type EmbedModelId = 'amazon.titan-embed-text-v1' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3';
|
|
94
|
+
type EmbedModelId = 'amazon.titan-embed-text-v1' | 'amazon.titan-embed-text-v2:0' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3';
|
|
149
95
|
type Embedding = number[];
|
|
150
96
|
interface EmbedOptions {
|
|
151
97
|
modelId?: EmbedModelId;
|
|
@@ -172,7 +118,7 @@ interface SummarizeOptions {
|
|
|
172
118
|
modelId?: SummarizeModelId;
|
|
173
119
|
maxTokens?: number;
|
|
174
120
|
}
|
|
175
|
-
type SummarizeModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-
|
|
121
|
+
type SummarizeModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v2' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1';
|
|
176
122
|
declare function summarize(input: string, options?: SummarizeOptions): Promise<Response>;
|
|
177
123
|
declare namespace summarize {
|
|
178
124
|
var models: () => Promise<ModelId[]>;
|
package/dist/index.js
CHANGED
|
@@ -7125,7 +7125,7 @@ function request(url, options) {
|
|
|
7125
7125
|
resolve(result);
|
|
7126
7126
|
}
|
|
7127
7127
|
};
|
|
7128
|
-
const req = https.request(url, { agent }, (res) => {
|
|
7128
|
+
const req = https.request(url, { agent, headers: options.headers }, (res) => {
|
|
7129
7129
|
const bufs = [];
|
|
7130
7130
|
res.on("data", (data) => bufs.push(data));
|
|
7131
7131
|
res.on("end", () => {
|
|
@@ -31366,6 +31366,66 @@ var modelInfoMap = {
|
|
|
31366
31366
|
return (json?.inputTextTokenCount ?? 0) * 10;
|
|
31367
31367
|
}
|
|
31368
31368
|
},
|
|
31369
|
+
"amazon.titan-embed-text-v2:0": {
|
|
31370
|
+
name: "Amazon Titan Embeddings V2",
|
|
31371
|
+
type: "embeddings" /* Embeddings */,
|
|
31372
|
+
streaming: false,
|
|
31373
|
+
provider: "Amazon",
|
|
31374
|
+
description: "",
|
|
31375
|
+
version: "v2",
|
|
31376
|
+
inferenceUsage: (body) => {
|
|
31377
|
+
const json = JSON.parse(Buffer.from(body).toString());
|
|
31378
|
+
return (json?.inputTextTokenCount ?? 0) * 2;
|
|
31379
|
+
}
|
|
31380
|
+
},
|
|
31381
|
+
"amazon.titan-text-express-v1": {
|
|
31382
|
+
name: "Amazon Titan Text Express",
|
|
31383
|
+
type: "language" /* Language */,
|
|
31384
|
+
streaming: true,
|
|
31385
|
+
provider: "Amazon",
|
|
31386
|
+
description: "",
|
|
31387
|
+
version: "v1.x",
|
|
31388
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
31389
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 20 + outputSize / AVERAGE_BYTES_PER_TOKEN * 60);
|
|
31390
|
+
}
|
|
31391
|
+
},
|
|
31392
|
+
"amazon.titan-text-lite-v1": {
|
|
31393
|
+
name: "Amazon Titan Text Lite",
|
|
31394
|
+
type: "language" /* Language */,
|
|
31395
|
+
streaming: true,
|
|
31396
|
+
provider: "Amazon",
|
|
31397
|
+
description: "",
|
|
31398
|
+
version: "v1.x",
|
|
31399
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
31400
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 15 + outputSize / AVERAGE_BYTES_PER_TOKEN * 20);
|
|
31401
|
+
}
|
|
31402
|
+
},
|
|
31403
|
+
"amazon.titan-text-premier-v1:0": {
|
|
31404
|
+
name: "Amazon Titan Text Premier",
|
|
31405
|
+
type: "language" /* Language */,
|
|
31406
|
+
streaming: true,
|
|
31407
|
+
provider: "Amazon",
|
|
31408
|
+
description: "",
|
|
31409
|
+
version: "v1.x",
|
|
31410
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
31411
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 50 + outputSize / AVERAGE_BYTES_PER_TOKEN * 150);
|
|
31412
|
+
}
|
|
31413
|
+
},
|
|
31414
|
+
// WIP: Need to change the interface
|
|
31415
|
+
// 'amazon.titan-image-generator-v1': {
|
|
31416
|
+
// name: 'Amazon: Titan Image Generator G1',
|
|
31417
|
+
// type: ModelType.Image,
|
|
31418
|
+
// streaming: false,
|
|
31419
|
+
// provider: 'Amazon',
|
|
31420
|
+
// description:
|
|
31421
|
+
// '',
|
|
31422
|
+
// version: '1.x',
|
|
31423
|
+
// inferenceUsage: (width: number, height: number, steps: number) => {
|
|
31424
|
+
// const large = width * height > 512 * 512
|
|
31425
|
+
// const highQuality = steps > 50
|
|
31426
|
+
// return Math.round((large ? 3600000 : 1800000) * (highQuality ? 2 : 1))
|
|
31427
|
+
// }
|
|
31428
|
+
// },
|
|
31369
31429
|
"anthropic.claude-instant-v1": {
|
|
31370
31430
|
name: "Claude Instant",
|
|
31371
31431
|
type: "language" /* Language */,
|
|
@@ -31374,29 +31434,64 @@ var modelInfoMap = {
|
|
|
31374
31434
|
description: "A faster and cheaper yet still very capable model, which can handle a range of tasks including casual dialogue, text analysis, summarization, and document question-answering.",
|
|
31375
31435
|
version: "v1.2",
|
|
31376
31436
|
inferenceUsage: (inputSize, outputSize) => {
|
|
31377
|
-
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN *
|
|
31437
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 80 + outputSize / AVERAGE_BYTES_PER_TOKEN * 240);
|
|
31378
31438
|
}
|
|
31379
31439
|
},
|
|
31380
|
-
"anthropic.claude-
|
|
31440
|
+
"anthropic.claude-v2": {
|
|
31381
31441
|
name: "Claude",
|
|
31382
31442
|
type: "language" /* Language */,
|
|
31383
31443
|
streaming: true,
|
|
31384
31444
|
provider: "Anthropic",
|
|
31385
|
-
description: "
|
|
31386
|
-
version: "
|
|
31445
|
+
description: "Anthropic's most powerful model, which excels at a wide range of tasks from sophisticated dialogue and creative content generation to detailed instruction following.",
|
|
31446
|
+
version: "v2.0",
|
|
31387
31447
|
inferenceUsage: (inputSize, outputSize) => {
|
|
31388
|
-
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN *
|
|
31448
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 800 + outputSize / AVERAGE_BYTES_PER_TOKEN * 2400);
|
|
31389
31449
|
}
|
|
31390
31450
|
},
|
|
31391
|
-
"anthropic.claude-v2": {
|
|
31451
|
+
"anthropic.claude-v2:1": {
|
|
31392
31452
|
name: "Claude",
|
|
31393
31453
|
type: "language" /* Language */,
|
|
31394
31454
|
streaming: true,
|
|
31395
31455
|
provider: "Anthropic",
|
|
31396
31456
|
description: "Anthropic's most powerful model, which excels at a wide range of tasks from sophisticated dialogue and creative content generation to detailed instruction following.",
|
|
31397
|
-
version: "v2",
|
|
31457
|
+
version: "v2.1",
|
|
31458
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
31459
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 800 + outputSize / AVERAGE_BYTES_PER_TOKEN * 2400);
|
|
31460
|
+
}
|
|
31461
|
+
},
|
|
31462
|
+
"anthropic.claude-3-sonnet-20240229-v1:0": {
|
|
31463
|
+
name: "Claude 3 Sonnet",
|
|
31464
|
+
type: "language" /* Language */,
|
|
31465
|
+
streaming: true,
|
|
31466
|
+
provider: "Anthropic",
|
|
31467
|
+
description: "",
|
|
31468
|
+
version: "v1.0",
|
|
31469
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
31470
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 300 + outputSize / AVERAGE_BYTES_PER_TOKEN * 1500);
|
|
31471
|
+
}
|
|
31472
|
+
},
|
|
31473
|
+
"anthropic.claude-3-haiku-20240307-v1:0": {
|
|
31474
|
+
name: "Claude 3 Haiku",
|
|
31475
|
+
type: "language" /* Language */,
|
|
31476
|
+
streaming: true,
|
|
31477
|
+
provider: "Anthropic",
|
|
31478
|
+
description: "",
|
|
31479
|
+
version: "v1.0",
|
|
31480
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
31481
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 25 + outputSize / AVERAGE_BYTES_PER_TOKEN * 125);
|
|
31482
|
+
}
|
|
31483
|
+
},
|
|
31484
|
+
"anthropic.claude-3-opus-20240229-v1:0": {
|
|
31485
|
+
name: "Claude 3 Opus",
|
|
31486
|
+
region: "us-west-2",
|
|
31487
|
+
// as of 5/10/2024, this is the only region that supports this model
|
|
31488
|
+
type: "language" /* Language */,
|
|
31489
|
+
streaming: true,
|
|
31490
|
+
provider: "Anthropic",
|
|
31491
|
+
description: "",
|
|
31492
|
+
version: "v1.0",
|
|
31398
31493
|
inferenceUsage: (inputSize, outputSize) => {
|
|
31399
|
-
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN *
|
|
31494
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 1500 + outputSize / AVERAGE_BYTES_PER_TOKEN * 7500);
|
|
31400
31495
|
}
|
|
31401
31496
|
},
|
|
31402
31497
|
"cohere.command-text-v14": {
|
|
@@ -31456,25 +31551,56 @@ var modelInfoMap = {
|
|
|
31456
31551
|
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 75 + outputSize / AVERAGE_BYTES_PER_TOKEN * 100);
|
|
31457
31552
|
}
|
|
31458
31553
|
},
|
|
31459
|
-
"
|
|
31554
|
+
"meta.llama2-70b-chat-v1": {
|
|
31555
|
+
name: "Meta Llama 2 Chat (70B)",
|
|
31556
|
+
type: "language" /* Language */,
|
|
31557
|
+
streaming: true,
|
|
31558
|
+
provider: "Meta",
|
|
31559
|
+
description: "",
|
|
31560
|
+
version: "v1",
|
|
31561
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
31562
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 195 + outputSize / AVERAGE_BYTES_PER_TOKEN * 256);
|
|
31563
|
+
}
|
|
31564
|
+
},
|
|
31565
|
+
"meta.llama3-8b-instruct-v1:0": {
|
|
31566
|
+
name: "Meta Llama 3 Instruct (8B)",
|
|
31567
|
+
type: "language" /* Language */,
|
|
31568
|
+
streaming: true,
|
|
31569
|
+
provider: "Meta",
|
|
31570
|
+
description: "",
|
|
31571
|
+
version: "v1.x",
|
|
31572
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
31573
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 40 + outputSize / AVERAGE_BYTES_PER_TOKEN * 60);
|
|
31574
|
+
}
|
|
31575
|
+
},
|
|
31576
|
+
"meta.llama3-70b-instruct-v1:0": {
|
|
31577
|
+
name: "Meta Llama 3 Instruct (70B)",
|
|
31578
|
+
type: "language" /* Language */,
|
|
31579
|
+
streaming: true,
|
|
31580
|
+
provider: "Meta",
|
|
31581
|
+
description: "",
|
|
31582
|
+
version: "v1.x",
|
|
31583
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
31584
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 265 + outputSize / AVERAGE_BYTES_PER_TOKEN * 350);
|
|
31585
|
+
}
|
|
31586
|
+
},
|
|
31587
|
+
"stability.stable-diffusion-xl-v1": {
|
|
31460
31588
|
name: "Stable Diffusion XL",
|
|
31461
31589
|
type: "image" /* Image */,
|
|
31462
31590
|
streaming: false,
|
|
31463
31591
|
provider: "Stability AI",
|
|
31464
31592
|
description: "Deep learning, text-to-image model used to generate detailed images conditioned on text descriptions, inpainting, outpainting, and generating image-to-image translations.",
|
|
31465
|
-
version: "
|
|
31593
|
+
version: "v1.x",
|
|
31466
31594
|
inferenceUsage: (width, height, steps) => {
|
|
31467
|
-
const large = width * height > 512 * 512;
|
|
31468
31595
|
const highQuality = steps > 50;
|
|
31469
|
-
return Math.round(
|
|
31596
|
+
return Math.round(4e6 * (highQuality ? 2 : 1));
|
|
31470
31597
|
}
|
|
31471
31598
|
},
|
|
31472
31599
|
"mistral.mistral-7b-instruct-v0:2": {
|
|
31473
31600
|
name: "Mistral Instruct (7B)",
|
|
31474
|
-
region:
|
|
31475
|
-
// at time of writing, this is the only region that supports this model
|
|
31601
|
+
// region: 'us-west-2',
|
|
31476
31602
|
type: "language" /* Language */,
|
|
31477
|
-
streaming:
|
|
31603
|
+
streaming: true,
|
|
31478
31604
|
provider: "Mistral",
|
|
31479
31605
|
description: "First foundation model from MistralAI. Ideal for text summarization, question and answering, text classification, text completion, and code generation.",
|
|
31480
31606
|
version: "v0.2",
|
|
@@ -31484,16 +31610,27 @@ var modelInfoMap = {
|
|
|
31484
31610
|
},
|
|
31485
31611
|
"mistral.mixtral-8x7b-instruct-v0:1": {
|
|
31486
31612
|
name: "MixTral Instruct (8x7B)",
|
|
31487
|
-
region:
|
|
31488
|
-
// at time of writing, this is the only region that supports this model
|
|
31613
|
+
// region: 'us-west-2',
|
|
31489
31614
|
type: "language" /* Language */,
|
|
31490
|
-
streaming:
|
|
31615
|
+
streaming: true,
|
|
31491
31616
|
provider: "Mistral",
|
|
31492
31617
|
description: "Ideal for text summarization, question and answering, text classification, text completion, and code generation.",
|
|
31493
31618
|
version: "v0.1",
|
|
31494
31619
|
inferenceUsage: (inputSize, outputSize) => {
|
|
31495
31620
|
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 45 + outputSize / AVERAGE_BYTES_PER_TOKEN * 70);
|
|
31496
31621
|
}
|
|
31622
|
+
},
|
|
31623
|
+
"mistral.mistral-large-2402-v1:0": {
|
|
31624
|
+
name: "Mistral Large",
|
|
31625
|
+
// region: 'us-west-2',
|
|
31626
|
+
type: "language" /* Language */,
|
|
31627
|
+
streaming: true,
|
|
31628
|
+
provider: "Mistral",
|
|
31629
|
+
description: "Ideal for text summarization, question and answering, text classification, text completion, and code generation.",
|
|
31630
|
+
version: "v0.1",
|
|
31631
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
31632
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 800 + outputSize / AVERAGE_BYTES_PER_TOKEN * 2400);
|
|
31633
|
+
}
|
|
31497
31634
|
}
|
|
31498
31635
|
};
|
|
31499
31636
|
function getModelInfo(id) {
|
|
@@ -31625,8 +31762,39 @@ var AnthropicClaudeChatAdapter = class {
|
|
|
31625
31762
|
}
|
|
31626
31763
|
};
|
|
31627
31764
|
|
|
31628
|
-
// src/chat/adapters/
|
|
31765
|
+
// src/chat/adapters/anthropic.claude.sonnet.ts
|
|
31629
31766
|
var decoder2 = new TextDecoder();
|
|
31767
|
+
var AnthropicClaudeSonnetChatAdapter = class {
|
|
31768
|
+
async buildInput(messages, options) {
|
|
31769
|
+
return {
|
|
31770
|
+
system: "You are a helpful virtual assistant. Please answer the user's questions and/or carry the conversation forward, abiding by the user's instructions.",
|
|
31771
|
+
messages: messages.map((message) => ({
|
|
31772
|
+
// Sonnet uses `user` instead of `human` for the user role.
|
|
31773
|
+
role: message.role === "human" ? "user" : message.role,
|
|
31774
|
+
content: message.content
|
|
31775
|
+
})),
|
|
31776
|
+
max_tokens: options.maxTokens ?? 1e3,
|
|
31777
|
+
anthropic_version: "bedrock-2023-05-31"
|
|
31778
|
+
};
|
|
31779
|
+
}
|
|
31780
|
+
formatResponse(response) {
|
|
31781
|
+
if (!response.body) {
|
|
31782
|
+
throw new Error("No response from model");
|
|
31783
|
+
}
|
|
31784
|
+
const transformer = new TransformStream({
|
|
31785
|
+
transform(chunk2, controller) {
|
|
31786
|
+
const event = JSON.parse(decoder2.decode(chunk2));
|
|
31787
|
+
if (event.type === "content_block_delta" && event.delta.type === "text_delta" && event.delta.text) {
|
|
31788
|
+
controller.enqueue(Buffer.from(event.delta.text, "utf8"));
|
|
31789
|
+
}
|
|
31790
|
+
}
|
|
31791
|
+
});
|
|
31792
|
+
return response.body.pipeThrough(transformer);
|
|
31793
|
+
}
|
|
31794
|
+
};
|
|
31795
|
+
|
|
31796
|
+
// src/chat/adapters/ai21.jurassic.ts
|
|
31797
|
+
var decoder3 = new TextDecoder();
|
|
31630
31798
|
function buildPrompt2(messages) {
|
|
31631
31799
|
const messagesCopy = [...messages];
|
|
31632
31800
|
if (messagesCopy.length === 0 || messagesCopy[messagesCopy.length - 1].role !== "assistant") {
|
|
@@ -31683,7 +31851,7 @@ var Ai21JurassicChatAdapter = class {
|
|
|
31683
31851
|
}
|
|
31684
31852
|
const transformer = new TransformStream({
|
|
31685
31853
|
transform(chunk2, controller) {
|
|
31686
|
-
const event = JSON.parse(
|
|
31854
|
+
const event = JSON.parse(decoder3.decode(chunk2));
|
|
31687
31855
|
for (const completion of event.completions) {
|
|
31688
31856
|
controller.enqueue(Buffer.from(completion.data.text, "utf8"));
|
|
31689
31857
|
}
|
|
@@ -31694,7 +31862,7 @@ var Ai21JurassicChatAdapter = class {
|
|
|
31694
31862
|
};
|
|
31695
31863
|
|
|
31696
31864
|
// src/chat/adapters/cohere.command.ts
|
|
31697
|
-
var
|
|
31865
|
+
var decoder4 = new TextDecoder();
|
|
31698
31866
|
function buildPrompt3(messages) {
|
|
31699
31867
|
const messagesCopy = [...messages];
|
|
31700
31868
|
if (messagesCopy.length === 0 || messagesCopy[messagesCopy.length - 1].role !== "assistant") {
|
|
@@ -31721,7 +31889,7 @@ var CohereCommandChatAdapter = class {
|
|
|
31721
31889
|
}
|
|
31722
31890
|
const transformer = new TransformStream({
|
|
31723
31891
|
transform(chunk2, controller) {
|
|
31724
|
-
const event = JSON.parse(
|
|
31892
|
+
const event = JSON.parse(decoder4.decode(chunk2));
|
|
31725
31893
|
if (event.text) {
|
|
31726
31894
|
controller.enqueue(Buffer.from(event.text, "utf8"));
|
|
31727
31895
|
}
|
|
@@ -31732,7 +31900,7 @@ var CohereCommandChatAdapter = class {
|
|
|
31732
31900
|
};
|
|
31733
31901
|
|
|
31734
31902
|
// src/chat/adapters/meta.llama.ts
|
|
31735
|
-
var
|
|
31903
|
+
var decoder5 = new TextDecoder();
|
|
31736
31904
|
function buildPrompt4(messages) {
|
|
31737
31905
|
const messagesCopy = [...messages];
|
|
31738
31906
|
if (messagesCopy.length === 0 || messagesCopy[messagesCopy.length - 1].role !== "assistant") {
|
|
@@ -31758,7 +31926,7 @@ var MetaLlamaChatAdapter = class {
|
|
|
31758
31926
|
}
|
|
31759
31927
|
const transformer = new TransformStream({
|
|
31760
31928
|
transform(chunk2, controller) {
|
|
31761
|
-
const event = JSON.parse(
|
|
31929
|
+
const event = JSON.parse(decoder5.decode(chunk2));
|
|
31762
31930
|
if (event.generation) {
|
|
31763
31931
|
controller.enqueue(Buffer.from(event.generation, "utf8"));
|
|
31764
31932
|
}
|
|
@@ -31769,7 +31937,7 @@ var MetaLlamaChatAdapter = class {
|
|
|
31769
31937
|
};
|
|
31770
31938
|
|
|
31771
31939
|
// src/chat/adapters/mixtral.ts
|
|
31772
|
-
var
|
|
31940
|
+
var decoder6 = new TextDecoder();
|
|
31773
31941
|
function buildPrompt5(messages) {
|
|
31774
31942
|
const messagesCopy = [...messages];
|
|
31775
31943
|
if (messagesCopy.length === 0 || messagesCopy[messagesCopy.length - 1].role !== "assistant") {
|
|
@@ -31797,7 +31965,7 @@ var MixtralAIChatAdapter = class {
|
|
|
31797
31965
|
}
|
|
31798
31966
|
const transformer = new TransformStream({
|
|
31799
31967
|
transform(chunk2, controller) {
|
|
31800
|
-
const event = JSON.parse(
|
|
31968
|
+
const event = JSON.parse(decoder6.decode(chunk2));
|
|
31801
31969
|
if (event.outputs?.length) {
|
|
31802
31970
|
const output = event.outputs.map((o14) => o14.text).join("");
|
|
31803
31971
|
controller.enqueue(Buffer.from(output, "utf8"));
|
|
@@ -31819,15 +31987,21 @@ var ChatMessage = class {
|
|
|
31819
31987
|
};
|
|
31820
31988
|
var adapters = {
|
|
31821
31989
|
"anthropic.claude-instant-v1": AnthropicClaudeChatAdapter,
|
|
31822
|
-
"anthropic.claude-v1": AnthropicClaudeChatAdapter,
|
|
31823
31990
|
"anthropic.claude-v2": AnthropicClaudeChatAdapter,
|
|
31991
|
+
"anthropic.claude-3-sonnet-20240229-v1:0": AnthropicClaudeSonnetChatAdapter,
|
|
31992
|
+
"anthropic.claude-3-haiku-20240307-v1:0": AnthropicClaudeSonnetChatAdapter,
|
|
31993
|
+
"anthropic.claude-3-opus-20240229-v1:0": AnthropicClaudeSonnetChatAdapter,
|
|
31824
31994
|
"ai21.j2-mid-v1": Ai21JurassicChatAdapter,
|
|
31825
31995
|
"ai21.j2-ultra-v1": Ai21JurassicChatAdapter,
|
|
31826
31996
|
"cohere.command-text-v14": CohereCommandChatAdapter,
|
|
31827
31997
|
"cohere.command-light-text-v14": CohereCommandChatAdapter,
|
|
31828
31998
|
"meta.llama2-13b-chat-v1": MetaLlamaChatAdapter,
|
|
31999
|
+
"meta.llama2-70b-chat-v1": MetaLlamaChatAdapter,
|
|
32000
|
+
"meta.llama3-8b-instruct-v1:0": MetaLlamaChatAdapter,
|
|
32001
|
+
"meta.llama3-70b-instruct-v1:0": MetaLlamaChatAdapter,
|
|
31829
32002
|
"mistral.mistral-7b-instruct-v0:2": MixtralAIChatAdapter,
|
|
31830
|
-
"mistral.mixtral-8x7b-instruct-v0:1": MixtralAIChatAdapter
|
|
32003
|
+
"mistral.mixtral-8x7b-instruct-v0:1": MixtralAIChatAdapter,
|
|
32004
|
+
"mistral.mistral-large-2402-v1:0": MixtralAIChatAdapter
|
|
31831
32005
|
};
|
|
31832
32006
|
async function chat(messages, options = {}) {
|
|
31833
32007
|
const modelId = options.modelId ?? "anthropic.claude-instant-v1";
|
|
@@ -31843,15 +32017,21 @@ async function chat(messages, options = {}) {
|
|
|
31843
32017
|
chat.models = async () => {
|
|
31844
32018
|
return [
|
|
31845
32019
|
"anthropic.claude-instant-v1",
|
|
31846
|
-
"anthropic.claude-v1",
|
|
31847
32020
|
"anthropic.claude-v2",
|
|
32021
|
+
"anthropic.claude-3-sonnet-20240229-v1:0",
|
|
32022
|
+
"anthropic.claude-3-haiku-20240307-v1:0",
|
|
32023
|
+
"anthropic.claude-3-opus-20240229-v1:0",
|
|
31848
32024
|
"ai21.j2-mid-v1",
|
|
31849
32025
|
"ai21.j2-ultra-v1",
|
|
31850
32026
|
"cohere.command-text-v14",
|
|
31851
32027
|
"cohere.command-light-text-v14",
|
|
31852
32028
|
"meta.llama2-13b-chat-v1",
|
|
32029
|
+
"meta.llama2-70b-chat-v1",
|
|
32030
|
+
"meta.llama3-8b-instruct-v1:0",
|
|
32031
|
+
"meta.llama3-70b-instruct-v1:0",
|
|
31853
32032
|
"mistral.mistral-7b-instruct-v0:2",
|
|
31854
|
-
"mistral.mixtral-8x7b-instruct-v0:1"
|
|
32033
|
+
"mistral.mixtral-8x7b-instruct-v0:1",
|
|
32034
|
+
"mistral.mistral-large-2402-v1:0"
|
|
31855
32035
|
];
|
|
31856
32036
|
};
|
|
31857
32037
|
|
|
@@ -31885,11 +32065,12 @@ var CohereEmbedAdapter = class {
|
|
|
31885
32065
|
// src/embed/index.ts
|
|
31886
32066
|
var adapters2 = {
|
|
31887
32067
|
"amazon.titan-embed-text-v1": AmazonTitanEmbedTextAdapter,
|
|
32068
|
+
"amazon.titan-embed-text-v2:0": AmazonTitanEmbedTextAdapter,
|
|
31888
32069
|
"cohere.embed-english-v3": CohereEmbedAdapter,
|
|
31889
32070
|
"cohere.embed-multilingual-v3": CohereEmbedAdapter
|
|
31890
32071
|
};
|
|
31891
32072
|
async function embed(input, options = {}) {
|
|
31892
|
-
const modelId = options.modelId ?? "amazon.titan-embed-text-
|
|
32073
|
+
const modelId = options.modelId ?? "amazon.titan-embed-text-v2:0";
|
|
31893
32074
|
const AdapterClass = adapters2[modelId];
|
|
31894
32075
|
if (!AdapterClass) {
|
|
31895
32076
|
throw new Error(`No adapter found for model ${modelId}`);
|
|
@@ -31905,7 +32086,7 @@ embed.models = async () => {
|
|
|
31905
32086
|
|
|
31906
32087
|
// src/render.ts
|
|
31907
32088
|
async function render(prompt, options = {}) {
|
|
31908
|
-
const modelId = options.modelId ?? "stability.stable-diffusion-xl-
|
|
32089
|
+
const modelId = options.modelId ?? "stability.stable-diffusion-xl-v1";
|
|
31909
32090
|
const body = {
|
|
31910
32091
|
text_prompts: [
|
|
31911
32092
|
{
|
|
@@ -31915,8 +32096,8 @@ async function render(prompt, options = {}) {
|
|
|
31915
32096
|
cfg_scale: options.scale ?? 10,
|
|
31916
32097
|
seed: options.seed ?? 20,
|
|
31917
32098
|
steps: options.steps ?? 50,
|
|
31918
|
-
width: options.width ??
|
|
31919
|
-
height: options.height ??
|
|
32099
|
+
width: options.width ?? 1024,
|
|
32100
|
+
height: options.height ?? 1024
|
|
31920
32101
|
};
|
|
31921
32102
|
const response = await invoke2({ body, modelId });
|
|
31922
32103
|
if (!response.body) {
|
|
@@ -31932,11 +32113,40 @@ async function render(prompt, options = {}) {
|
|
|
31932
32113
|
return new Response(responseBody, { headers: { "Content-Type": "image/png" } });
|
|
31933
32114
|
}
|
|
31934
32115
|
render.models = async () => {
|
|
31935
|
-
return ["stability.stable-diffusion-xl-
|
|
32116
|
+
return ["stability.stable-diffusion-xl-v1"];
|
|
32117
|
+
};
|
|
32118
|
+
|
|
32119
|
+
// src/summarize/adapters/anthropic.claude.sonnet.ts
|
|
32120
|
+
var decoder7 = new TextDecoder();
|
|
32121
|
+
var AnthropicClaudeSonnetSummarizeAdapter = class {
|
|
32122
|
+
async buildInput(input, options) {
|
|
32123
|
+
return {
|
|
32124
|
+
// Sonnet varies from the original Claude model in that it does not take a prompt argument.
|
|
32125
|
+
// see https://github.com/langchain-ai/langchain/issues/18513
|
|
32126
|
+
system: "You are a helpful virtual assistant. Please summarize the bodies of text provided to you. Write only one or two paragraphs, and only include the summary, without any preamble or other text.",
|
|
32127
|
+
messages: [{ role: "user", content: input }],
|
|
32128
|
+
anthropic_version: "bedrock-2023-05-31",
|
|
32129
|
+
max_tokens: options.maxTokens ?? 1e3
|
|
32130
|
+
};
|
|
32131
|
+
}
|
|
32132
|
+
formatResponse(response) {
|
|
32133
|
+
if (!response.body) {
|
|
32134
|
+
throw new Error("No response from model");
|
|
32135
|
+
}
|
|
32136
|
+
const transformer = new TransformStream({
|
|
32137
|
+
transform(chunk2, controller) {
|
|
32138
|
+
const event = JSON.parse(decoder7.decode(chunk2));
|
|
32139
|
+
if (event.type === "content_block_delta" && event.delta.type === "text_delta" && event.delta.text) {
|
|
32140
|
+
controller.enqueue(Buffer.from(event.delta.text, "utf8"));
|
|
32141
|
+
}
|
|
32142
|
+
}
|
|
32143
|
+
});
|
|
32144
|
+
return response.body.pipeThrough(transformer);
|
|
32145
|
+
}
|
|
31936
32146
|
};
|
|
31937
32147
|
|
|
31938
32148
|
// src/summarize/adapters/anthropic.claude.ts
|
|
31939
|
-
var
|
|
32149
|
+
var decoder8 = new TextDecoder();
|
|
31940
32150
|
function buildPrompt6(input) {
|
|
31941
32151
|
return `Human: I'm going to give you a document. Then I'm going to ask you to summarize it. Here is the document:
|
|
31942
32152
|
|
|
@@ -31959,7 +32169,7 @@ var AnthropicClaudeSummarizeAdapter = class {
|
|
|
31959
32169
|
}
|
|
31960
32170
|
const transformer = new TransformStream({
|
|
31961
32171
|
transform(chunk2, controller) {
|
|
31962
|
-
const event = JSON.parse(
|
|
32172
|
+
const event = JSON.parse(decoder8.decode(chunk2));
|
|
31963
32173
|
if (event.completion) {
|
|
31964
32174
|
controller.enqueue(Buffer.from(event.completion, "utf8"));
|
|
31965
32175
|
}
|
|
@@ -31970,7 +32180,7 @@ var AnthropicClaudeSummarizeAdapter = class {
|
|
|
31970
32180
|
};
|
|
31971
32181
|
|
|
31972
32182
|
// src/summarize/adapters/mixtral.ts
|
|
31973
|
-
var
|
|
32183
|
+
var decoder9 = new TextDecoder();
|
|
31974
32184
|
function buildPrompt7(input) {
|
|
31975
32185
|
return `Human: I'm going to give you a document. Then I'm going to ask you to summarize it. Here is the document:
|
|
31976
32186
|
|
|
@@ -31995,7 +32205,7 @@ var MixtralAISummarizeAdapter = class {
|
|
|
31995
32205
|
}
|
|
31996
32206
|
const transformer = new TransformStream({
|
|
31997
32207
|
transform(chunk2, controller) {
|
|
31998
|
-
const event = JSON.parse(
|
|
32208
|
+
const event = JSON.parse(decoder9.decode(chunk2));
|
|
31999
32209
|
if (event.outputs?.length) {
|
|
32000
32210
|
const output = event.outputs.map((o14) => o14.text).join("");
|
|
32001
32211
|
controller.enqueue(Buffer.from(output, "utf8"));
|
|
@@ -32009,8 +32219,9 @@ var MixtralAISummarizeAdapter = class {
|
|
|
32009
32219
|
// src/summarize/index.ts
|
|
32010
32220
|
var adapters3 = {
|
|
32011
32221
|
"anthropic.claude-instant-v1": AnthropicClaudeSummarizeAdapter,
|
|
32012
|
-
|
|
32222
|
+
// 'anthropic.claude-v1': AnthropicClaudeSummarizeAdapter,
|
|
32013
32223
|
"anthropic.claude-v2": AnthropicClaudeSummarizeAdapter,
|
|
32224
|
+
"anthropic.claude-3-sonnet-20240229-v1:0": AnthropicClaudeSonnetSummarizeAdapter,
|
|
32014
32225
|
"mistral.mistral-7b-instruct-v0:2": MixtralAISummarizeAdapter,
|
|
32015
32226
|
"mistral.mixtral-8x7b-instruct-v0:1": MixtralAISummarizeAdapter
|
|
32016
32227
|
};
|
|
@@ -32028,8 +32239,9 @@ async function summarize(input, options = {}) {
|
|
|
32028
32239
|
summarize.models = async () => {
|
|
32029
32240
|
return [
|
|
32030
32241
|
"anthropic.claude-instant-v1",
|
|
32031
|
-
|
|
32242
|
+
// 'anthropic.claude-v1',
|
|
32032
32243
|
"anthropic.claude-v2",
|
|
32244
|
+
"anthropic.claude-3-sonnet-20240229-v1:0",
|
|
32033
32245
|
"mistral.mistral-7b-instruct-v0:2",
|
|
32034
32246
|
"mistral.mixtral-8x7b-instruct-v0:1"
|
|
32035
32247
|
];
|
|
@@ -42289,7 +42501,7 @@ async function translate(input, options) {
|
|
|
42289
42501
|
// src/index.ts
|
|
42290
42502
|
if (process.env.AMPT_RUNTIME_NAME === "nodejs18-beta") {
|
|
42291
42503
|
console.error(
|
|
42292
|
-
'@ampt/ai requires the nodejs18 runtime. Please add "runtime": "
|
|
42504
|
+
'@ampt/ai requires the nodejs18 runtime or higher. Please add "runtime": "nodejs20" to the "ampt" section of your package.json.'
|
|
42293
42505
|
);
|
|
42294
42506
|
}
|
|
42295
42507
|
export {
|