wirejs-deploy-amplify-basic 0.1.137-llm → 0.1.139-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.
@@ -3,6 +3,6 @@
3
3
  "dependencies": {
4
4
  "jsdom": "^25.0.1",
5
5
  "wirejs-dom": "^1.0.42",
6
- "wirejs-resources": "^0.1.137-llm"
6
+ "wirejs-resources": "^0.1.139-llm"
7
7
  }
8
8
  }
@@ -1,5 +1,5 @@
1
1
  import { LLM as BaseLLM } from 'wirejs-resources';
2
- import { BedrockRuntimeClient, InvokeModelCommand, InvokeModelWithResponseStreamCommand } from '@aws-sdk/client-bedrock-runtime';
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;
@@ -19,7 +19,9 @@ export class LLM extends BaseLLM {
19
19
  convertToBedrockFormat(messages) {
20
20
  return messages.map(msg => ({
21
21
  role: msg.role === 'user' ? 'user' : 'assistant',
22
- content: msg.content
22
+ content: [{
23
+ text: msg.content
24
+ }]
23
25
  }));
24
26
  }
25
27
  getModelId(model) {
@@ -36,54 +38,49 @@ export class LLM extends BaseLLM {
36
38
  return modelMap[model] || model;
37
39
  }
38
40
  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
41
  if (stream) {
45
- const command = new InvokeModelWithResponseStreamCommand({
42
+ const command = new ConverseStreamCommand({
46
43
  modelId,
47
- body,
48
- contentType: 'application/json',
49
- accept: 'application/json'
44
+ messages: this.convertToBedrockFormat(messages),
45
+ inferenceConfig: {
46
+ maxTokens: 10000
47
+ }
50
48
  });
51
49
  return await this.bedrockClient.send(command);
52
50
  }
53
51
  else {
54
- const command = new InvokeModelCommand({
52
+ const command = new ConverseCommand({
55
53
  modelId,
56
- body,
57
- contentType: 'application/json',
58
- accept: 'application/json'
54
+ messages: this.convertToBedrockFormat(messages),
55
+ inferenceConfig: {
56
+ maxTokens: 10000
57
+ }
59
58
  });
60
59
  return await this.bedrockClient.send(command);
61
60
  }
62
61
  }
63
62
  async streamBedrock(response, onChunk) {
63
+ if (!response.stream)
64
+ return null;
64
65
  let content = '';
65
- if (response.body) {
66
- for await (const chunk of response.body) {
67
- if (chunk.chunk?.bytes) {
68
- const data = JSON.parse(new TextDecoder().decode(chunk.chunk.bytes));
69
- if (data.delta?.text) {
70
- content += data.delta.text;
71
- const llmChunk = {
72
- created_at: new Date().toISOString(),
73
- message: {
74
- role: 'assistant',
75
- content: data.delta.text
76
- },
77
- done: false
78
- };
79
- if (onChunk) {
80
- try {
81
- await onChunk(llmChunk);
82
- }
83
- catch (error) {
84
- console.error(error);
85
- }
86
- }
66
+ for await (const chunk of response.stream) {
67
+ const chunkText = chunk.contentBlockDelta?.delta?.text;
68
+ if (chunkText) {
69
+ content += chunkText;
70
+ const llmChunk = {
71
+ created_at: new Date().toISOString(),
72
+ message: {
73
+ role: 'assistant',
74
+ content: chunkText
75
+ },
76
+ done: false
77
+ };
78
+ if (onChunk) {
79
+ try {
80
+ await onChunk(llmChunk);
81
+ }
82
+ catch (error) {
83
+ console.error(error);
87
84
  }
88
85
  }
89
86
  }
@@ -128,7 +125,9 @@ export class LLM extends BaseLLM {
128
125
  // throw a fit wins.
129
126
  for (const model of this.models) {
130
127
  try {
131
- return await this.invokeModel(model, history, onChunk);
128
+ const result = await this.invokeModel(model, history, onChunk);
129
+ if (!result)
130
+ throw new Error("No response from model.");
132
131
  }
133
132
  catch (error) {
134
133
  console.log(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wirejs-deploy-amplify-basic",
3
- "version": "0.1.137-llm",
3
+ "version": "0.1.139-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.137-llm"
47
+ "wirejs-resources": "^0.1.139-llm"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@aws-amplify/backend": "^1.14.0",