|
5 | 5 | <meta name="color-scheme" content="light dark"> |
6 | 6 | <title>🦙 llama.cpp - chat</title> |
7 | 7 |
|
8 | | - <!-- TODO: embed dependencies into cpp --> |
| 8 | + <!-- Note: dependencies can de updated using ./deps.sh script --> |
9 | 9 | <link href="./deps_daisyui.min.css" rel="stylesheet" type="text/css" /> |
10 | 10 | <script src="./deps_tailwindcss.js"></script> |
| 11 | + <script> |
| 12 | + tailwind.config = {}; |
| 13 | + </script> |
| 14 | + <style type="text/tailwindcss"> |
| 15 | + .markdown { |
| 16 | + h1, h2, h3, h4, h5, h6, ul, ol, li { all: revert; } |
| 17 | + pre { @apply whitespace-pre-wrap; } |
| 18 | + /* TODO: fix table */ |
| 19 | + } |
| 20 | + </style> |
11 | 21 | </head> |
12 | 22 |
|
13 | 23 | <body> |
|
53 | 63 | 'chat-end': msg.role === 'user', |
54 | 64 | }"> |
55 | 65 | <div :class="{ |
56 | | - 'chat-bubble': true, |
| 66 | + 'chat-bubble markdown': true, |
57 | 67 | 'chat-bubble-primary': msg.role === 'user', |
58 | 68 | }"> |
59 | | - <p v-for="line in msg.content.split('\n')">{{ line }}</p> |
| 69 | + <vue-markdown :source="msg.content" /> |
60 | 70 | </div> |
61 | 71 | </div> |
62 | 72 |
|
63 | 73 | <!-- pending assistant message --> |
64 | 74 | <div id="pending-msg" class="chat chat-start"> |
65 | | - <div v-if="pendingMsg" class="chat-bubble"> |
| 75 | + <div v-if="pendingMsg" class="chat-bubble markdown"> |
66 | 76 | <span v-if="!pendingMsg.content" class="loading loading-dots loading-md"></span> |
67 | | - <p v-else v-for="line in pendingMsg.content.split('\n')">{{ line }}</p> |
| 77 | + <vue-markdown v-else :source="pendingMsg.content" /> |
68 | 78 | </div> |
69 | 79 | </div> |
70 | 80 | </div> |
|
84 | 94 | </div> |
85 | 95 | </div> |
86 | 96 |
|
| 97 | + <script src="./deps_markdown-it.js"></script> |
87 | 98 | <script type="module"> |
88 | | - import { createApp } from './deps_vue.esm-browser.js'; |
| 99 | + import { createApp, defineComponent, shallowRef, computed, h } from './deps_vue.esm-browser.js'; |
89 | 100 | import { llama } from './completion.js'; |
90 | 101 |
|
91 | 102 | const BASE_URL = (new URL('.', document.baseURI).href).toString(); |
92 | 103 |
|
| 104 | + // markdown support |
| 105 | + const VueMarkdown = defineComponent( |
| 106 | + (props) => { |
| 107 | + const md = shallowRef(new markdownit(props.options ?? {})); |
| 108 | + for (const plugin of props.plugins ?? []) { |
| 109 | + md.value.use(plugin); |
| 110 | + } |
| 111 | + const content = computed(() => md.value.render(props.source)); |
| 112 | + return () => h("div", { innerHTML: content.value }); |
| 113 | + }, |
| 114 | + { props: ["source", "options", "plugins"] } |
| 115 | + ); |
| 116 | + |
93 | 117 | createApp({ |
| 118 | + components: { |
| 119 | + VueMarkdown, |
| 120 | + }, |
94 | 121 | data() { |
95 | 122 | return { |
96 | 123 | messages: [], |
|
0 commit comments