cerebras_codermigrations1 match
7export const ITERATIONS_TABLE = "cerebras_coder_iterations";
89export async function createTables() {
10await sqlite.execute(`
11CREATE TABLE IF NOT EXISTS ${PROJECTS_TABLE} (
cerebras_coderindex.html1 match
19<meta property="og:site_name" content="Cerebras Coder">
20<meta property="og:url" content="https://cerebrascoder.com"/>
21<meta property="og:description" content="Turn your ideas into fully functional apps in less than a second – powered by Llama3.3-70b on Cerebras's super-fast wafer chips. Code is 100% open-source, hosted on Val Town."">
22<meta property="og:type" content="website">
23<meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">
cerebras_coderindex2 matches
3import { createProject, getCode, getNextVersionNumber, insertVersion } from "./database/queries";
45async function servePublicFile(path: string): Promise<Response> {
6const url = new URL("./public/" + path, import.meta.url);
7const text = await (await fetch(url, {
20await createTables();
2122export default async function cerebras_coder(req: Request): Promise<Response> {
23if (req.method === "POST") {
24let { prompt, currentCode, versionHistory, projectId } = await req.json();
cerebras_coderindex7 matches
23);
2425function Hero({
26prompt,
27setPrompt,
4445<p className="text-[#bababa] text-center max-w-[25ch] mx-auto my-4 font-dm-sans">
46Turn your ideas into fully functional apps in{" "}
47<span className="relative w-fit text-fuchsia-400 z-10 italic font-semibold rounded-full">
48less than a second
115}
116117function App() {
118const previewRef = React.useRef<HTMLDivElement>(null);
119const [prompt, setPrompt] = useState("");
169});
170171function handleStarterPromptClick(promptItem: typeof prompts[number]) {
172setLoading(true);
173setTimeout(() => handleSubmit(promptItem.prompt), 0);
174}
175176async function handleSubmit(e: React.FormEvent | string) {
177if (typeof e !== "string") {
178e.preventDefault();
225}
226227function handleVersionChange(direction: "back" | "forward") {
228const { currentVersionIndex, versions } = versionHistory;
229if (direction === "back" && currentVersionIndex > 0) {
973);
974975function client() {
976const path = window.location.pathname;
977const root = createRoot(document.getElementById("root")!);
cerebras_codergenerate-code2 matches
2import STARTER_PROMPTS from "../public/starter-prompts.js";
34function extractCodeFromFence(text: string): string {
5const htmlMatch = text.match(/```html\n([\s\S]*?)\n```/);
6return htmlMatch ? htmlMatch[1].trim() : text;
7}
89export async function generateCode(prompt: string, currentCode: string) {
10const starterPrompt = STARTER_PROMPTS.find(p => p.prompt === prompt);
11if (starterPrompt) {
getProjectsAsZipsindex.ts4 matches
25});
2627async function getAllProjects() {
28let offset = 0;
29const limit = 100;
88});
8990function parseValTownProjectURL(url: string) {
91// Use the URL constructor to parse the URL
92const { pathname } = new URL(url);
102}
103104async function getFilesWithContent(files: any[], projectId) {
105const nonDirectoryFiles = files.filter(file => file.type !== "directory");
106137}
138139async function createZipFromEndpoints(
140files: any[],
141zipFileName: string,
replicate_starterApp.tsx1 match
3import React from "https://esm.sh/react@18.2.0";
45function ImageGenerator() {
6const [prompt, setPrompt] = React.useState("");
7const [images, setImages] = React.useState<any>([]);
replicate_starterApp.tsx1 match
3import React from "https://esm.sh/react@18.2.0";
45function ImageGenerator() {
6const [prompt, setPrompt] = React.useState("");
7const [images, setImages] = React.useState<any>([]);
test_projectmain.js19 matches
7* Remove common variations of "+ C" at the end of an indefinite integral.
8*/
9function stripPlusC(str) {
10return str.replace(/\+\s*c\s*$/i, "").trim();
11}
15* Remove or replace common LaTeX constructs.
16*/
17function latexToExpression(latex) {
18// Remove display math delimiters: $$...$$ or $...$
19let expr = latex.replace(/\${1,2}/g, "");
22expr = expr.replace(/\\frac\s*\{([^}]+)\}\s*\{([^}]+)\}/g, "($1)/($2)");
2324// Some common function replacements for Algebrite
25expr = expr.replace(/\\sin/g, "sin");
26expr = expr.replace(/\\cos/g, "cos");
46* Return the simplified string or null on error.
47*/
48function parseAndSimplify(expr) {
49try {
50// If it's an empty string, treat that as invalid
59* Check if two expressions (already simplified) differ by at most a constant.
60*/
61function differByConstant(simpl1, simpl2) {
62try {
63const diff = Algebrite.simplify(`(${simpl1}) - (${simpl2})`).toString();
74* Symbolic check: compare simplified forms, then see if they differ by a constant.
75*/
76function symbolicCheck(expr1, expr2) {
77const s1 = parseAndSimplify(expr1);
78const s2 = parseAndSimplify(expr2);
85* Evaluate an expression numerically at x, returning a float or null if invalid.
86*/
87function safeEval(expr, x) {
88try {
89const val = parseFloat(Algebrite.eval(expr, { x }).toString());
100* If the difference changes by more than a small tolerance, we reject it.
101*/
102function numericCheck(expr1, expr2, samples = [-2, 0, 2]) {
103const diffs = [];
104125* Loose equivalence: first do a symbolic check, if that fails, do numeric check.
126*/
127function expressionsAreLooselyEquivalent(expr1, expr2) {
128// 1) Symbolic check
129if (symbolicCheck(expr1, expr2)) {
137* GPT-4 call to generate a new math problem.
138*/
139async function handleProblemGeneration() {
140const openai = new OpenAI();
141const completion = await openai.chat.completions.create({
153},
154],
155functions: [
156{
157name: "generate_math_problem",
177},
178],
179function_call: { name: "generate_math_problem" },
180});
181182const functionCall = completion.choices[0].message.function_call;
183if (!functionCall || functionCall.name !== "generate_math_problem") {
184return new Response("Failed to generate problem", { status: 500 });
185}
187let problem;
188try {
189problem = JSON.parse(functionCall.arguments);
190} catch (error) {
191console.error("Failed to parse function call arguments:", error);
192console.log("Raw arguments:", functionCall.arguments);
193return new Response("Failed to generate problem", { status: 500 });
194}
213* - Return result
214*/
215async function handleAnswerCheck(request) {
216const { answer, problemId } = await request.json();
217const problem = await blob.getJSON(`problem_${problemId}`);
257* Main request handler.
258*/
259export default async function(req: Request): Promise<Response> {
260const url = new URL(req.url);
261
2import type { ReactNode } from "npm:react@18.2.0";
34export function Layout({ children }: { children: ReactNode }) {
5return (
6<html lang="en">