@ampt/ai 2.0.6 → 2.0.7
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 +89 -14
- package/dist/index.d.cts +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.js +89 -14
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -44581,6 +44581,17 @@ var modelInfoMap = {
|
|
|
44581
44581
|
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 1102 + outputSize / AVERAGE_BYTES_PER_TOKEN * 3268);
|
|
44582
44582
|
}
|
|
44583
44583
|
},
|
|
44584
|
+
"anthropic.claude-3-sonnet-20240229-v1:0": {
|
|
44585
|
+
name: "Claude 3 Sonnet",
|
|
44586
|
+
type: "language" /* Language */,
|
|
44587
|
+
streaming: true,
|
|
44588
|
+
provider: "Anthropic",
|
|
44589
|
+
description: "",
|
|
44590
|
+
version: "v1",
|
|
44591
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
44592
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 300 + outputSize / AVERAGE_BYTES_PER_TOKEN * 1500);
|
|
44593
|
+
}
|
|
44594
|
+
},
|
|
44584
44595
|
"cohere.command-text-v14": {
|
|
44585
44596
|
name: "Command",
|
|
44586
44597
|
type: "language" /* Language */,
|
|
@@ -44656,7 +44667,7 @@ var modelInfoMap = {
|
|
|
44656
44667
|
region: "us-west-2",
|
|
44657
44668
|
// at time of writing, this is the only region that supports this model
|
|
44658
44669
|
type: "language" /* Language */,
|
|
44659
|
-
streaming:
|
|
44670
|
+
streaming: true,
|
|
44660
44671
|
provider: "Mistral",
|
|
44661
44672
|
description: "First foundation model from MistralAI. Ideal for text summarization, question and answering, text classification, text completion, and code generation.",
|
|
44662
44673
|
version: "v0.2",
|
|
@@ -44669,7 +44680,7 @@ var modelInfoMap = {
|
|
|
44669
44680
|
region: "us-west-2",
|
|
44670
44681
|
// at time of writing, this is the only region that supports this model
|
|
44671
44682
|
type: "language" /* Language */,
|
|
44672
|
-
streaming:
|
|
44683
|
+
streaming: true,
|
|
44673
44684
|
provider: "Mistral",
|
|
44674
44685
|
description: "Ideal for text summarization, question and answering, text classification, text completion, and code generation.",
|
|
44675
44686
|
version: "v0.1",
|
|
@@ -44807,8 +44818,39 @@ var AnthropicClaudeChatAdapter = class {
|
|
|
44807
44818
|
}
|
|
44808
44819
|
};
|
|
44809
44820
|
|
|
44810
|
-
// src/chat/adapters/
|
|
44821
|
+
// src/chat/adapters/anthropic.claude.sonnet.ts
|
|
44811
44822
|
var decoder2 = new TextDecoder();
|
|
44823
|
+
var AnthropicClaudeSonnetChatAdapter = class {
|
|
44824
|
+
async buildInput(messages, options) {
|
|
44825
|
+
return {
|
|
44826
|
+
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.",
|
|
44827
|
+
messages: messages.map((message) => ({
|
|
44828
|
+
// Sonnet uses `user` instead of `human` for the user role.
|
|
44829
|
+
role: message.role === "human" ? "user" : message.role,
|
|
44830
|
+
content: message.content
|
|
44831
|
+
})),
|
|
44832
|
+
max_tokens: options.maxTokens ?? 1e3,
|
|
44833
|
+
anthropic_version: "bedrock-2023-05-31"
|
|
44834
|
+
};
|
|
44835
|
+
}
|
|
44836
|
+
formatResponse(response) {
|
|
44837
|
+
if (!response.body) {
|
|
44838
|
+
throw new Error("No response from model");
|
|
44839
|
+
}
|
|
44840
|
+
const transformer = new TransformStream({
|
|
44841
|
+
transform(chunk2, controller) {
|
|
44842
|
+
const event = JSON.parse(decoder2.decode(chunk2));
|
|
44843
|
+
if (event.type === "content_block_delta" && event.delta.type === "text_delta" && event.delta.text) {
|
|
44844
|
+
controller.enqueue(Buffer.from(event.delta.text, "utf8"));
|
|
44845
|
+
}
|
|
44846
|
+
}
|
|
44847
|
+
});
|
|
44848
|
+
return response.body.pipeThrough(transformer);
|
|
44849
|
+
}
|
|
44850
|
+
};
|
|
44851
|
+
|
|
44852
|
+
// src/chat/adapters/ai21.jurassic.ts
|
|
44853
|
+
var decoder3 = new TextDecoder();
|
|
44812
44854
|
function buildPrompt2(messages) {
|
|
44813
44855
|
const messagesCopy = [...messages];
|
|
44814
44856
|
if (messagesCopy.length === 0 || messagesCopy[messagesCopy.length - 1].role !== "assistant") {
|
|
@@ -44865,7 +44907,7 @@ var Ai21JurassicChatAdapter = class {
|
|
|
44865
44907
|
}
|
|
44866
44908
|
const transformer = new TransformStream({
|
|
44867
44909
|
transform(chunk2, controller) {
|
|
44868
|
-
const event = JSON.parse(
|
|
44910
|
+
const event = JSON.parse(decoder3.decode(chunk2));
|
|
44869
44911
|
for (const completion of event.completions) {
|
|
44870
44912
|
controller.enqueue(Buffer.from(completion.data.text, "utf8"));
|
|
44871
44913
|
}
|
|
@@ -44876,7 +44918,7 @@ var Ai21JurassicChatAdapter = class {
|
|
|
44876
44918
|
};
|
|
44877
44919
|
|
|
44878
44920
|
// src/chat/adapters/cohere.command.ts
|
|
44879
|
-
var
|
|
44921
|
+
var decoder4 = new TextDecoder();
|
|
44880
44922
|
function buildPrompt3(messages) {
|
|
44881
44923
|
const messagesCopy = [...messages];
|
|
44882
44924
|
if (messagesCopy.length === 0 || messagesCopy[messagesCopy.length - 1].role !== "assistant") {
|
|
@@ -44903,7 +44945,7 @@ var CohereCommandChatAdapter = class {
|
|
|
44903
44945
|
}
|
|
44904
44946
|
const transformer = new TransformStream({
|
|
44905
44947
|
transform(chunk2, controller) {
|
|
44906
|
-
const event = JSON.parse(
|
|
44948
|
+
const event = JSON.parse(decoder4.decode(chunk2));
|
|
44907
44949
|
if (event.text) {
|
|
44908
44950
|
controller.enqueue(Buffer.from(event.text, "utf8"));
|
|
44909
44951
|
}
|
|
@@ -44914,7 +44956,7 @@ var CohereCommandChatAdapter = class {
|
|
|
44914
44956
|
};
|
|
44915
44957
|
|
|
44916
44958
|
// src/chat/adapters/meta.llama.ts
|
|
44917
|
-
var
|
|
44959
|
+
var decoder5 = new TextDecoder();
|
|
44918
44960
|
function buildPrompt4(messages) {
|
|
44919
44961
|
const messagesCopy = [...messages];
|
|
44920
44962
|
if (messagesCopy.length === 0 || messagesCopy[messagesCopy.length - 1].role !== "assistant") {
|
|
@@ -44940,7 +44982,7 @@ var MetaLlamaChatAdapter = class {
|
|
|
44940
44982
|
}
|
|
44941
44983
|
const transformer = new TransformStream({
|
|
44942
44984
|
transform(chunk2, controller) {
|
|
44943
|
-
const event = JSON.parse(
|
|
44985
|
+
const event = JSON.parse(decoder5.decode(chunk2));
|
|
44944
44986
|
if (event.generation) {
|
|
44945
44987
|
controller.enqueue(Buffer.from(event.generation, "utf8"));
|
|
44946
44988
|
}
|
|
@@ -44951,7 +44993,7 @@ var MetaLlamaChatAdapter = class {
|
|
|
44951
44993
|
};
|
|
44952
44994
|
|
|
44953
44995
|
// src/chat/adapters/mixtral.ts
|
|
44954
|
-
var
|
|
44996
|
+
var decoder6 = new TextDecoder();
|
|
44955
44997
|
function buildPrompt5(messages) {
|
|
44956
44998
|
const messagesCopy = [...messages];
|
|
44957
44999
|
if (messagesCopy.length === 0 || messagesCopy[messagesCopy.length - 1].role !== "assistant") {
|
|
@@ -44979,7 +45021,7 @@ var MixtralAIChatAdapter = class {
|
|
|
44979
45021
|
}
|
|
44980
45022
|
const transformer = new TransformStream({
|
|
44981
45023
|
transform(chunk2, controller) {
|
|
44982
|
-
const event = JSON.parse(
|
|
45024
|
+
const event = JSON.parse(decoder6.decode(chunk2));
|
|
44983
45025
|
if (event.outputs?.length) {
|
|
44984
45026
|
const output = event.outputs.map((o18) => o18.text).join("");
|
|
44985
45027
|
controller.enqueue(Buffer.from(output, "utf8"));
|
|
@@ -45003,6 +45045,7 @@ var adapters = {
|
|
|
45003
45045
|
"anthropic.claude-instant-v1": AnthropicClaudeChatAdapter,
|
|
45004
45046
|
"anthropic.claude-v1": AnthropicClaudeChatAdapter,
|
|
45005
45047
|
"anthropic.claude-v2": AnthropicClaudeChatAdapter,
|
|
45048
|
+
"anthropic.claude-3-sonnet-20240229-v1:0": AnthropicClaudeSonnetChatAdapter,
|
|
45006
45049
|
"ai21.j2-mid-v1": Ai21JurassicChatAdapter,
|
|
45007
45050
|
"ai21.j2-ultra-v1": Ai21JurassicChatAdapter,
|
|
45008
45051
|
"cohere.command-text-v14": CohereCommandChatAdapter,
|
|
@@ -45027,6 +45070,7 @@ chat.models = async () => {
|
|
|
45027
45070
|
"anthropic.claude-instant-v1",
|
|
45028
45071
|
"anthropic.claude-v1",
|
|
45029
45072
|
"anthropic.claude-v2",
|
|
45073
|
+
"anthropic.claude-3-sonnet-20240229-v1:0",
|
|
45030
45074
|
"ai21.j2-mid-v1",
|
|
45031
45075
|
"ai21.j2-ultra-v1",
|
|
45032
45076
|
"cohere.command-text-v14",
|
|
@@ -45117,8 +45161,37 @@ render.models = async () => {
|
|
|
45117
45161
|
return ["stability.stable-diffusion-xl-v0"];
|
|
45118
45162
|
};
|
|
45119
45163
|
|
|
45164
|
+
// src/summarize/adapters/anthropic.claude.sonnet.ts
|
|
45165
|
+
var decoder7 = new TextDecoder();
|
|
45166
|
+
var AnthropicClaudeSonnetSummarizeAdapter = class {
|
|
45167
|
+
async buildInput(input, options) {
|
|
45168
|
+
return {
|
|
45169
|
+
// Sonnet varies from the original Claude model in that it does not take a prompt argument.
|
|
45170
|
+
// see https://github.com/langchain-ai/langchain/issues/18513
|
|
45171
|
+
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.",
|
|
45172
|
+
messages: [{ role: "user", content: input }],
|
|
45173
|
+
anthropic_version: "bedrock-2023-05-31",
|
|
45174
|
+
max_tokens: options.maxTokens ?? 1e3
|
|
45175
|
+
};
|
|
45176
|
+
}
|
|
45177
|
+
formatResponse(response) {
|
|
45178
|
+
if (!response.body) {
|
|
45179
|
+
throw new Error("No response from model");
|
|
45180
|
+
}
|
|
45181
|
+
const transformer = new TransformStream({
|
|
45182
|
+
transform(chunk2, controller) {
|
|
45183
|
+
const event = JSON.parse(decoder7.decode(chunk2));
|
|
45184
|
+
if (event.type === "content_block_delta" && event.delta.type === "text_delta" && event.delta.text) {
|
|
45185
|
+
controller.enqueue(Buffer.from(event.delta.text, "utf8"));
|
|
45186
|
+
}
|
|
45187
|
+
}
|
|
45188
|
+
});
|
|
45189
|
+
return response.body.pipeThrough(transformer);
|
|
45190
|
+
}
|
|
45191
|
+
};
|
|
45192
|
+
|
|
45120
45193
|
// src/summarize/adapters/anthropic.claude.ts
|
|
45121
|
-
var
|
|
45194
|
+
var decoder8 = new TextDecoder();
|
|
45122
45195
|
function buildPrompt6(input) {
|
|
45123
45196
|
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
45197
|
|
|
@@ -45141,7 +45214,7 @@ var AnthropicClaudeSummarizeAdapter = class {
|
|
|
45141
45214
|
}
|
|
45142
45215
|
const transformer = new TransformStream({
|
|
45143
45216
|
transform(chunk2, controller) {
|
|
45144
|
-
const event = JSON.parse(
|
|
45217
|
+
const event = JSON.parse(decoder8.decode(chunk2));
|
|
45145
45218
|
if (event.completion) {
|
|
45146
45219
|
controller.enqueue(Buffer.from(event.completion, "utf8"));
|
|
45147
45220
|
}
|
|
@@ -45152,7 +45225,7 @@ var AnthropicClaudeSummarizeAdapter = class {
|
|
|
45152
45225
|
};
|
|
45153
45226
|
|
|
45154
45227
|
// src/summarize/adapters/mixtral.ts
|
|
45155
|
-
var
|
|
45228
|
+
var decoder9 = new TextDecoder();
|
|
45156
45229
|
function buildPrompt7(input) {
|
|
45157
45230
|
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
45231
|
|
|
@@ -45177,7 +45250,7 @@ var MixtralAISummarizeAdapter = class {
|
|
|
45177
45250
|
}
|
|
45178
45251
|
const transformer = new TransformStream({
|
|
45179
45252
|
transform(chunk2, controller) {
|
|
45180
|
-
const event = JSON.parse(
|
|
45253
|
+
const event = JSON.parse(decoder9.decode(chunk2));
|
|
45181
45254
|
if (event.outputs?.length) {
|
|
45182
45255
|
const output = event.outputs.map((o18) => o18.text).join("");
|
|
45183
45256
|
controller.enqueue(Buffer.from(output, "utf8"));
|
|
@@ -45193,6 +45266,7 @@ var adapters3 = {
|
|
|
45193
45266
|
"anthropic.claude-instant-v1": AnthropicClaudeSummarizeAdapter,
|
|
45194
45267
|
"anthropic.claude-v1": AnthropicClaudeSummarizeAdapter,
|
|
45195
45268
|
"anthropic.claude-v2": AnthropicClaudeSummarizeAdapter,
|
|
45269
|
+
"anthropic.claude-3-sonnet-20240229-v1:0": AnthropicClaudeSonnetSummarizeAdapter,
|
|
45196
45270
|
"mistral.mistral-7b-instruct-v0:2": MixtralAISummarizeAdapter,
|
|
45197
45271
|
"mistral.mixtral-8x7b-instruct-v0:1": MixtralAISummarizeAdapter
|
|
45198
45272
|
};
|
|
@@ -45212,6 +45286,7 @@ summarize.models = async () => {
|
|
|
45212
45286
|
"anthropic.claude-instant-v1",
|
|
45213
45287
|
"anthropic.claude-v1",
|
|
45214
45288
|
"anthropic.claude-v2",
|
|
45289
|
+
"anthropic.claude-3-sonnet-20240229-v1:0",
|
|
45215
45290
|
"mistral.mistral-7b-instruct-v0:2",
|
|
45216
45291
|
"mistral.mixtral-8x7b-instruct-v0:1"
|
|
45217
45292
|
];
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Translate } from '@aws-sdk/client-translate';
|
|
2
2
|
|
|
3
|
-
type ModelId = 'ai21.j2-mid-v1' | 'ai21.j2-ultra-v1' | 'anthropic.claude-v2' | 'anthropic.claude-instant-v1' | 'anthropic.claude-v1' | 'cohere.command-text-v14' | 'cohere.command-light-text-v14' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3' | 'stability.stable-diffusion-xl-v0' | 'amazon.titan-embed-text-v1' | 'meta.llama2-13b-chat-v1' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1';
|
|
3
|
+
type ModelId = 'ai21.j2-mid-v1' | 'ai21.j2-ultra-v1' | 'anthropic.claude-v2' | 'anthropic.claude-instant-v1' | 'anthropic.claude-v1' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'cohere.command-text-v14' | 'cohere.command-light-text-v14' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3' | 'stability.stable-diffusion-xl-v0' | 'amazon.titan-embed-text-v1' | 'meta.llama2-13b-chat-v1' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1';
|
|
4
4
|
declare function models(): Promise<string[]>;
|
|
5
5
|
declare enum ModelType {
|
|
6
6
|
Embeddings = "embeddings",
|
|
@@ -58,6 +58,10 @@ type ModelInfoMap = {
|
|
|
58
58
|
* - $0.01102 per 1000 input tokens: 1102 uc per token
|
|
59
59
|
* - $0.03268 per 1000 output tokens: 3268 uc per token
|
|
60
60
|
*
|
|
61
|
+
* Claude 3 Sonnet:
|
|
62
|
+
* - $0.00300 per 1000 input tokens: 300 uc per token
|
|
63
|
+
* - $0.01500 per 1000 output tokens: 1500 uc per token
|
|
64
|
+
*
|
|
61
65
|
* Cohere Command:
|
|
62
66
|
* - $0.0015 per 1000 input tokens: 150 uc per token
|
|
63
67
|
* - $0.0020 per 1000 output tokens: 200 uc per token
|
|
@@ -113,7 +117,7 @@ interface InvokeOptions {
|
|
|
113
117
|
*/
|
|
114
118
|
declare function invoke(options: InvokeOptions): Promise<Response>;
|
|
115
119
|
|
|
116
|
-
type MessageRole = 'assistant' | 'human';
|
|
120
|
+
type MessageRole = 'assistant' | 'human' | 'user';
|
|
117
121
|
interface ResponseWithBody extends Response {
|
|
118
122
|
body: ReadableStream<any>;
|
|
119
123
|
}
|
|
@@ -134,7 +138,7 @@ interface ChatOptions {
|
|
|
134
138
|
modelId?: ChatModelId;
|
|
135
139
|
maxTokens?: number;
|
|
136
140
|
}
|
|
137
|
-
type ChatModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v1' | 'anthropic.claude-v2' | 'ai21.j2-mid-v1' | 'ai21.j2-ultra-v1' | 'cohere.command-text-v14' | 'cohere.command-light-text-v14' | 'meta.llama2-13b-chat-v1' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1';
|
|
141
|
+
type ChatModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v1' | 'anthropic.claude-v2' | 'anthropic.claude-3-sonnet-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' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1';
|
|
138
142
|
/**
|
|
139
143
|
* Send messages to the model and return the completion
|
|
140
144
|
* @param messages Array of messages to send to the model
|
|
@@ -172,7 +176,7 @@ interface SummarizeOptions {
|
|
|
172
176
|
modelId?: SummarizeModelId;
|
|
173
177
|
maxTokens?: number;
|
|
174
178
|
}
|
|
175
|
-
type SummarizeModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v1' | 'anthropic.claude-v2' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1';
|
|
179
|
+
type SummarizeModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v1' | 'anthropic.claude-v2' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1';
|
|
176
180
|
declare function summarize(input: string, options?: SummarizeOptions): Promise<Response>;
|
|
177
181
|
declare namespace summarize {
|
|
178
182
|
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 = 'ai21.j2-mid-v1' | 'ai21.j2-ultra-v1' | 'anthropic.claude-v2' | 'anthropic.claude-instant-v1' | 'anthropic.claude-v1' | 'cohere.command-text-v14' | 'cohere.command-light-text-v14' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3' | 'stability.stable-diffusion-xl-v0' | 'amazon.titan-embed-text-v1' | 'meta.llama2-13b-chat-v1' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1';
|
|
3
|
+
type ModelId = 'ai21.j2-mid-v1' | 'ai21.j2-ultra-v1' | 'anthropic.claude-v2' | 'anthropic.claude-instant-v1' | 'anthropic.claude-v1' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'cohere.command-text-v14' | 'cohere.command-light-text-v14' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3' | 'stability.stable-diffusion-xl-v0' | 'amazon.titan-embed-text-v1' | 'meta.llama2-13b-chat-v1' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1';
|
|
4
4
|
declare function models(): Promise<string[]>;
|
|
5
5
|
declare enum ModelType {
|
|
6
6
|
Embeddings = "embeddings",
|
|
@@ -58,6 +58,10 @@ type ModelInfoMap = {
|
|
|
58
58
|
* - $0.01102 per 1000 input tokens: 1102 uc per token
|
|
59
59
|
* - $0.03268 per 1000 output tokens: 3268 uc per token
|
|
60
60
|
*
|
|
61
|
+
* Claude 3 Sonnet:
|
|
62
|
+
* - $0.00300 per 1000 input tokens: 300 uc per token
|
|
63
|
+
* - $0.01500 per 1000 output tokens: 1500 uc per token
|
|
64
|
+
*
|
|
61
65
|
* Cohere Command:
|
|
62
66
|
* - $0.0015 per 1000 input tokens: 150 uc per token
|
|
63
67
|
* - $0.0020 per 1000 output tokens: 200 uc per token
|
|
@@ -113,7 +117,7 @@ interface InvokeOptions {
|
|
|
113
117
|
*/
|
|
114
118
|
declare function invoke(options: InvokeOptions): Promise<Response>;
|
|
115
119
|
|
|
116
|
-
type MessageRole = 'assistant' | 'human';
|
|
120
|
+
type MessageRole = 'assistant' | 'human' | 'user';
|
|
117
121
|
interface ResponseWithBody extends Response {
|
|
118
122
|
body: ReadableStream<any>;
|
|
119
123
|
}
|
|
@@ -134,7 +138,7 @@ interface ChatOptions {
|
|
|
134
138
|
modelId?: ChatModelId;
|
|
135
139
|
maxTokens?: number;
|
|
136
140
|
}
|
|
137
|
-
type ChatModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v1' | 'anthropic.claude-v2' | 'ai21.j2-mid-v1' | 'ai21.j2-ultra-v1' | 'cohere.command-text-v14' | 'cohere.command-light-text-v14' | 'meta.llama2-13b-chat-v1' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1';
|
|
141
|
+
type ChatModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v1' | 'anthropic.claude-v2' | 'anthropic.claude-3-sonnet-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' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1';
|
|
138
142
|
/**
|
|
139
143
|
* Send messages to the model and return the completion
|
|
140
144
|
* @param messages Array of messages to send to the model
|
|
@@ -172,7 +176,7 @@ interface SummarizeOptions {
|
|
|
172
176
|
modelId?: SummarizeModelId;
|
|
173
177
|
maxTokens?: number;
|
|
174
178
|
}
|
|
175
|
-
type SummarizeModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v1' | 'anthropic.claude-v2' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1';
|
|
179
|
+
type SummarizeModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v1' | 'anthropic.claude-v2' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1';
|
|
176
180
|
declare function summarize(input: string, options?: SummarizeOptions): Promise<Response>;
|
|
177
181
|
declare namespace summarize {
|
|
178
182
|
var models: () => Promise<ModelId[]>;
|
package/dist/index.js
CHANGED
|
@@ -31399,6 +31399,17 @@ var modelInfoMap = {
|
|
|
31399
31399
|
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 1102 + outputSize / AVERAGE_BYTES_PER_TOKEN * 3268);
|
|
31400
31400
|
}
|
|
31401
31401
|
},
|
|
31402
|
+
"anthropic.claude-3-sonnet-20240229-v1:0": {
|
|
31403
|
+
name: "Claude 3 Sonnet",
|
|
31404
|
+
type: "language" /* Language */,
|
|
31405
|
+
streaming: true,
|
|
31406
|
+
provider: "Anthropic",
|
|
31407
|
+
description: "",
|
|
31408
|
+
version: "v1",
|
|
31409
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
31410
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 300 + outputSize / AVERAGE_BYTES_PER_TOKEN * 1500);
|
|
31411
|
+
}
|
|
31412
|
+
},
|
|
31402
31413
|
"cohere.command-text-v14": {
|
|
31403
31414
|
name: "Command",
|
|
31404
31415
|
type: "language" /* Language */,
|
|
@@ -31474,7 +31485,7 @@ var modelInfoMap = {
|
|
|
31474
31485
|
region: "us-west-2",
|
|
31475
31486
|
// at time of writing, this is the only region that supports this model
|
|
31476
31487
|
type: "language" /* Language */,
|
|
31477
|
-
streaming:
|
|
31488
|
+
streaming: true,
|
|
31478
31489
|
provider: "Mistral",
|
|
31479
31490
|
description: "First foundation model from MistralAI. Ideal for text summarization, question and answering, text classification, text completion, and code generation.",
|
|
31480
31491
|
version: "v0.2",
|
|
@@ -31487,7 +31498,7 @@ var modelInfoMap = {
|
|
|
31487
31498
|
region: "us-west-2",
|
|
31488
31499
|
// at time of writing, this is the only region that supports this model
|
|
31489
31500
|
type: "language" /* Language */,
|
|
31490
|
-
streaming:
|
|
31501
|
+
streaming: true,
|
|
31491
31502
|
provider: "Mistral",
|
|
31492
31503
|
description: "Ideal for text summarization, question and answering, text classification, text completion, and code generation.",
|
|
31493
31504
|
version: "v0.1",
|
|
@@ -31625,8 +31636,39 @@ var AnthropicClaudeChatAdapter = class {
|
|
|
31625
31636
|
}
|
|
31626
31637
|
};
|
|
31627
31638
|
|
|
31628
|
-
// src/chat/adapters/
|
|
31639
|
+
// src/chat/adapters/anthropic.claude.sonnet.ts
|
|
31629
31640
|
var decoder2 = new TextDecoder();
|
|
31641
|
+
var AnthropicClaudeSonnetChatAdapter = class {
|
|
31642
|
+
async buildInput(messages, options) {
|
|
31643
|
+
return {
|
|
31644
|
+
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.",
|
|
31645
|
+
messages: messages.map((message) => ({
|
|
31646
|
+
// Sonnet uses `user` instead of `human` for the user role.
|
|
31647
|
+
role: message.role === "human" ? "user" : message.role,
|
|
31648
|
+
content: message.content
|
|
31649
|
+
})),
|
|
31650
|
+
max_tokens: options.maxTokens ?? 1e3,
|
|
31651
|
+
anthropic_version: "bedrock-2023-05-31"
|
|
31652
|
+
};
|
|
31653
|
+
}
|
|
31654
|
+
formatResponse(response) {
|
|
31655
|
+
if (!response.body) {
|
|
31656
|
+
throw new Error("No response from model");
|
|
31657
|
+
}
|
|
31658
|
+
const transformer = new TransformStream({
|
|
31659
|
+
transform(chunk2, controller) {
|
|
31660
|
+
const event = JSON.parse(decoder2.decode(chunk2));
|
|
31661
|
+
if (event.type === "content_block_delta" && event.delta.type === "text_delta" && event.delta.text) {
|
|
31662
|
+
controller.enqueue(Buffer.from(event.delta.text, "utf8"));
|
|
31663
|
+
}
|
|
31664
|
+
}
|
|
31665
|
+
});
|
|
31666
|
+
return response.body.pipeThrough(transformer);
|
|
31667
|
+
}
|
|
31668
|
+
};
|
|
31669
|
+
|
|
31670
|
+
// src/chat/adapters/ai21.jurassic.ts
|
|
31671
|
+
var decoder3 = new TextDecoder();
|
|
31630
31672
|
function buildPrompt2(messages) {
|
|
31631
31673
|
const messagesCopy = [...messages];
|
|
31632
31674
|
if (messagesCopy.length === 0 || messagesCopy[messagesCopy.length - 1].role !== "assistant") {
|
|
@@ -31683,7 +31725,7 @@ var Ai21JurassicChatAdapter = class {
|
|
|
31683
31725
|
}
|
|
31684
31726
|
const transformer = new TransformStream({
|
|
31685
31727
|
transform(chunk2, controller) {
|
|
31686
|
-
const event = JSON.parse(
|
|
31728
|
+
const event = JSON.parse(decoder3.decode(chunk2));
|
|
31687
31729
|
for (const completion of event.completions) {
|
|
31688
31730
|
controller.enqueue(Buffer.from(completion.data.text, "utf8"));
|
|
31689
31731
|
}
|
|
@@ -31694,7 +31736,7 @@ var Ai21JurassicChatAdapter = class {
|
|
|
31694
31736
|
};
|
|
31695
31737
|
|
|
31696
31738
|
// src/chat/adapters/cohere.command.ts
|
|
31697
|
-
var
|
|
31739
|
+
var decoder4 = new TextDecoder();
|
|
31698
31740
|
function buildPrompt3(messages) {
|
|
31699
31741
|
const messagesCopy = [...messages];
|
|
31700
31742
|
if (messagesCopy.length === 0 || messagesCopy[messagesCopy.length - 1].role !== "assistant") {
|
|
@@ -31721,7 +31763,7 @@ var CohereCommandChatAdapter = class {
|
|
|
31721
31763
|
}
|
|
31722
31764
|
const transformer = new TransformStream({
|
|
31723
31765
|
transform(chunk2, controller) {
|
|
31724
|
-
const event = JSON.parse(
|
|
31766
|
+
const event = JSON.parse(decoder4.decode(chunk2));
|
|
31725
31767
|
if (event.text) {
|
|
31726
31768
|
controller.enqueue(Buffer.from(event.text, "utf8"));
|
|
31727
31769
|
}
|
|
@@ -31732,7 +31774,7 @@ var CohereCommandChatAdapter = class {
|
|
|
31732
31774
|
};
|
|
31733
31775
|
|
|
31734
31776
|
// src/chat/adapters/meta.llama.ts
|
|
31735
|
-
var
|
|
31777
|
+
var decoder5 = new TextDecoder();
|
|
31736
31778
|
function buildPrompt4(messages) {
|
|
31737
31779
|
const messagesCopy = [...messages];
|
|
31738
31780
|
if (messagesCopy.length === 0 || messagesCopy[messagesCopy.length - 1].role !== "assistant") {
|
|
@@ -31758,7 +31800,7 @@ var MetaLlamaChatAdapter = class {
|
|
|
31758
31800
|
}
|
|
31759
31801
|
const transformer = new TransformStream({
|
|
31760
31802
|
transform(chunk2, controller) {
|
|
31761
|
-
const event = JSON.parse(
|
|
31803
|
+
const event = JSON.parse(decoder5.decode(chunk2));
|
|
31762
31804
|
if (event.generation) {
|
|
31763
31805
|
controller.enqueue(Buffer.from(event.generation, "utf8"));
|
|
31764
31806
|
}
|
|
@@ -31769,7 +31811,7 @@ var MetaLlamaChatAdapter = class {
|
|
|
31769
31811
|
};
|
|
31770
31812
|
|
|
31771
31813
|
// src/chat/adapters/mixtral.ts
|
|
31772
|
-
var
|
|
31814
|
+
var decoder6 = new TextDecoder();
|
|
31773
31815
|
function buildPrompt5(messages) {
|
|
31774
31816
|
const messagesCopy = [...messages];
|
|
31775
31817
|
if (messagesCopy.length === 0 || messagesCopy[messagesCopy.length - 1].role !== "assistant") {
|
|
@@ -31797,7 +31839,7 @@ var MixtralAIChatAdapter = class {
|
|
|
31797
31839
|
}
|
|
31798
31840
|
const transformer = new TransformStream({
|
|
31799
31841
|
transform(chunk2, controller) {
|
|
31800
|
-
const event = JSON.parse(
|
|
31842
|
+
const event = JSON.parse(decoder6.decode(chunk2));
|
|
31801
31843
|
if (event.outputs?.length) {
|
|
31802
31844
|
const output = event.outputs.map((o14) => o14.text).join("");
|
|
31803
31845
|
controller.enqueue(Buffer.from(output, "utf8"));
|
|
@@ -31821,6 +31863,7 @@ var adapters = {
|
|
|
31821
31863
|
"anthropic.claude-instant-v1": AnthropicClaudeChatAdapter,
|
|
31822
31864
|
"anthropic.claude-v1": AnthropicClaudeChatAdapter,
|
|
31823
31865
|
"anthropic.claude-v2": AnthropicClaudeChatAdapter,
|
|
31866
|
+
"anthropic.claude-3-sonnet-20240229-v1:0": AnthropicClaudeSonnetChatAdapter,
|
|
31824
31867
|
"ai21.j2-mid-v1": Ai21JurassicChatAdapter,
|
|
31825
31868
|
"ai21.j2-ultra-v1": Ai21JurassicChatAdapter,
|
|
31826
31869
|
"cohere.command-text-v14": CohereCommandChatAdapter,
|
|
@@ -31845,6 +31888,7 @@ chat.models = async () => {
|
|
|
31845
31888
|
"anthropic.claude-instant-v1",
|
|
31846
31889
|
"anthropic.claude-v1",
|
|
31847
31890
|
"anthropic.claude-v2",
|
|
31891
|
+
"anthropic.claude-3-sonnet-20240229-v1:0",
|
|
31848
31892
|
"ai21.j2-mid-v1",
|
|
31849
31893
|
"ai21.j2-ultra-v1",
|
|
31850
31894
|
"cohere.command-text-v14",
|
|
@@ -31935,8 +31979,37 @@ render.models = async () => {
|
|
|
31935
31979
|
return ["stability.stable-diffusion-xl-v0"];
|
|
31936
31980
|
};
|
|
31937
31981
|
|
|
31982
|
+
// src/summarize/adapters/anthropic.claude.sonnet.ts
|
|
31983
|
+
var decoder7 = new TextDecoder();
|
|
31984
|
+
var AnthropicClaudeSonnetSummarizeAdapter = class {
|
|
31985
|
+
async buildInput(input, options) {
|
|
31986
|
+
return {
|
|
31987
|
+
// Sonnet varies from the original Claude model in that it does not take a prompt argument.
|
|
31988
|
+
// see https://github.com/langchain-ai/langchain/issues/18513
|
|
31989
|
+
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.",
|
|
31990
|
+
messages: [{ role: "user", content: input }],
|
|
31991
|
+
anthropic_version: "bedrock-2023-05-31",
|
|
31992
|
+
max_tokens: options.maxTokens ?? 1e3
|
|
31993
|
+
};
|
|
31994
|
+
}
|
|
31995
|
+
formatResponse(response) {
|
|
31996
|
+
if (!response.body) {
|
|
31997
|
+
throw new Error("No response from model");
|
|
31998
|
+
}
|
|
31999
|
+
const transformer = new TransformStream({
|
|
32000
|
+
transform(chunk2, controller) {
|
|
32001
|
+
const event = JSON.parse(decoder7.decode(chunk2));
|
|
32002
|
+
if (event.type === "content_block_delta" && event.delta.type === "text_delta" && event.delta.text) {
|
|
32003
|
+
controller.enqueue(Buffer.from(event.delta.text, "utf8"));
|
|
32004
|
+
}
|
|
32005
|
+
}
|
|
32006
|
+
});
|
|
32007
|
+
return response.body.pipeThrough(transformer);
|
|
32008
|
+
}
|
|
32009
|
+
};
|
|
32010
|
+
|
|
31938
32011
|
// src/summarize/adapters/anthropic.claude.ts
|
|
31939
|
-
var
|
|
32012
|
+
var decoder8 = new TextDecoder();
|
|
31940
32013
|
function buildPrompt6(input) {
|
|
31941
32014
|
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
32015
|
|
|
@@ -31959,7 +32032,7 @@ var AnthropicClaudeSummarizeAdapter = class {
|
|
|
31959
32032
|
}
|
|
31960
32033
|
const transformer = new TransformStream({
|
|
31961
32034
|
transform(chunk2, controller) {
|
|
31962
|
-
const event = JSON.parse(
|
|
32035
|
+
const event = JSON.parse(decoder8.decode(chunk2));
|
|
31963
32036
|
if (event.completion) {
|
|
31964
32037
|
controller.enqueue(Buffer.from(event.completion, "utf8"));
|
|
31965
32038
|
}
|
|
@@ -31970,7 +32043,7 @@ var AnthropicClaudeSummarizeAdapter = class {
|
|
|
31970
32043
|
};
|
|
31971
32044
|
|
|
31972
32045
|
// src/summarize/adapters/mixtral.ts
|
|
31973
|
-
var
|
|
32046
|
+
var decoder9 = new TextDecoder();
|
|
31974
32047
|
function buildPrompt7(input) {
|
|
31975
32048
|
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
32049
|
|
|
@@ -31995,7 +32068,7 @@ var MixtralAISummarizeAdapter = class {
|
|
|
31995
32068
|
}
|
|
31996
32069
|
const transformer = new TransformStream({
|
|
31997
32070
|
transform(chunk2, controller) {
|
|
31998
|
-
const event = JSON.parse(
|
|
32071
|
+
const event = JSON.parse(decoder9.decode(chunk2));
|
|
31999
32072
|
if (event.outputs?.length) {
|
|
32000
32073
|
const output = event.outputs.map((o14) => o14.text).join("");
|
|
32001
32074
|
controller.enqueue(Buffer.from(output, "utf8"));
|
|
@@ -32011,6 +32084,7 @@ var adapters3 = {
|
|
|
32011
32084
|
"anthropic.claude-instant-v1": AnthropicClaudeSummarizeAdapter,
|
|
32012
32085
|
"anthropic.claude-v1": AnthropicClaudeSummarizeAdapter,
|
|
32013
32086
|
"anthropic.claude-v2": AnthropicClaudeSummarizeAdapter,
|
|
32087
|
+
"anthropic.claude-3-sonnet-20240229-v1:0": AnthropicClaudeSonnetSummarizeAdapter,
|
|
32014
32088
|
"mistral.mistral-7b-instruct-v0:2": MixtralAISummarizeAdapter,
|
|
32015
32089
|
"mistral.mixtral-8x7b-instruct-v0:1": MixtralAISummarizeAdapter
|
|
32016
32090
|
};
|
|
@@ -32030,6 +32104,7 @@ summarize.models = async () => {
|
|
|
32030
32104
|
"anthropic.claude-instant-v1",
|
|
32031
32105
|
"anthropic.claude-v1",
|
|
32032
32106
|
"anthropic.claude-v2",
|
|
32107
|
+
"anthropic.claude-3-sonnet-20240229-v1:0",
|
|
32033
32108
|
"mistral.mistral-7b-instruct-v0:2",
|
|
32034
32109
|
"mistral.mixtral-8x7b-instruct-v0:1"
|
|
32035
32110
|
];
|