Code
HTTP
/** @jsxImportSource https://esm.sh/react */
import Cerebras from "https://esm.sh/@cerebras/cerebras_cloud_sdk";
import React, { useState } from "https://esm.sh/react";
import { createRoot } from "https://esm.sh/react-dom/client";
import { Prism as SyntaxHighlighter } from "https://esm.sh/react-syntax-highlighter";
import { tomorrow } from "https://esm.sh/react-syntax-highlighter/dist/esm/styles/prism";
function App() {
const [prompt, setPrompt] = useState("hello llamapalooza");
const [code, setCode] = useState("");
const [loading, setLoading] = useState(false);
const [performance, setPerformance] = useState<
{
tokensPerSecond: number;
totalTokens: number;
time: number;
} | null
>(null);
async function handleSubmit(e: React.FormEvent) {
e.preventDefault();
setLoading(true);
try {
const response = await fetch("/", {
method: "POST",
body: JSON.stringify({ prompt, currentCode: code }),
headers: { "Content-Type": "application/json" },
});
const result = await response.json();
setCode(result.code);
setPerformance(result.performance);
} catch (error) {
console.error("Error:", error);
} finally {
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
kate-cerebras_coder.web.val.run
Updated: October 31, 2024