From 514823dacafbbddb8c04a2be080f7221b5108e2f Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 9 May 2024 12:11:50 +1000 Subject: [PATCH] FIX: streaming broken in bedrock when chunks are not aligned (#609) Also - Stop caching llm list - this cause llm list in persona to be incorrect - Add more UI to debug screen so you can properly see raw response --- .../components/modal/debug-ai-modal.gjs | 48 ++++++++++++++++++- .../modules/ai-bot/common/bot-replies.scss | 6 +++ config/locales/client.en.yml | 2 + lib/completions/endpoints/aws_bedrock.rb | 45 ++++++++++------- lib/completions/endpoints/base.rb | 18 ++++++- lib/completions/endpoints/cohere.rb | 2 - lib/configuration/llm_enumerator.rb | 14 +++--- .../completions/endpoints/aws_bedrock_spec.rb | 4 ++ 8 files changed, 111 insertions(+), 28 deletions(-) diff --git a/assets/javascripts/discourse/components/modal/debug-ai-modal.gjs b/assets/javascripts/discourse/components/modal/debug-ai-modal.gjs index c61b12fa..d18cb28e 100644 --- a/assets/javascripts/discourse/components/modal/debug-ai-modal.gjs +++ b/assets/javascripts/discourse/components/modal/debug-ai-modal.gjs @@ -1,5 +1,6 @@ import Component from "@glimmer/component"; import { tracked } from "@glimmer/tracking"; +import { on } from "@ember/modifier"; import { action } from "@ember/object"; import { next } from "@ember/runloop"; import { htmlSafe } from "@ember/template"; @@ -14,6 +15,7 @@ import I18n from "discourse-i18n"; export default class DebugAiModal extends Component { @tracked info = null; @tracked justCopiedText = ""; + @tracked activeTab = "request"; constructor() { super(...arguments); @@ -30,7 +32,11 @@ export default class DebugAiModal extends Component { let parsed; try { - parsed = JSON.parse(this.info.raw_request_payload); + if (this.activeTab === "request") { + parsed = JSON.parse(this.info.raw_request_payload); + } else { + return this.formattedResponse(this.info.raw_response_payload); + } } catch (e) { return this.info.raw_request_payload; } @@ -38,6 +44,14 @@ export default class DebugAiModal extends Component { return htmlSafe(this.jsonToHtml(parsed)); } + formattedResponse(response) { + // we need to replace the new lines with
to make it look good + const split = response.split("\n"); + const safe = split.map((line) => escapeExpression(line)).join("
"); + + return htmlSafe(safe); + } + jsonToHtml(json) { let html = "