From c382d3e6e23140c3182d329672586c7a8063efdf Mon Sep 17 00:00:00 2001
From: simon chauvin <simon.chauvin@accenture.com>
Date: Fri, 10 Jan 2025 09:36:00 +0100
Subject: [PATCH] fix - resolve error for http-slash-command

---
 core/commands/slash/http.ts | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/core/commands/slash/http.ts b/core/commands/slash/http.ts
index 2f5e2a7afb..7a662561c5 100644
--- a/core/commands/slash/http.ts
+++ b/core/commands/slash/http.ts
@@ -1,5 +1,6 @@
 import { SlashCommand } from "../../index.js";
 import { removeQuotesAndEscapes } from "../../util/index.js";
+import { streamResponse } from "../../llm/stream.js";
 
 const HttpSlashCommand: SlashCommand = {
   name: "http",
@@ -23,14 +24,8 @@ const HttpSlashCommand: SlashCommand = {
     if (response.body === null) {
       throw new Error("Response body is null");
     }
-    const reader = response.body.getReader();
-    while (true) {
-      const { done, value } = await reader.read();
-      if (done) {
-        break;
-      }
-      const decoded = new TextDecoder("utf-8").decode(value);
-      yield decoded;
+    for await (const chunk of streamResponse(response)) {
+      yield chunk;
     }
   },
 };