wirejs-deploy-amplify-basic 0.1.163-llm → 0.1.165
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.
|
@@ -51,6 +51,10 @@ function createContext(event: APIGatewayProxyEventV2) {
|
|
|
51
51
|
description: 'HTTP origin (base address) for machines outside your network to use. Only populated for `npm run start:public`, and only accessible in environments that support NAT-PMP.',
|
|
52
52
|
value: location.origin
|
|
53
53
|
}),
|
|
54
|
+
new SystemAttribute('wirejs', 'aws-region', {
|
|
55
|
+
description: 'AWS region where the application is deployed.',
|
|
56
|
+
value: env.AWS_REGION || 'unknown'
|
|
57
|
+
}),
|
|
54
58
|
]
|
|
55
59
|
});
|
|
56
60
|
} catch {
|
package/build.js
CHANGED
|
@@ -103,64 +103,6 @@ async function discoverResources() {
|
|
|
103
103
|
);
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
// /**
|
|
107
|
-
// *
|
|
108
|
-
// * @returns {string[]}
|
|
109
|
-
// */
|
|
110
|
-
// function discoverApiDeps() {
|
|
111
|
-
// return execSync(`npm ls --omit=dev --all --parseable -w ./api`)
|
|
112
|
-
// .toString()
|
|
113
|
-
// .split('\n')
|
|
114
|
-
// .map(line => line.trim())
|
|
115
|
-
// .filter(line => line.includes('node_modules'));
|
|
116
|
-
// }
|
|
117
|
-
|
|
118
|
-
// async function installApiDeps() {
|
|
119
|
-
// console.log("adding deps to package.json");
|
|
120
|
-
// // add deps used by Amplify to deploy backend
|
|
121
|
-
// const packageData = JSON.parse(
|
|
122
|
-
// await fs.promises.readFile(path.join(LAMBDA_BUILD_DIR, 'package.json'))
|
|
123
|
-
// );
|
|
124
|
-
// packageData.dependencies = {
|
|
125
|
-
// 'jose': '^6.1.0',
|
|
126
|
-
// ...(packageData.dependencies || {}),
|
|
127
|
-
// 'wirejs-resources': `file:${SELF_DIR}`
|
|
128
|
-
// };
|
|
129
|
-
// await fs.promises.writeFile(
|
|
130
|
-
// path.join(LAMBDA_BUILD_DIR, 'package.json'),
|
|
131
|
-
// JSON.stringify(packageData, null, 2)
|
|
132
|
-
// );
|
|
133
|
-
|
|
134
|
-
// console.log("installing all deps")
|
|
135
|
-
|
|
136
|
-
// // install all
|
|
137
|
-
// execSync('npm i');
|
|
138
|
-
|
|
139
|
-
// console.log("done installing deps");
|
|
140
|
-
// }
|
|
141
|
-
|
|
142
|
-
// /**
|
|
143
|
-
// *
|
|
144
|
-
// * @param {string[]} deps
|
|
145
|
-
// */
|
|
146
|
-
// async function prepareApiLambda(deps) {
|
|
147
|
-
// await copy
|
|
148
|
-
// (path.join(CWD, 'api', 'dist'),
|
|
149
|
-
// path.join(LAMBDA_BUILD_DIR, 'dist')
|
|
150
|
-
// );
|
|
151
|
-
// await copy(
|
|
152
|
-
// path.join(CWD, 'api', 'dist', 'package.json'),
|
|
153
|
-
// path.join(LAMBDA_BUILD_DIR, 'dist', 'package.json')
|
|
154
|
-
// );
|
|
155
|
-
|
|
156
|
-
// buildSync({
|
|
157
|
-
// entryPoints: path.join(LAMBDA_BUILD_DIR, 'handler.ts'),
|
|
158
|
-
// bundle: true,
|
|
159
|
-
// packages: 'external',
|
|
160
|
-
// outfile: 'handler.js',
|
|
161
|
-
// });
|
|
162
|
-
// }
|
|
163
|
-
|
|
164
106
|
async function deployFrontend() {
|
|
165
107
|
console.log("copying frontend assets");
|
|
166
108
|
await copy(PROJECT_DIST_DIR, STATIC_DIR);
|
package/dist/services/llm.d.ts
CHANGED
package/dist/services/llm.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { LLM as BaseLLM } from 'wirejs-resources';
|
|
2
2
|
import { BedrockRuntimeClient, ConverseCommand, ConverseStreamCommand, } from '@aws-sdk/client-bedrock-runtime';
|
|
3
3
|
import { defaultProvider } from '@aws-sdk/credential-provider-node';
|
|
4
|
+
import { env } from 'process';
|
|
4
5
|
export class LLM extends BaseLLM {
|
|
5
6
|
bedrockClient;
|
|
6
7
|
constructor(scope, id, options) {
|
|
@@ -53,19 +54,60 @@ export class LLM extends BaseLLM {
|
|
|
53
54
|
}
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
'
|
|
61
|
-
'
|
|
62
|
-
'
|
|
63
|
-
'
|
|
64
|
-
|
|
65
|
-
'
|
|
66
|
-
'
|
|
57
|
+
getModelAliases() {
|
|
58
|
+
return {
|
|
59
|
+
// Anthropic Claude
|
|
60
|
+
'anthropic.claude-3-5-sonnet-20241022-v2:0': ['claude', 'claude-3.5-sonnet'],
|
|
61
|
+
'anthropic.claude-3-sonnet-20240229-v1:0': ['claude-3-sonnet'],
|
|
62
|
+
'anthropic.claude-3-5-haiku-20241022-v1:0': ['claude-3.5-haiku'],
|
|
63
|
+
'anthropic.claude-3-haiku-20240307-v1:0': ['claude-3-haiku'],
|
|
64
|
+
'anthropic.claude-3-opus-20240229-v1:0': ['claude-3-opus'],
|
|
65
|
+
// Meta Llama
|
|
66
|
+
'meta.llama3-2-90b-instruct-v1:0': ['llama3.2'],
|
|
67
|
+
'meta.llama3-2-8b-instruct-v1:0': ['llama3.2-8b'],
|
|
68
|
+
'meta.llama3-1-405b-instruct-v1:0': ['llama3.1'],
|
|
69
|
+
'meta.llama3-70b-instruct-v1:0': ['llama3'],
|
|
70
|
+
// Mistral
|
|
71
|
+
'mistral.mistral-large-2407-v1:0': ['mistral-large', 'mistral'],
|
|
72
|
+
'mistral.mistral-7b-instruct-v0:2': ['mistral-7b'],
|
|
73
|
+
// Amazon Nova (newer)
|
|
74
|
+
'amazon.nova-pro-v1:0': ['nova-pro'],
|
|
75
|
+
'amazon.nova-lite-v1:0': ['nova-lite'],
|
|
76
|
+
'amazon.nova-micro-v1:0': ['nova-micro']
|
|
67
77
|
};
|
|
68
|
-
|
|
78
|
+
}
|
|
79
|
+
getRegionalPrefix() {
|
|
80
|
+
const region = env.AWS_REGION || 'us-east-1';
|
|
81
|
+
if (region.startsWith('us-')) {
|
|
82
|
+
return 'us';
|
|
83
|
+
}
|
|
84
|
+
else if (region.startsWith('eu-')) {
|
|
85
|
+
return 'eu';
|
|
86
|
+
}
|
|
87
|
+
else if (region.startsWith('ap-')) {
|
|
88
|
+
return 'ap';
|
|
89
|
+
}
|
|
90
|
+
else if (region.startsWith('ca-')) {
|
|
91
|
+
return 'us'; // Canada uses US prefix
|
|
92
|
+
}
|
|
93
|
+
else if (region.startsWith('sa-')) {
|
|
94
|
+
return 'us'; // South America uses US prefix
|
|
95
|
+
}
|
|
96
|
+
// Default to US for unknown regions
|
|
97
|
+
return 'us';
|
|
98
|
+
}
|
|
99
|
+
getModelId(model) {
|
|
100
|
+
const normalized = model.trim().toLowerCase();
|
|
101
|
+
const modelAliases = this.getModelAliases();
|
|
102
|
+
for (const [canonicalModelId, aliases] of Object.entries(modelAliases)) {
|
|
103
|
+
if (normalized === canonicalModelId || aliases.includes(normalized)) {
|
|
104
|
+
const regionalPrefix = this.getRegionalPrefix();
|
|
105
|
+
return `${regionalPrefix}.${canonicalModelId}`;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// For unknown models, still apply regional prefix if it looks like a standard model ID
|
|
109
|
+
const regionalPrefix = this.getRegionalPrefix();
|
|
110
|
+
return `${regionalPrefix}.${model}`;
|
|
69
111
|
}
|
|
70
112
|
async invokeBedrock(modelId, systemPrompt, messages, stream, tools, abortSignal) {
|
|
71
113
|
const toolConfig = tools && tools.length > 0 ? {
|
|
@@ -237,15 +279,16 @@ export class LLM extends BaseLLM {
|
|
|
237
279
|
async continueConversation({ history, onChunk, timeoutSeconds, systemPrompt, models, tools, }) {
|
|
238
280
|
const controller = new AbortController();
|
|
239
281
|
let timeoutId;
|
|
282
|
+
const intendedModels = models ?? this.models;
|
|
240
283
|
if (timeoutSeconds) {
|
|
241
284
|
timeoutId = setTimeout(() => {
|
|
242
285
|
controller.abort();
|
|
243
286
|
}, timeoutSeconds * 1000);
|
|
244
287
|
}
|
|
245
288
|
try {
|
|
246
|
-
// models are expected to be given in priority order.
|
|
247
|
-
// throw a fit wins.
|
|
248
|
-
for (const model of
|
|
289
|
+
// models are expected to be given in priority order.
|
|
290
|
+
// first one that doesn't throw a fit wins.
|
|
291
|
+
for (const model of intendedModels) {
|
|
249
292
|
try {
|
|
250
293
|
const result = await this.invokeModel(model, (systemPrompt ?? this.systemPrompt) ?? '', history, onChunk, controller.signal, tools ?? this.tools);
|
|
251
294
|
if (!result)
|
|
@@ -279,13 +322,14 @@ export class LLM extends BaseLLM {
|
|
|
279
322
|
if (timeoutId) {
|
|
280
323
|
clearTimeout(timeoutId);
|
|
281
324
|
}
|
|
282
|
-
const message = this.createBedrockInstructionMessage(`None of the attempted models are
|
|
283
|
-
`
|
|
325
|
+
const message = this.createBedrockInstructionMessage(`None of the attempted models are suitable for this request. ` +
|
|
326
|
+
`Review CloudWatch logs to see the reason why. If necessary:\n\n` +
|
|
284
327
|
`1. Go to AWS Bedrock Console (https://console.aws.amazon.com/bedrock/)\n` +
|
|
285
328
|
`2. Navigate to "Model access"\n` +
|
|
286
|
-
`3. Request access to the model\n` +
|
|
287
|
-
`
|
|
288
|
-
`
|
|
329
|
+
`3. Request access to and accept the model's End User License Agreement (EULA)\n\n` +
|
|
330
|
+
`Models attempted: ${intendedModels.join(', ')}\n\n` +
|
|
331
|
+
`Note: The following friendly aliases are available:\n` +
|
|
332
|
+
`${Object.entries(this.getModelAliases()).map(([name, aliases]) => `${name}: ${aliases.join(', ')}`).join('\n')}`);
|
|
289
333
|
if (onChunk) {
|
|
290
334
|
try {
|
|
291
335
|
await onChunk({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wirejs-deploy-amplify-basic",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.165",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"recursive-copy": "^2.0.14",
|
|
45
45
|
"rimraf": "^6.0.1",
|
|
46
46
|
"wirejs-dom": "^1.0.44",
|
|
47
|
-
"wirejs-resources": "^0.1.
|
|
47
|
+
"wirejs-resources": "^0.1.165"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@aws-amplify/backend": "^1.14.0",
|