wirejs-deploy-amplify-basic 0.1.136-llm → 0.1.138-llm
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/services/llm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LLM as BaseLLM } from 'wirejs-resources';
|
|
2
|
-
import { BedrockRuntimeClient,
|
|
2
|
+
import { BedrockRuntimeClient, ConverseCommand, ConverseStreamCommand, } from '@aws-sdk/client-bedrock-runtime';
|
|
3
3
|
import { defaultProvider } from '@aws-sdk/credential-provider-node';
|
|
4
4
|
export class LLM extends BaseLLM {
|
|
5
5
|
bedrockClient;
|
|
@@ -36,54 +36,49 @@ export class LLM extends BaseLLM {
|
|
|
36
36
|
return modelMap[model] || model;
|
|
37
37
|
}
|
|
38
38
|
async invokeBedrock(modelId, messages, stream) {
|
|
39
|
-
const body = JSON.stringify({
|
|
40
|
-
anthropic_version: "bedrock-2023-05-31",
|
|
41
|
-
max_tokens: 10000,
|
|
42
|
-
messages: this.convertToBedrockFormat(messages)
|
|
43
|
-
});
|
|
44
39
|
if (stream) {
|
|
45
|
-
const command = new
|
|
40
|
+
const command = new ConverseStreamCommand({
|
|
46
41
|
modelId,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
messages: this.convertToBedrockFormat(messages),
|
|
43
|
+
inferenceConfig: {
|
|
44
|
+
maxTokens: 10000
|
|
45
|
+
}
|
|
50
46
|
});
|
|
51
47
|
return await this.bedrockClient.send(command);
|
|
52
48
|
}
|
|
53
49
|
else {
|
|
54
|
-
const command = new
|
|
50
|
+
const command = new ConverseCommand({
|
|
55
51
|
modelId,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
messages: this.convertToBedrockFormat(messages),
|
|
53
|
+
inferenceConfig: {
|
|
54
|
+
maxTokens: 10000
|
|
55
|
+
}
|
|
59
56
|
});
|
|
60
57
|
return await this.bedrockClient.send(command);
|
|
61
58
|
}
|
|
62
59
|
}
|
|
63
60
|
async streamBedrock(response, onChunk) {
|
|
61
|
+
if (!response.stream)
|
|
62
|
+
return null;
|
|
64
63
|
let content = '';
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
catch (error) {
|
|
84
|
-
console.error(error);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
64
|
+
for await (const chunk of response.stream) {
|
|
65
|
+
const chunkText = chunk.contentBlockDelta?.delta?.text;
|
|
66
|
+
if (chunkText) {
|
|
67
|
+
content += chunkText;
|
|
68
|
+
const llmChunk = {
|
|
69
|
+
created_at: new Date().toISOString(),
|
|
70
|
+
message: {
|
|
71
|
+
role: 'assistant',
|
|
72
|
+
content: chunkText
|
|
73
|
+
},
|
|
74
|
+
done: false
|
|
75
|
+
};
|
|
76
|
+
if (onChunk) {
|
|
77
|
+
try {
|
|
78
|
+
await onChunk(llmChunk);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
console.error(error);
|
|
87
82
|
}
|
|
88
83
|
}
|
|
89
84
|
}
|
|
@@ -128,7 +123,9 @@ export class LLM extends BaseLLM {
|
|
|
128
123
|
// throw a fit wins.
|
|
129
124
|
for (const model of this.models) {
|
|
130
125
|
try {
|
|
131
|
-
|
|
126
|
+
const result = await this.invokeModel(model, history, onChunk);
|
|
127
|
+
if (!result)
|
|
128
|
+
throw new Error("No response from model.");
|
|
132
129
|
}
|
|
133
130
|
catch (error) {
|
|
134
131
|
console.log(error);
|
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.138-llm",
|
|
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.42",
|
|
47
|
-
"wirejs-resources": "^0.1.
|
|
47
|
+
"wirejs-resources": "^0.1.138-llm"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@aws-amplify/backend": "^1.14.0",
|