This PR introduces 3 things: 1. Fake bot that can be used on local so you can test LLMs, to enable on dev use: SiteSetting.ai_bot_enabled_chat_bots = "fake" 2. More elegant smooth streaming of progress on LLM completion This leans on JavaScript to buffer and trickle llm results through. It also amends it so the progress dot is much more consistently rendered 3. It fixes the Claude dialect Claude needs newlines **exactly** at the right spot, amended so it is happy --------- Co-authored-by: Martin Brennan <[email protected]>
73 lines
1.8 KiB
JavaScript
73 lines
1.8 KiB
JavaScript
import { module, test } from "qunit";
|
|
import { addProgressDot } from "discourse/plugins/discourse-ai/discourse/lib/ai-streamer";
|
|
|
|
module("Discourse AI | Unit | Lib | ai-streamer", function () {
|
|
function confirmPlaceholder(html, expected, assert) {
|
|
const element = document.createElement("div");
|
|
element.innerHTML = html;
|
|
|
|
const expectedElement = document.createElement("div");
|
|
expectedElement.innerHTML = expected;
|
|
|
|
addProgressDot(element);
|
|
|
|
assert.equal(element.innerHTML, expectedElement.innerHTML);
|
|
}
|
|
|
|
test("inserts progress span in correct location for simple div", function (assert) {
|
|
const html = "<div>hello world<div>hello 2</div></div>";
|
|
const expected =
|
|
"<div>hello world<div>hello 2<span class='progress-dot'></span></div></div>";
|
|
|
|
confirmPlaceholder(html, expected, assert);
|
|
});
|
|
|
|
test("inserts progress span in correct location for lists", function (assert) {
|
|
const html = "<p>test</p><ul><li>hello world</li><li>hello world</li></ul>";
|
|
const expected =
|
|
"<p>test</p><ul><li>hello world</li><li>hello world<span class='progress-dot'></span></li></ul>";
|
|
|
|
confirmPlaceholder(html, expected, assert);
|
|
});
|
|
|
|
test("inserts correctly if list has blank html nodes", function (assert) {
|
|
const html = `<ul>
|
|
<li><strong>Bold Text</strong>: To</li>
|
|
|
|
</ul>`;
|
|
|
|
const expected = `<ul>
|
|
<li><strong>Bold Text</strong>: To<span class="progress-dot"></span></li>
|
|
|
|
</ul>`;
|
|
|
|
confirmPlaceholder(html, expected, assert);
|
|
});
|
|
|
|
test("inserts correctly for tables", function (assert) {
|
|
const html = `<table>
|
|
<tbody>
|
|
<tr>
|
|
<td>Bananas</td>
|
|
<td>20</td>
|
|
<td>$0.50</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
`;
|
|
|
|
const expected = `<table>
|
|
<tbody>
|
|
<tr>
|
|
<td>Bananas</td>
|
|
<td>20</td>
|
|
<td>$0.50<span class="progress-dot"></span></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
`;
|
|
|
|
confirmPlaceholder(html, expected, assert);
|
|
});
|
|
});
|