cerebrasTemplatemain.tsx5 matches
88// Keep these comments so we remember not to change this
89const client = new OpenAI({
90apiKey: Deno.env.get("CEREBRAS_API_KEY"),
91baseURL: "https://api.cerebras.ai/v1",
92});
93101return Response.json({ message: generatedMessage });
102} catch (error) {
103console.error("Error calling Cerebras API:", error);
104105if (error.status === 429) {
106return Response.json({ error: "Cerebras API rate limit reached. Please try again later." }, { status: 429 });
107} else {
108return Response.json({ error: `API Error: ${error.message}` }, { status: 500 });
109}
110}
cerebrasTemplateREADME.md6 matches
22231. Sign up for [Cerebras](https://cloud.cerebras.ai/)
242. Get a Cerebras API Key
253. Save it in a [Val Town environment variable](https://www.val.town/settings/environment-variables) called `CEREBRAS_API_KEY`
2627Once Cerebras is set up in your Val Town account, there are two ways to get started:
37const { OpenAI } = await import("https://esm.sh/openai");
38const client = new OpenAI({
39apiKey: Deno.env.get("CEREBRAS_API_KEY"),
40baseURL: "https://api.cerebras.ai/v1"
41});
42const response = await client.chat.completions.create({
54## Sample apps
5556* **[Cerebras Searcher](https://www.val.town/v/stevekrouse/cerebras_searcher)** - a Perplexity clone that uses the SerpAPI to do RAG
57and summaries with Cerebras (*requires a SerpAPI key*)
58* **[Cerebras Coder](https://www.val.town/v/stevekrouse/cerebras_coder)** - an app that
59generates websites in a second with Cerebras
cerebrasTemplatemain.tsx5 matches
88// Keep these comments so we remember not to change this
89const client = new OpenAI({
90apiKey: Deno.env.get("CEREBRAS_API_KEY"),
91baseURL: "https://api.cerebras.ai/v1",
92});
93101return Response.json({ message: generatedMessage });
102} catch (error) {
103console.error("Error calling Cerebras API:", error);
104105if (error.status === 429) {
106return Response.json({ error: "Cerebras API rate limit reached. Please try again later." }, { status: 429 });
107} else {
108return Response.json({ error: `API Error: ${error.message}` }, { status: 500 });
109}
110}
characterGuessermain.tsx1 match
233const conversationParam = url.searchParams.get("conversation");
234const { Cerebras } = await import("https://esm.sh/@cerebras/cerebras_cloud_sdk");
235const client = new Cerebras({ apiKey: Deno.env.get("CEREBRAS_API_KEY") });
236237let conversation = conversationParam ? JSON.parse(decodeURIComponent(conversationParam)) : [];
flowingAmethystHippopotamusmain.tsx24 matches
10const FRAMEWORKS = {
11"TypeScript": ["Express", "NestJS", "Fastify", "Koa"],
12"Python": ["Flask", "FastAPI", "Django", "FastAPI"],
13"JavaScript": ["Express", "Koa", "Fastify", "NestJS"],
14"Go": ["Gin", "Echo", "Fiber", "Gorilla Mux"],
56}
5758function APIGenerator() {
59const [apiDescription, setApiDescription] = useState("");
60const [language, setLanguage] = useState("TypeScript");
61const [framework, setFramework] = useState("Express");
70const handleGenerate = useCallback(async () => {
71// Validate input
72if (!apiDescription.trim()) {
73setError("Please provide an API description");
74return;
75}
80const openai = new OpenAI();
8182// Generate API Code
83const codeCompletion = await openai.chat.completions.create({
84model: "gpt-4o-mini",
86{
87role: "system",
88content: `You are an expert API developer. Generate a complete, production-ready API implementation.`,
89},
90{
91role: "user",
92content:
93`Generate an API in ${language} using ${framework} framework with the following description: ${apiDescription}.
94Include:
951. Complete API implementation
962. Proper error handling
973. Basic input validation
114role: "user",
115content:
116`Write a complete test suite for the API in ${language} testing all endpoints and scenarios for the following API description: ${apiDescription}.
117Ensure:
1181. High test coverage
130{
131role: "system",
132content: `You are an expert technical writer specializing in API documentation.`,
133},
134{
135role: "user",
136content: `Create comprehensive API documentation for the following API description in ${language}.
137Include:
1381. Overview
154} catch (error) {
155console.error("Generation error:", error);
156setError(`Failed to generate API: ${error.message || "Unknown error"}`);
157} finally {
158setLoading(false);
159}
160}, [apiDescription, language, framework]);
161162return (
163<div className="container mx-auto p-6 max-w-4xl">
164<h1 className="text-3xl font-bold mb-6 text-center">🚀 API Code Generator</h1>
165166<div className="bg-gray-800 p-6 rounded-lg shadow-lg">
171)}
172<div className="mb-4">
173<label className="block text-sm font-bold mb-2">API Description</label>
174<textarea
175value={apiDescription}
176onChange={(e) => setApiDescription(e.target.value)}
177placeholder="Describe your API (e.g., 'A todo list management API with CRUD operations')"
178className="w-full p-2 bg-gray-700 text-white rounded"
179rows={4}
210<button
211onClick={handleGenerate}
212disabled={!apiDescription || loading}
213className={`w-full p-3 rounded ${
214!apiDescription || loading
215? "bg-gray-500 cursor-not-allowed"
216: "bg-blue-600 hover:bg-blue-700 text-white"
217}`}
218>
219{loading ? "Generating..." : "Generate API"}
220</button>
221</div>
254return (
255<div className="min-h-screen bg-gray-900 text-white">
256<APIGenerator />
257</div>
258);
275<meta charset="UTF-8">
276<meta name="viewport" content="width=device-width, initial-scale=1.0">
277<title>API Code Generator</title>
278<script src="https://cdn.tailwindcss.com"></script>
279<script src="https://esm.town/v/std/catch"></script>
flowingAmethystHippopotamusREADME.md2 matches
671. Sign up for [Cerebras](https://cloud.cerebras.ai/)
82. Get a Cerebras API Key
93. Save it in a [Val Town environment variable](https://www.val.town/settings/environment-variables) called `CEREBRAS_API_KEY`
prosperousYellowMulemain.tsx20 matches
38}
3940function APIGeneratorApp() {
41const [prompt, setPrompt] = useState("");
42const [method, setMethod] = useState("GET");
5758try {
59const response = await fetch("/generate-api", {
60method: "POST",
61headers: { "Content-Type": "application/json" },
72setGeneratedCode(data.code);
73} catch (error) {
74console.error("API Generation Error:", error);
75setGeneratedCode(`Error: ${error.message}`);
76} finally {
8081return (
82<div className="api-generator-container">
83<h1>🚀 API Code Generator</h1>
84
85<div className="input-section">
86<textarea
87placeholder="Describe your API endpoint (e.g., 'Create a user registration endpoint')"
88value={prompt}
89onChange={(e) => setPrompt(e.target.value)}
113onChange={(e) => setFramework(e.target.value)}
114>
115{['Express.js', 'Next.js', 'FastAPI', 'Gin', 'Rocket'].map(f => (
116<option key={f} value={f}>{f}</option>
117))}
164return (
165<ErrorBoundary>
166<APIGeneratorApp />
167</ErrorBoundary>
168);
189190export default async function server(request: Request): Promise<Response> {
191if (request.method === "POST" && new URL(request.url).pathname === "/generate-api") {
192const { OpenAI } = await import("https://esm.sh/openai");
193
201} = await request.json();
202
203// Validate API key is set
204const apiKey = Deno.env.get("CEREBRAS_API_KEY");
205if (!apiKey) {
206return new Response(JSON.stringify({
207code: "// Error: Cerebras API key not configured"
208}), {
209status: 500,
213214const client = new OpenAI({
215apiKey: apiKey,
216baseURL: "https://api.cerebras.ai/v1"
217});
218219const cerebrasPrompt = `Generate a ${generationType} for a ${method} API endpoint in ${language} using ${framework}.
220221Endpoint Description: ${prompt}
224- Use best practices for ${framework}
225- ${generationType === 'code' ? 'Provide a concise, production-ready implementation' : ''}
226${generationType === 'documentation' ? '- Create comprehensive API documentation' : ''}
227${generationType === 'tests' ? '- Write comprehensive unit and integration tests' : ''}
228- Include error handling
243});
244} catch (error) {
245console.error("Cerebras API Error:", error);
246return new Response(JSON.stringify({
247code: `// Error generating ${generationType}: ${error.message}`
256<html>
257<head>
258<title>🚀 Cerebras API Generator</title>
259<meta name="viewport" content="width=device-width, initial-scale=1">
260<script src="https://esm.town/v/std/catch"></script>
296}
297298.api-generator-container {
299width: 100%;
300max-width: 800px;
prosperousYellowMuleREADME.md6 matches
22231. Sign up for [Cerebras](https://cloud.cerebras.ai/)
242. Get a Cerebras API Key
253. Save it in a [Val Town environment variable](https://www.val.town/settings/environment-variables) called `CEREBRAS_API_KEY`
2627Once Cerebras is set up in your Val Town account, there are two ways to get started:
37const { OpenAI } = await import("https://esm.sh/openai");
38const client = new OpenAI({
39apiKey: Deno.env.get("CEREBRAS_API_KEY"),
40baseURL: "https://api.cerebras.ai/v1"
41});
42const response = await client.chat.completions.create({
54## Sample apps
5556* **[Cerebras Searcher](https://www.val.town/v/stevekrouse/cerebras_searcher)** - a Perplexity clone that uses the SerpAPI to do RAG
57and summaries with Cerebras (*requires a SerpAPI key*)
58* **[Cerebras Coder](https://www.val.town/v/stevekrouse/cerebras_coder)** - an app that
59generates websites in a second with Cerebras
cerebras_coderREADME.md2 matches
671. Sign up for [Cerebras](https://cloud.cerebras.ai/)
82. Get a Cerebras API Key
93. Save it in a [Val Town environment variable](https://www.val.town/settings/environment-variables) called `CEREBRAS_API_KEY`
cerebras_codermain.tsx5 matches
264} catch (error) {
265Toastify({
266text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
267position: "center",
268duration: 3000,
1044};
1045} else {
1046const client = new Cerebras({ apiKey: Deno.env.get("CEREBRAS_API_KEY") });
1047const completion = await client.chat.completions.create({
1048messages: [
1169<meta name="viewport" content="width=device-width, initial-scale=1.0">
1170<title>CerebrasCoder</title>
1171<link rel="preconnect" href="https://fonts.googleapis.com" />
1172<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
1173<link
1174href="https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400;0,500;1,300;1,400;1,500&family=DM+Sans:ital,opsz,wght@0,9..40,100..1000;1,9..40,100..1000&display=swap"
1175rel="stylesheet"
1176/>
1185<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."">
1186<meta property="og:type" content="website">
1187<meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">
1188
1189