@ampt/ai 2.0.5 → 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.
@@ -0,0 +1,192 @@
1
+ import { Translate } from '@aws-sdk/client-translate';
2
+
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
+ declare function models(): Promise<string[]>;
5
+ declare enum ModelType {
6
+ Embeddings = "embeddings",
7
+ Language = "language",
8
+ Image = "image"
9
+ }
10
+ type EmbeddingsInferenceCostFunction = (body: Uint8Array) => number;
11
+ type LanguageInferenceCostFunction = (inputSize: number, outputSize: number) => number;
12
+ type ImageInferenceCostFunction = (width: number, height: number, steps: number) => number;
13
+ type InferenceCostFunction = EmbeddingsInferenceCostFunction | LanguageInferenceCostFunction | ImageInferenceCostFunction;
14
+ interface ModelInfo {
15
+ name: string;
16
+ type: ModelType;
17
+ streaming: boolean;
18
+ provider: string;
19
+ description: string;
20
+ version: string;
21
+ region?: string;
22
+ inferenceUsage: InferenceCostFunction;
23
+ }
24
+ interface LanguageModelInfo extends ModelInfo {
25
+ type: ModelType.Language;
26
+ inferenceUsage: LanguageInferenceCostFunction;
27
+ }
28
+ interface ImageModelInfo extends ModelInfo {
29
+ type: ModelType.Image;
30
+ inferenceUsage: ImageInferenceCostFunction;
31
+ }
32
+ interface EmbeddingsModelInfo extends ModelInfo {
33
+ type: ModelType.Embeddings;
34
+ inferenceUsage: EmbeddingsInferenceCostFunction;
35
+ }
36
+ type ModelInfoMap = {
37
+ [id in ModelId]: EmbeddingsModelInfo | LanguageModelInfo | ImageModelInfo;
38
+ };
39
+ /**
40
+ * Model pricing info:
41
+ *
42
+ * Note: we track usage in micro-cents/uc (1,000,000ths of a cent, or 100,000,000ths of a dollar) because
43
+ * the quota system only works with integers.
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
+ * 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
+ *
65
+ * Cohere Command:
66
+ * - $0.0015 per 1000 input tokens: 150 uc per token
67
+ * - $0.0020 per 1000 output tokens: 200 uc per token
68
+ *
69
+ * Cohere Command Light:
70
+ * - $0.0003 per 1000 input tokens: 30 uc per token
71
+ * - $0.0006 per 1000 output tokens: 60 uc per token
72
+ *
73
+ * Cohere Embed - English:
74
+ * - $0.0001 for 1000 input tokens: 10 uc per token
75
+ *
76
+ * Cohere Embed - Multilingual:
77
+ * - $0.0001 for 1000 input tokens: 10 uc per token
78
+ *
79
+ * Meta Llama 2 Chat (13B):
80
+ * - $0.00075 per 1000 input tokens: 75 uc per token
81
+ * - $0.001 per 1000 output tokens: 100 uc per token
82
+ *
83
+ * Mistral 7B:
84
+ * - $.00015 per 1000 input tokens: 15 uc per token
85
+ * - $.0002 per 1000 output tokens: 20 uc per token
86
+ *
87
+ * MixTral 8x7B:
88
+ * - $0.00045 per 1000 input tokens: 45 uc per token
89
+ * - $0.0007 per 1000 output tokens: 70 uc per token
90
+ *
91
+ * Stable Diffusion XL:
92
+ *
93
+ * small format (512x512 or smaller):
94
+ * - standard quality: 1800000 per image
95
+ * - high quality: 3600000 per image
96
+ *
97
+ * large format (larger than 512x512):
98
+ * - standard quality: 3600000 per image (2x more expensive than small format)
99
+ * - high quality: 7200000 per image (2x more expensive than small format)
100
+ *
101
+ * Amazon Titan Embeddings:
102
+ * - $0.0001 for 1000 input tokens: 10 uc per token
103
+ */
104
+ declare const modelInfoMap: ModelInfoMap;
105
+ declare function getModelInfo(id: ModelId): EmbeddingsModelInfo | LanguageModelInfo | ImageModelInfo;
106
+
107
+ interface InvokeOptions {
108
+ modelId: ModelId;
109
+ body: any;
110
+ contentType?: string;
111
+ accept?: string;
112
+ }
113
+ /**
114
+ * Invoke model and return events as a ReadableStream.
115
+ * @param options
116
+ * @returns
117
+ */
118
+ declare function invoke(options: InvokeOptions): Promise<Response>;
119
+
120
+ type MessageRole = 'assistant' | 'human' | 'user';
121
+ interface ResponseWithBody extends Response {
122
+ body: ReadableStream<any>;
123
+ }
124
+ /**
125
+ * A message to send to the model
126
+ * @param role The role of the message (assistant or human)
127
+ * @param content The content of the message
128
+ */
129
+ declare class ChatMessage {
130
+ role: MessageRole;
131
+ content: string;
132
+ constructor({ content, role }: {
133
+ role: MessageRole;
134
+ content: string;
135
+ });
136
+ }
137
+ interface ChatOptions {
138
+ modelId?: ChatModelId;
139
+ maxTokens?: number;
140
+ }
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';
142
+ /**
143
+ * Send messages to the model and return the completion
144
+ * @param messages Array of messages to send to the model
145
+ * @returns Chat completion as a ReadableStream
146
+ */
147
+ declare function chat(messages: ChatMessage[], options?: ChatOptions): Promise<Response>;
148
+ declare namespace chat {
149
+ var models: () => Promise<ModelId[]>;
150
+ }
151
+
152
+ type EmbedModelId = 'amazon.titan-embed-text-v1' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3';
153
+ type Embedding = number[];
154
+ interface EmbedOptions {
155
+ modelId?: EmbedModelId;
156
+ }
157
+ declare function embed(input: string, options?: EmbedOptions): Promise<Embedding>;
158
+ declare namespace embed {
159
+ var models: () => Promise<string[]>;
160
+ }
161
+
162
+ interface RenderOptions {
163
+ width?: number;
164
+ height?: number;
165
+ modelId?: ModelId;
166
+ steps?: number;
167
+ seed?: number;
168
+ scale?: number;
169
+ }
170
+ declare function render(prompt: string, options?: RenderOptions): Promise<Response>;
171
+ declare namespace render {
172
+ var models: () => Promise<string[]>;
173
+ }
174
+
175
+ interface SummarizeOptions {
176
+ modelId?: SummarizeModelId;
177
+ maxTokens?: number;
178
+ }
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';
180
+ declare function summarize(input: string, options?: SummarizeOptions): Promise<Response>;
181
+ declare namespace summarize {
182
+ var models: () => Promise<ModelId[]>;
183
+ }
184
+
185
+ interface TranslateOptions {
186
+ sourceLanguage: string;
187
+ targetLanguage: string;
188
+ }
189
+ declare const client: Translate;
190
+ declare function translate(input: string, options: TranslateOptions): Promise<Response>;
191
+
192
+ export { ChatMessage, type ChatModelId, type ChatOptions, type EmbedModelId, type EmbedOptions, type Embedding, type EmbeddingsModelInfo, type ImageModelInfo, type InvokeOptions, type LanguageModelInfo, type MessageRole, type ModelId, type ModelInfo, ModelType, type RenderOptions, type ResponseWithBody, type SummarizeModelId, type SummarizeOptions, type TranslateOptions, chat, client, embed, getModelInfo, invoke, modelInfoMap, models, render, summarize, translate };
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';
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",
@@ -18,6 +18,7 @@ interface ModelInfo {
18
18
  provider: string;
19
19
  description: string;
20
20
  version: string;
21
+ region?: string;
21
22
  inferenceUsage: InferenceCostFunction;
22
23
  }
