@bedrockio/ai 0.9.2 → 0.9.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.9.3
2
+
3
+ - Further fixes for empty input.
4
+
1
5
  ## 0.9.2
2
6
 
3
7
  - Strip empty input out of resulting messages.
@@ -110,7 +110,7 @@ class BaseClient {
110
110
  getFilteredMessages(options) {
111
111
  const { messages = [] } = options;
112
112
  return messages.filter((message) => {
113
- return message.content;
113
+ return message.content.trim();
114
114
  });
115
115
  }
116
116
  // Protected
@@ -220,19 +220,30 @@ class BaseClient {
220
220
  if (Array.isArray(input) && !input.length) {
221
221
  input = '';
222
222
  }
223
+ let result = [];
223
224
  if (Array.isArray(input)) {
224
- return input;
225
+ result = input;
225
226
  }
226
227
  else {
227
228
  const { messages = [] } = options;
228
- return [
229
+ result = [
229
230
  ...messages,
230
231
  {
231
232
  role: 'user',
232
- content: input || '',
233
+ content: input,
233
234
  },
234
235
  ];
235
236
  }
237
+ if (result.length === 1 && !result[0].content) {
238
+ // If a single user input is passed and is nullish, coerce it to a
239
+ // single space. Combined with getFilteredMessages below this allows
240
+ // a chatbot the ability to "speak first" by prompting it with empty
241
+ // content. The empty message will be filtered out of the final result
242
+ // appearing as if the chatbot went first. Note empty string will also
243
+ // fail here hence the single space.
244
+ result[0].content = ' ';
245
+ }
246
+ return result;
236
247
  }
237
248
  normalizeSchema(options) {
238
249
  let { schema } = options;
@@ -108,7 +108,7 @@ export default class BaseClient {
108
108
  getFilteredMessages(options) {
109
109
  const { messages = [] } = options;
110
110
  return messages.filter((message) => {
111
- return message.content;
111
+ return message.content.trim();
112
112
  });
113
113
  }
114
114
  // Protected
@@ -218,19 +218,30 @@ export default class BaseClient {
218
218
  if (Array.isArray(input) && !input.length) {
219
219
  input = '';
220
220
  }
221
+ let result = [];
221
222
  if (Array.isArray(input)) {
222
- return input;
223
+ result = input;
223
224
  }
224
225
  else {
225
226
  const { messages = [] } = options;
226
- return [
227
+ result = [
227
228
  ...messages,
228
229
  {
229
230
  role: 'user',
230
- content: input || '',
231
+ content: input,
231
232
  },
232
233
  ];
233
234
  }
235
+ if (result.length === 1 && !result[0].content) {
236
+ // If a single user input is passed and is nullish, coerce it to a
237
+ // single space. Combined with getFilteredMessages below this allows
238
+ // a chatbot the ability to "speak first" by prompting it with empty
239
+ // content. The empty message will be filtered out of the final result
240
+ // appearing as if the chatbot went first. Note empty string will also
241
+ // fail here hence the single space.
242
+ result[0].content = ' ';
243
+ }
244
+ return result;
234
245
  }
235
246
  normalizeSchema(options) {
236
247
  let { schema } = options;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/ai",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "Bedrock wrapper for common AI chatbots.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -1 +1 @@
1
- {"version":3,"file":"BaseClient.d.ts","sourceRoot":"","sources":["../src/BaseClient.js"],"names":[],"mappings":"AAKA;IACE,0BASC;IARC,aAIC;IACD,2BAEE;IAKJ;;;;;OAKG;IACH,gBAFW,aAAa,gBAiCvB;IAED;;;;;OAKG;IACH,gBAHW,aAAa,GAAG,aAAa,gCAsDvC;IAED;;;;OAIG;IACH,wBAFW,MAAM,OAIhB;IAED,uCAKC;IAID,8BAGC;IAED,8BAGC;IAED,qCAGC;IAED;;OAEG;IACH,0CAGC;IAED;;OAEG;IACH,oDAIC;IAED;;OAEG;IACH,oDAIC;IAID;;OAEG;IACH,oCAOC;IAED;;;MAeC;IAED,4CAiDC;IAED,uCAoBC;IAED;;;MA4BC;IAED,uDAWC;IAED,kDAMC;CACF;;;;;WAIa,MAAM;kBACN,MAAM;;;;cACN,aAAa,EAAE;;;;YACf,MAAM;;;;YACN,OAAO;;;;;;;;aAEP,MAAM,GAAG,MAAM;;;;;;;;;;;sBAOf,MAAM;;;UAKN,QAAQ,GAAG,MAAM,GAAG,WAAW;aAC/B,MAAM;;iCAjWa,sBAAsB"}
1
+ {"version":3,"file":"BaseClient.d.ts","sourceRoot":"","sources":["../src/BaseClient.js"],"names":[],"mappings":"AAKA;IACE,0BASC;IARC,aAIC;IACD,2BAEE;IAKJ;;;;;OAKG;IACH,gBAFW,aAAa,gBAiCvB;IAED;;;;;OAKG;IACH,gBAHW,aAAa,GAAG,aAAa,gCAsDvC;IAED;;;;OAIG;IACH,wBAFW,MAAM,OAIhB;IAED,uCAKC;IAID,8BAGC;IAED,8BAGC;IAED,qCAGC;IAED;;OAEG;IACH,0CAGC;IAED;;OAEG;IACH,oDAIC;IAED;;OAEG;IACH,oDAIC;IAID;;OAEG;IACH,oCAOC;IAED;;;MAeC;IAED,4CAiDC;IAED,uCAkCC;IAED;;;MA4BC;IAED,uDAWC;IAED,kDAMC;CACF;;;;;WAIa,MAAM;kBACN,MAAM;;;;cACN,aAAa,EAAE;;;;YACf,MAAM;;;;YACN,OAAO;;;;;;;;aAEP,MAAM,GAAG,MAAM;;;;;;;;;;;sBAOf,MAAM;;;UAKN,QAAQ,GAAG,MAAM,GAAG,WAAW;aAC/B,MAAM;;iCA/Wa,sBAAsB"}