@bedrockio/ai 0.8.3 → 0.8.4

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,8 @@
1
+ ## 0.8.4
2
+
3
+ - Fixed issue with user roles parsed from template is injected into conversation
4
+ history.
5
+
1
6
  ## 0.8.3
2
7
 
3
8
  - Fixed issue with message history not being retained.
@@ -177,13 +177,20 @@ class BaseClient {
177
177
  });
178
178
  let system = '';
179
179
  let { messages = [] } = options;
180
+ // Templates may contain multiple roles, ie SYSTEM or USER, making them
181
+ // useful for one-off prompting. However in a multi-turn conversation
182
+ // the entire chat history will be passed, so do not inject user messages
183
+ // when they already exist in the options.
184
+ const hasUserMessages = messages.some((message) => {
185
+ return message.role === 'user';
186
+ });
180
187
  for (let section of sections) {
181
188
  const { title = 'system', content } = section;
182
189
  const role = title.toLowerCase();
183
190
  if (role === 'system') {
184
191
  system += [system, content].join('\n');
185
192
  }
186
- else {
193
+ else if (!hasUserMessages) {
187
194
  messages = [
188
195
  ...messages,
189
196
  {
@@ -175,13 +175,20 @@ export default class BaseClient {
175
175
  });
176
176
  let system = '';
177
177
  let { messages = [] } = options;
178
+ // Templates may contain multiple roles, ie SYSTEM or USER, making them
179
+ // useful for one-off prompting. However in a multi-turn conversation
180
+ // the entire chat history will be passed, so do not inject user messages
181
+ // when they already exist in the options.
182
+ const hasUserMessages = messages.some((message) => {
183
+ return message.role === 'user';
184
+ });
178
185
  for (let section of sections) {
179
186
  const { title = 'system', content } = section;
180
187
  const role = title.toLowerCase();
181
188
  if (role === 'system') {
182
189
  system += [system, content].join('\n');
183
190
  }
184
- else {
191
+ else if (!hasUserMessages) {
185
192
  messages = [
186
193
  ...messages,
187
194
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/ai",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
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,gBAgCvB;IAED;;;;;OAKG;IACH,gBAHW,aAAa,GAAG,aAAa,gCAsDvC;IAED;;;;OAIG;IACH,wBAFW,MAAM,OAIhB;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,4CAyCC;IAED,uCAoBC;IAED;;;MA4BC;IAED,uDAWC;IAED,kDAMC;CACF;;;;;WAIa,MAAM,GAAC,aAAa,EAAE;;;;YACtB,MAAM;;;;YACN,OAAO;;;;;;;;aAEP,MAAM,GAAG,MAAM;;;;;;;;;;;sBAOf,MAAM;;;UAKN,QAAQ,GAAG,MAAM,GAAG,WAAW;aAC/B,MAAM;;iCA/Ua,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,gBAgCvB;IAED;;;;;OAKG;IACH,gBAHW,aAAa,GAAG,aAAa,gCAsDvC;IAED;;;;OAIG;IACH,wBAFW,MAAM,OAIhB;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,GAAC,aAAa,EAAE;;;;YACtB,MAAM;;;;YACN,OAAO;;;;;;;;aAEP,MAAM,GAAG,MAAM;;;;;;;;;;;sBAOf,MAAM;;;UAKN,QAAQ,GAAG,MAAM,GAAG,WAAW;aAC/B,MAAM;;iCAvVa,sBAAsB"}