feat: implement Node.js backend server and frontend text chat interface

This commit is contained in:
techjarves committed 2026-06-15 09:14:43 +05:30
1 parent ed154d66d4
commit dbd222dc9a
3 files changed
+27 -19

No files matched your search

+4 -4
View File
@@ -909,17 +909,17 @@ export function MarkdownRenderer({ content }) {
return <h2 key={blockIdx} style={{ fontSize: "1.35rem", fontWeight: 700, margin: "18px 0 8px 0", color: "var(--md-sys-color-primary)" }}>{parseInlineMarkdown(block.content)}</h2>;
case "ul":
return (
<ul key={blockIdx} style={{ margin: "4px 0 4px 20px", padding: 0, listStyleType: "disc", display: "flex", flexDirection: "column", gap: "4px" }}>
<ul key={blockIdx} style={{ margin: "6px 0 6px 24px", padding: 0, listStyleType: "disc", display: "block" }}>
{block.items.map((item, itemIdx) => (
<li key={itemIdx} style={{ fontSize: "0.9rem", lineHeight: 1.5 }}>{parseInlineMarkdown(item)}</li>
<li key={itemIdx} style={{ fontSize: "0.9rem", lineHeight: 1.5, marginBottom: "4px", display: "list-item" }}>{parseInlineMarkdown(item)}</li>
))}
</ul>
);
case "ol":
return (
<ol key={blockIdx} style={{ margin: "4px 0 4px 20px", padding: 0, listStyleType: "decimal", display: "flex", flexDirection: "column", gap: "4px" }}>
<ol key={blockIdx} style={{ margin: "6px 0 6px 24px", padding: 0, listStyleType: "decimal", display: "block" }}>
{block.items.map((item, itemIdx) => (
<li key={itemIdx} style={{ fontSize: "0.9rem", lineHeight: 1.5 }}>{parseInlineMarkdown(item)}</li>
<li key={itemIdx} style={{ fontSize: "0.9rem", lineHeight: 1.5, marginBottom: "4px", display: "list-item" }}>{parseInlineMarkdown(item)}</li>
))}
</ol>
);
+20 -15
View File
@@ -405,23 +405,28 @@ export async function streamChatWithLlm(messages, options = {}, onToken = () =>
let timings = null;
const consumeEvent = (eventText) => {
const data = eventText
.split(/\r?\n/)
.filter((line) => line.startsWith("data:"))
.map((line) => line.slice(5).trimStart())
.join("\n")
.trim();
if (!data || data === "[DONE]") return data === "[DONE]";
try {
const data = eventText
.split(/\r?\n/)
.filter((line) => line.startsWith("data:"))
.map((line) => line.slice(5).trimStart())
.join("\n")
.trim();
if (!data || data === "[DONE]") return data === "[DONE]";
const parsed = JSON.parse(data);
const token = parsed.choices?.[0]?.delta?.content || "";
if (token) {
content += token;
onToken(token, content);
const parsed = JSON.parse(data);
const token = parsed.choices?.[0]?.delta?.content || "";
if (token) {
content += token;
onToken(token, content);
}
if (parsed.usage) usage = parsed.usage;
if (parsed.timings) timings = parsed.timings;
return false;
} catch (err) {
console.warn("Failed to parse EventStream JSON:", eventText, err);
return false;
}
if (parsed.usage) usage = parsed.usage;
if (parsed.timings) timings = parsed.timings;
return false;
};
let finished = false;