'use client' import { useState } from 'react' const API_URL = 'http://127.0.0.1:8080' type Message = { sender: string content: string } async function completion(prompt: string, callback: (res: string) => void) { const result = await fetch(`${API_URL}/completion`, { method: 'POST', body: JSON.stringify({ prompt: prompt, temperature: 0.2, top_k: 40, top_p: 0.9, n_predict: 256, stop: ['\n### Human:'], // stop completion after generating this stream: true, }), }) if (!result.ok || !result.body) { return } let reader = result.body.getReader() while (true) { const { done, value } = await reader.read() if (done) { break } const t = Buffer.from(value).toString('utf8') if (t.startsWith('data: ')) { const message = JSON.parse(t.substring(6)) callback(message.content) if (message.stop) { break } } } return } export default function Home() { const [prompt, setPrompt] = useState('') const [messages, setMessages] = useState([]) return (

LLaMa

Meta Platforms, Inc.

{messages.map((m, i) => (
{m.sender === 'human' ? '👩' : '🤖'}
{m.content} {m.sender === 'bot' && ⬤}
))}
) }