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.
@@ -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.136-llm"
6
+ "wirejs-resources": "^0.1.138-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;
@@ -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 InvokeModelWithResponseStreamCommand({
40
+ const command = new ConverseStreamCommand({
46
41
  modelId,
47
- body,
48
- contentType: 'application/json',
49
- accept: 'application/json'
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 InvokeModelCommand({
50
+ const command = new ConverseCommand({
55
51
  modelId,
56
- body,
57
- contentType: 'application/json',
58
- accept: 'application/json'
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
- 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
- }
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
- return await this.invokeModel(model, history, onChunk);
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.136-llm",
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.136-llm"
47
+ "wirejs-resources": "^0.1.138-llm"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@aws-amplify/backend": "^1.14.0",