212 } catch (error) {
213 Toastify({
214 text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
215 position: "center",
216 duration: 3000,
1024 };
1025 } else {
1026 const client = new Cerebras({ apiKey: Deno.env.get("CEREBRAS_API_KEY") });
1027 const completion = await client.chat.completions.create({
1028 messages: [
1149 <meta name="viewport" content="width=device-width, initial-scale=1.0">
1150 <title>CerebrasCoder</title>
1151 <link rel="preconnect" href="https://fonts.googleapis.com" />
1152 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
1153 <link
1154 href="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"
1155 rel="stylesheet"
1156 />
1165 <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."">
1166 <meta property="og:type" content="website">
1167 <meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">
1168
1169
20 };
21 } else {
22 const client = new Cerebras({ apiKey: Deno.env.get("CEREBRAS_API_KEY") });
23 const completion = await client.chat.completions.create({
24 messages: [
57
58export default async function cerebras_coder(req: Request): Promise<Response> {
59 // Handle API requests for code generation
60 if (req.method === 'POST') {
61 try {
6
71. 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`
10
11# Todos
6
71. 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`
10
11# Todos
212 } catch (error) {
213 Toastify({
214 text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
215 position: "center",
216 duration: 3000,
1024 };
1025 } else {
1026 const client = new Cerebras({ apiKey: Deno.env.get("CEREBRAS_API_KEY") });
1027 const completion = await client.chat.completions.create({
1028 messages: [
1149 <meta name="viewport" content="width=device-width, initial-scale=1.0">
1150 <title>CerebrasCoder</title>
1151 <link rel="preconnect" href="https://fonts.googleapis.com" />
1152 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
1153 <link
1154 href="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"
1155 rel="stylesheet"
1156 />
1165 <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."">
1166 <meta property="og:type" content="website">
1167 <meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">
1168
1169
6
71. 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`
10
11# Todos
212 } catch (error) {
213 Toastify({
214 text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
215 position: "center",
216 duration: 3000,
1024 };
1025 } else {
1026 const client = new Cerebras({ apiKey: Deno.env.get("CEREBRAS_API_KEY") });
1027 const completion = await client.chat.completions.create({
1028 messages: [
1149 <meta name="viewport" content="width=device-width, initial-scale=1.0">
1150 <title>CerebrasCoder</title>
1151 <link rel="preconnect" href="https://fonts.googleapis.com" />
1152 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
1153 <link
1154 href="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"
1155 rel="stylesheet"
1156 />
1165 <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."">
1166 <meta property="og:type" content="website">
1167 <meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">
1168
1169
6
71. 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`
10
11# Todos
212 } catch (error) {
213 Toastify({
214 text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
215 position: "center",
216 duration: 3000,
1024 };
1025 } else {
1026 const client = new Cerebras({ apiKey: Deno.env.get("CEREBRAS_API_KEY") });
1027 const completion = await client.chat.completions.create({
1028 messages: [
1149 <meta name="viewport" content="width=device-width, initial-scale=1.0">
1150 <title>CerebrasCoder</title>
1151 <link rel="preconnect" href="https://fonts.googleapis.com" />
1152 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
1153 <link
1154 href="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"
1155 rel="stylesheet"
1156 />
1165 <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."">
1166 <meta property="og:type" content="website">
1167 <meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">
1168
1169
27 const [adContent, setAdContent] = useState("");
28 const [selectedProvider, setSelectedProvider] = useState("OpenAI");
29 const [apiKey, setApiKey] = useState("");
30
31 useEffect(() => {
39 setUser(userData);
40 setSelectedProvider(userData.aiProvider || "OpenAI");
41 setApiKey(userData.apiKey || "");
42 };
43
55 method: "POST",
56 headers: { "Content-Type": "application/json" },
57 body: JSON.stringify({ topic, format, provider: selectedProvider, apiKey }),
58 });
59 const data = await response.json();
91 };
92
93 const handleApiKeyChange = async (e) => {
94 const newApiKey = e.target.value;
95 setApiKey(newApiKey);
96 await updateUserSettings({ apiKey: newApiKey });
97 };
98
160 </div>
161 <div>
162 <label htmlFor="apiKey" className="block mb-2">API Key:</label>
163 <input
164 type="password"
165 id="apiKey"
166 value={apiKey}
167 onChange={handleApiKeyChange}
168 placeholder="Enter your API key"
169 className="w-full p-2 border rounded"
170 />
172 <button
173 type="submit"
174 disabled={isLoading || (user && user.contentGenerated >= SUBSCRIPTION_TIERS[user.tier].contentLimit) || !apiKey}
175 className="w-full bg-blue-500 text-white p-2 rounded hover:bg-blue-600 disabled:opacity-50"
176 >
294 contentGenerated INTEGER NOT NULL,
295 aiProvider TEXT,
296 apiKey TEXT
297 )
298 `);
304 await sqlite.execute(`
305 INSERT INTO ${KEY}_users_${SCHEMA_VERSION}
306 (name, tier, contentGenerated, aiProvider, apiKey)
307 VALUES (?, ?, ?, ?, ?)
308 `, ["Demo User", "FREE", 0, "OpenAI", ""]);
341 if (url.pathname === "/generate") {
342 try {
343 const { topic, format, provider, apiKey } = await request.json();
344
345 // Get current user
429 }
430
431 if (settings.apiKey) {
432 updateFields.push("apiKey = ?");
433 updateValues.push(settings.apiKey);
434 }
435