mirror of
				https://github.com/ggml-org/llama.cpp.git
				synced 2025-11-03 09:22:01 +00:00 
			
		
		
		
	consistent semicolons
This commit is contained in:
		@@ -108,9 +108,9 @@
 | 
			
		||||
  <script type="module">
 | 
			
		||||
    import {
 | 
			
		||||
      html, h, signal, effect, computed, render, useSignal, useEffect, useRef
 | 
			
		||||
    } from '/index.js';
 | 
			
		||||
    } from '/index.js'
 | 
			
		||||
 | 
			
		||||
    import { llama } from '/completion.js';
 | 
			
		||||
    import { llama } from '/completion.js'
 | 
			
		||||
 | 
			
		||||
    const session = signal({
 | 
			
		||||
      prompt: "This is a conversation between user and llama, a friendly chatbot. respond in simple markdown.",
 | 
			
		||||
@@ -140,35 +140,35 @@
 | 
			
		||||
    const transcriptUpdate = (transcript) => {
 | 
			
		||||
      session.value = {
 | 
			
		||||
        ...session.value,
 | 
			
		||||
        transcript
 | 
			
		||||
        transcript,
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // simple template replace
 | 
			
		||||
    const template = (str, extraSettings) => {
 | 
			
		||||
      let settings = session.value;
 | 
			
		||||
      let settings = session.value
 | 
			
		||||
      if (extraSettings) {
 | 
			
		||||
        settings = { ...settings, ...extraSettings };
 | 
			
		||||
        settings = { ...settings, ...extraSettings }
 | 
			
		||||
      }
 | 
			
		||||
      return String(str).replaceAll(/\{\{(.*?)\}\}/g, (_, key) => template(settings[key]));
 | 
			
		||||
      return String(str).replaceAll(/\{\{(.*?)\}\}/g, (_, key) => template(settings[key]))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // send message to server
 | 
			
		||||
    const chat = async (msg) => {
 | 
			
		||||
      if (controller.value) {
 | 
			
		||||
        console.log('already running...');
 | 
			
		||||
        return;
 | 
			
		||||
        console.log('already running...')
 | 
			
		||||
        return
 | 
			
		||||
      }
 | 
			
		||||
      controller.value = new AbortController();
 | 
			
		||||
      controller.value = new AbortController()
 | 
			
		||||
 | 
			
		||||
      transcriptUpdate([...session.value.transcript, ["{{user}}", msg]])
 | 
			
		||||
 | 
			
		||||
      const prompt = template(session.value.template, {
 | 
			
		||||
        message: msg,
 | 
			
		||||
        history: session.value.transcript.flatMap(([name, message]) => template(session.value.historyTemplate, {name, message})).join("\n"),
 | 
			
		||||
      });
 | 
			
		||||
      })
 | 
			
		||||
 | 
			
		||||
      let currentMessage = '';
 | 
			
		||||
      let currentMessage = ''
 | 
			
		||||
      const history = session.value.transcript
 | 
			
		||||
 | 
			
		||||
      const llamaParams = {
 | 
			
		||||
@@ -177,8 +177,8 @@
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      for await (const chunk of llama(prompt, llamaParams, { controller: controller.value })) {
 | 
			
		||||
        const data = chunk.data;
 | 
			
		||||
        currentMessage += data.content;
 | 
			
		||||
        const data = chunk.data
 | 
			
		||||
        currentMessage += data.content
 | 
			
		||||
 | 
			
		||||
        // remove leading whitespace
 | 
			
		||||
        currentMessage = currentMessage.replace(/^\s+/, "")
 | 
			
		||||
@@ -186,42 +186,42 @@
 | 
			
		||||
        transcriptUpdate([...history, ["{{char}}", currentMessage]])
 | 
			
		||||
 | 
			
		||||
        if (data.stop) {
 | 
			
		||||
          console.log("Completion finished: '", currentMessage, "', summary: ", data);
 | 
			
		||||
          console.log("Completion finished: '", currentMessage, "', summary: ", data)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (data.timings) {
 | 
			
		||||
          llamaStats.value = data.timings;
 | 
			
		||||
          llamaStats.value = data.timings
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      controller.value = null;
 | 
			
		||||
      controller.value = null
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function MessageInput() {
 | 
			
		||||
      const message = useSignal("")
 | 
			
		||||
 | 
			
		||||
      const stop = (e) => {
 | 
			
		||||
        e.preventDefault();
 | 
			
		||||
        e.preventDefault()
 | 
			
		||||
        if (controller.value) {
 | 
			
		||||
          controller.value.abort();
 | 
			
		||||
          controller.value = null;
 | 
			
		||||
          controller.value.abort()
 | 
			
		||||
          controller.value = null
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      const reset = (e) => {
 | 
			
		||||
        stop(e);
 | 
			
		||||
        transcriptUpdate([]);
 | 
			
		||||
        stop(e)
 | 
			
		||||
        transcriptUpdate([])
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      const submit = (e) => {
 | 
			
		||||
        stop(e);
 | 
			
		||||
        chat(message.value);
 | 
			
		||||
        message.value = "";
 | 
			
		||||
        stop(e)
 | 
			
		||||
        chat(message.value)
 | 
			
		||||
        message.value = ""
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      const enterSubmits = (event) => {
 | 
			
		||||
        if (event.which === 13 && !event.shiftKey) {
 | 
			
		||||
          submit(event);
 | 
			
		||||
          submit(event)
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
@@ -240,7 +240,7 @@
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const ChatLog = (props) => {
 | 
			
		||||
      const messages = session.value.transcript;
 | 
			
		||||
      const messages = session.value.transcript
 | 
			
		||||
      const container = useRef(null)
 | 
			
		||||
 | 
			
		||||
      useEffect(() => {
 | 
			
		||||
@@ -252,13 +252,13 @@
 | 
			
		||||
 | 
			
		||||
      const chatLine = ([user, msg]) => {
 | 
			
		||||
        return html`<p key=${msg}><strong>${template(user)}:</strong> <${Markdownish} text=${template(msg)} /></p>`
 | 
			
		||||
      };
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      return html`
 | 
			
		||||
        <section id="chat" ref=${container}>
 | 
			
		||||
          ${messages.flatMap(chatLine)}
 | 
			
		||||
        </section>`;
 | 
			
		||||
    };
 | 
			
		||||
        </section>`
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const ConfigForm = (props) => {
 | 
			
		||||
      const updateSession = (el) => session.value = { ...session.value, [el.target.name]: el.target.value }
 | 
			
		||||
@@ -331,9 +331,9 @@
 | 
			
		||||
        .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 }} />`;
 | 
			
		||||
    };
 | 
			
		||||
        .replace(/\n/gim, '<br />')
 | 
			
		||||
      return html`<span dangerouslySetInnerHTML=${{ __html: md }} />`
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const ModelGenerationInfo = (params) => {
 | 
			
		||||
      if (!llamaStats.value) {
 | 
			
		||||
@@ -367,10 +367,10 @@
 | 
			
		||||
            <p>Powered by <a href="https://github.com/ggerganov/llama.cpp">llama.cpp</a> and <a href="https://ggml.ai">ggml.ai</a>.</p>
 | 
			
		||||
          </footer>
 | 
			
		||||
        </div>
 | 
			
		||||
      `;
 | 
			
		||||
      `
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    render(h(App), document.body);
 | 
			
		||||
    render(h(App), document.body)
 | 
			
		||||
  </script>
 | 
			
		||||
</head>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user