23
24
  interface LanguageModelInfo extends ModelInfo {
@@ -57,6 +58,10 @@ type ModelInfoMap = {
57
58
  * - $0.01102 per 1000 input tokens: 1102 uc per token
58
59
  * - $0.03268 per 1000 output tokens: 3268 uc per token
59
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
+ *
60
65
  * Cohere Command:
61
66
  * - $0.0015 per 1000 input tokens: 150 uc per token
62
67
  * - $0.0020 per 1000 output tokens: 200 uc per token
@@ -75,6 +80,14 @@ type ModelInfoMap = {
75
80
  * - $0.00075 per 1000 input tokens: 75 uc per token
76
81
  * - $0.001 per 1000 output tokens: 100 uc per token
77
82
  *
83
+ * Mistral 7B:
84
+ * - $.00015 per 1000 input tokens: 15 uc per token
85
+ * - $.0002 per 1000 output tokens: 20 uc per token
86
+ *
87
+ * MixTral 8x7B:
88
+ * - $0.00045 per 1000 input tokens: 45 uc per token
89
+ * - $0.0007 per 1000 output tokens: 70 uc per token
90
+ *
78
91
  * Stable Diffusion XL:
79
92
  *
80
93
  * small format (512x512 or smaller):
@@ -89,7 +102,7 @@ type ModelInfoMap = {
89
102
  * - $0.0001 for 1000 input tokens: 10 uc per token
90
103
  */
91
104
  declare const modelInfoMap: ModelInfoMap;
92
- declare function getModelInfo(id: ModelId): Promise<EmbeddingsModelInfo | LanguageModelInfo | ImageModelInfo>;
105
+ declare function getModelInfo(id: ModelId): EmbeddingsModelInfo | LanguageModelInfo | ImageModelInfo;
93
106
 
94
107
  interface InvokeOptions {
95
108
  modelId: ModelId;
@@ -104,7 +117,7 @@ interface InvokeOptions {
104
117
  */
105
118
  declare function invoke(options: InvokeOptions): Promise<Response>;
106
119
 
107
- type MessageRole = 'assistant' | 'human';
120
+ type MessageRole = 'assistant' | 'human' | 'user';
108
121
  interface ResponseWithBody extends Response {
109
122
  body: ReadableStream<any>;
110
123
  }
@@ -125,7 +138,7 @@ interface ChatOptions {
125
138
  modelId?: ChatModelId;
126
139
  maxTokens?: number;
127
140
  }
128
- 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';
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';
129
142
  /**
130
143
  * Send messages to the model and return the completion
131
144
  * @param messages Array of messages to send to the model
@@ -163,7 +176,7 @@ interface SummarizeOptions {
163
176
  modelId?: SummarizeModelId;
164
177
  maxTokens?: number;
165
178
  }
166
- type SummarizeModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v1' | 'anthropic.claude-v2';
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';
167
180
  declare function summarize(input: string, options?: SummarizeOptions): Promise<Response>;
168
181
  declare namespace summarize {
169
182
  var models: () => Promise<ModelId[]>;
@@ -176,4 +189,4 @@ interface TranslateOptions {
176
189
  declare const client: Translate;
177
190
  declare function translate(input: string, options: TranslateOptions): Promise<Response>;
178
191
 
179
- export { ChatMessage, ChatModelId, ChatOptions, EmbedModelId, EmbedOptions, Embedding, EmbeddingsModelInfo, ImageModelInfo, InvokeOptions, LanguageModelInfo, MessageRole, ModelId, ModelInfo, ModelType, RenderOptions, ResponseWithBody, SummarizeModelId, SummarizeOptions, TranslateOptions, chat, client, embed, getModelInfo, invoke, modelInfoMap, models, render, summarize, translate };
192
+ export { ChatMessage, type ChatModelId, type ChatOptions, type EmbedModelId, type EmbedOptions, type Embedding, type EmbeddingsModelInfo, type ImageModelInfo, type InvokeOptions, type LanguageModelInfo, type MessageRole, type ModelId, type ModelInfo, ModelType, type RenderOptions, type ResponseWithBody, type SummarizeModelId, type SummarizeOptions, type TranslateOptions, chat, client, embed, getModelInfo, invoke, modelInfoMap, models, render, summarize, translate };