Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render markdown from chatbot's response #11

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"@sveltejs/adapter-node": "^2.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@types/markdown-it": "^13.0.7",
"@types/sanitize-html": "^2.9.5",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/parser": "^6.15.0",
"autoprefixer": "^10.4.16",
Expand All @@ -40,6 +42,8 @@
"@steeze-ui/icons": "^2.1.0",
"@steeze-ui/svelte-icon": "^1.5.0",
"langchain": "^0.0.198",
"markdown-it": "^14.0.0",
"sanitize-html": "^2.11.0",
"tiktoken": "^1.0.11"
}
}
124 changes: 119 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import { PaperAirplane, Trash, Stop } from '@steeze-ui/heroicons';

import { writable } from 'svelte/store';
import markdownit from 'markdown-it';
import { setContext } from 'svelte';
import * as sanitizeHtml from 'sanitize-html';
charliehuang09 marked this conversation as resolved.
Show resolved Hide resolved

let history: ChatHistory[] = [];

Expand All @@ -33,7 +35,7 @@
...history,
{
type: ChatHistoryType.Human,
content: userInput
content: sanitizeHtml(userInput)
charliehuang09 marked this conversation as resolved.
Show resolved Hide resolved
}
];

Expand Down Expand Up @@ -71,6 +73,9 @@
break;
}
}
const md = markdownit('commonmark');
history[history.length - 1].content = md.render(history[history.length - 1].content);
charliehuang09 marked this conversation as resolved.
Show resolved Hide resolved
history[history.length - 1].content = sanitizeHtml(history[history.length - 1].content)
charliehuang09 marked this conversation as resolved.
Show resolved Hide resolved

completionState.set(CompletionState.Completed);
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/Message.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<p>🤖</p>
{/if}

<p>{content}</p>
<p>{@html content}</p>
</div>
{:else}
<div class="message">
Expand Down
Loading