ui: adding zeromd for markdown handling
This commit is contained in:
parent
ea8d513e6e
commit
622975b742
3 changed files with 63 additions and 54 deletions
|
@ -7,9 +7,12 @@
|
||||||
<title>llama.cpp - chat</title>
|
<title>llama.cpp - chat</title>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: system-ui;
|
font-family: system-ui;
|
||||||
font-size: 90%;
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +131,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
code {
|
code {
|
||||||
font-family: monospace;
|
|
||||||
padding: 0.1em 0.3em;
|
padding: 0.1em 0.3em;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
}
|
}
|
||||||
|
@ -188,7 +190,7 @@
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
button{
|
button {
|
||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,15 +223,13 @@
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.response p {
|
.response>p {
|
||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
margin-bottom: 0.5em;
|
||||||
border-radius: 0.5em;
|
border-radius: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.response p:nth-child(even) {
|
|
||||||
background-color: rgba(242, 242, 242, 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
header,
|
header,
|
||||||
footer {
|
footer {
|
||||||
|
@ -256,6 +256,7 @@
|
||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
textarea[name=prompt] {
|
textarea[name=prompt] {
|
||||||
height: 20em;
|
height: 20em;
|
||||||
margin: 1em 0;
|
margin: 1em 0;
|
||||||
|
@ -296,6 +297,27 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<script>
|
||||||
|
window.ZeroMdConfig = {
|
||||||
|
markedUrl: 'https://cdn.jsdelivr.net/gh/markedjs/marked@4/marked.min.js',
|
||||||
|
prismUrl: [
|
||||||
|
['https://cdn.jsdelivr.net/npm/prismjs@1.29.0/prism.min.js', 'data-manual'],
|
||||||
|
'https://cdn.jsdelivr.net/npm/prismjs@1.29.0/plugins/autoloader/prism-autoloader.min.js',
|
||||||
|
],
|
||||||
|
cssUrls: window.matchMedia("(prefers-color-scheme: light)").matches
|
||||||
|
? [
|
||||||
|
'https://cdn.jsdelivr.net/npm/github-markdown-css@5.5.0/github-markdown.min.css',
|
||||||
|
'https://cdn.jsdelivr.net/gh/katorlys/prism-theme-github/themes/prism-theme-github-light.css'
|
||||||
|
]
|
||||||
|
: [
|
||||||
|
'https://cdn.jsdelivr.net/npm/github-markdown-css@5.5.0/github-markdown.min.css',
|
||||||
|
'https://cdn.jsdelivr.net/gh/katorlys/prism-theme-github/themes/prism-theme-github-dark.css'
|
||||||
|
],
|
||||||
|
// Host styles that apply to each instance
|
||||||
|
hostCss: ':host{display:block;position:relative;contain:content;}:host([hidden]){display:none;}'
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<script type="module" src="https://cdn.jsdelivr.net/npm/zero-md@2.5.3/dist/zero-md.min.js"></script>
|
||||||
|
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import {
|
import {
|
||||||
|
@ -647,19 +669,19 @@
|
||||||
return html`
|
return html`
|
||||||
<form onsubmit=${submit}>
|
<form onsubmit=${submit}>
|
||||||
<div>
|
<div>
|
||||||
<textarea
|
<textarea
|
||||||
id="chat_input"
|
id="chat_input"
|
||||||
className=${generating.value ? "loading" : null}
|
className=${generating.value ? "loading" : null}
|
||||||
oninput=${(e) => {
|
oninput=${(e) => {
|
||||||
message.value = e.target.value;
|
message.value = e.target.value;
|
||||||
chatMessage.value = "";
|
chatMessage.value = "";
|
||||||
}}
|
}}
|
||||||
onkeypress=${enterSubmits}
|
onkeypress=${enterSubmits}
|
||||||
placeholder="Say something..."
|
placeholder="Say something..."
|
||||||
rows=2
|
rows=2
|
||||||
type="text"
|
type="text"
|
||||||
value="${message}"
|
value="${message}"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="right">
|
<div class="right">
|
||||||
<button type="submit" disabled=${generating.value}>Send</button>
|
<button type="submit" disabled=${generating.value}>Send</button>
|
||||||
|
@ -799,14 +821,13 @@
|
||||||
userTemplateAutosave()
|
userTemplateAutosave()
|
||||||
}, [session.value])
|
}, [session.value])
|
||||||
|
|
||||||
useEffect(()=> {
|
useEffect(() => {
|
||||||
fetch('/prompts.json')
|
fetch('/prompts.json')
|
||||||
.then(res=> res.json())
|
.then(res => res.json())
|
||||||
.then(res=> {
|
.then(res => {
|
||||||
prompts.value = res;
|
prompts.value = res;
|
||||||
console.log('updated prompts');
|
})
|
||||||
})
|
}, [])
|
||||||
},[])
|
|
||||||
|
|
||||||
|
|
||||||
const GrammarControl = () => (
|
const GrammarControl = () => (
|
||||||
|
@ -824,20 +845,20 @@
|
||||||
const PromptControlFieldSet = () => {
|
const PromptControlFieldSet = () => {
|
||||||
const regex = /(.*\.) (My(.*))/i;
|
const regex = /(.*\.) (My(.*))/i;
|
||||||
const handlePromptChange = (event) => {
|
const handlePromptChange = (event) => {
|
||||||
const selectedValue = `${event.target.value} \n\n `;
|
const selectedValue = `${event.target.value} \n\n `;
|
||||||
const match = selectedValue.match(regex);
|
const match = selectedValue.match(regex);
|
||||||
if(session.value.type === 'chat' && match){
|
if (session.value.type === 'chat' && match) {
|
||||||
const _prompt = match[1];
|
const _prompt = match[1];
|
||||||
const _chatMessage = match[2];
|
const _chatMessage = match[2];
|
||||||
|
|
||||||
document.getElementById('_prompt').value = _prompt;
|
document.getElementById('_prompt').value = _prompt;
|
||||||
session.value.prompt = selectedValue;
|
session.value.prompt = selectedValue;
|
||||||
|
|
||||||
document.getElementById('chat_input').value = _chatMessage;
|
document.getElementById('chat_input').value = _chatMessage;
|
||||||
chatMessage.value = _chatMessage;
|
chatMessage.value = _chatMessage;
|
||||||
} else{
|
} else {
|
||||||
document.getElementById('_prompt').value = selectedValue;
|
document.getElementById('_prompt').value = selectedValue;
|
||||||
session.value.prompt = selectedValue;
|
session.value.prompt = selectedValue;
|
||||||
chatMessage.value = "";
|
chatMessage.value = "";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -848,11 +869,11 @@
|
||||||
<label htmlFor="prompt">Prompt</label>
|
<label htmlFor="prompt">Prompt</label>
|
||||||
<select id="promptlist" onchange=${handlePromptChange}>
|
<select id="promptlist" onchange=${handlePromptChange}>
|
||||||
<option>Select a Custom prompt</option>
|
<option>Select a Custom prompt</option>
|
||||||
${prompts.value.map(prompt => {
|
${prompts.value.sort((a, b) => a.act.localeCompare(b.act)).map(prompt => {
|
||||||
return html`
|
return html`
|
||||||
<option value="${prompt.prompt}">${prompt.act}</option>
|
<option value="${prompt.prompt}">${prompt.act}</option>
|
||||||
`;
|
`;
|
||||||
})}
|
})}
|
||||||
</select>
|
</select>
|
||||||
<textarea id="_prompt" type="text" name="prompt" value="${session.value.prompt}" oninput=${updateSession} onchange=${updateSession}/>
|
<textarea id="_prompt" type="text" name="prompt" value="${session.value.prompt}" oninput=${updateSession} onchange=${updateSession}/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1024,19 +1045,7 @@
|
||||||
|
|
||||||
// poor mans markdown replacement
|
// poor mans markdown replacement
|
||||||
const Markdownish = (params) => {
|
const Markdownish = (params) => {
|
||||||
const md = params.text
|
return html`<zero-md> <script type="text/markdown" dangerouslySetInnerHTML=${{ __html: params.text }} /></zero-md>`;
|
||||||
.replace(/&/g, '&')
|
|
||||||
.replace(/</g, '<')
|
|
||||||
.replace(/>/g, '>')
|
|
||||||
.replace(/^#{1,6} (.*)$/gim, '<h3>$1</h3>')
|
|
||||||
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
|
|
||||||
.replace(/__(.*?)__/g, '<strong>$1</strong>')
|
|
||||||
.replace(/\*(.*?)\*/g, '<em>$1</em>')
|
|
||||||
.replace(/_(.*?)_/g, '<em>$1</em>')
|
|
||||||
.replace(/```.*?\n([\s\S]*?)```/g, '<pre><code>$1</code></pre>')
|
|
||||||
.replace(/`(.*?)`/g, '<code>$1</code>')
|
|
||||||
.replace(/\n/gim, '<br />');
|
|
||||||
return html`<span dangerouslySetInnerHTML=${{ __html: md }} />`;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const ModelGenerationInfo = (params) => {
|
const ModelGenerationInfo = (params) => {
|
||||||
|
@ -1045,7 +1054,7 @@
|
||||||
}
|
}
|
||||||
return html`
|
return html`
|
||||||
<span>
|
<span>
|
||||||
${llamaStats.value.predicted_per_token_ms.toFixed()}ms per token, ${llamaStats.value.predicted_per_second.toFixed(2)} tokens per second |
|
${llamaStats.value.predicted_per_token_ms.toFixed()}ms per token, ${llamaStats.value.predicted_per_second.toFixed(2)} tokens per second |
|
||||||
</span>
|
</span>
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
@ -1196,4 +1205,4 @@
|
||||||
<div id="portal"></div>
|
<div id="portal"></div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -663,4 +663,4 @@
|
||||||
"act": "Data Scientist",
|
"act": "Data Scientist",
|
||||||
"prompt": "I want you to act as a data scientist. Imagine you're working on a challenging project for a cutting-edge tech company. You've been tasked with extracting valuable insights from a large dataset related to user behavior on a new app. Your goal is to provide actionable recommendations to improve user engagement and retention."
|
"prompt": "I want you to act as a data scientist. Imagine you're working on a challenging project for a cutting-edge tech company. You've been tasked with extracting valuable insights from a large dataset related to user behavior on a new app. Your goal is to provide actionable recommendations to improve user engagement and retention."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
# pip install csvkit
|
# pip install csvkit
|
||||||
curl -s https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv | csvjson -i 2 > public/prompts.json
|
curl -s https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv | csvjson -i 2 > public/prompts.json
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue