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(vtwn_42EwBu8CJxFYhtU4Raa6C7JxxBy1) });
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`
217 } catch (error) {
218 Toastify({
219 text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
220 position: "center",
221 duration: 3000,
970 };
971 } else {
972 const client = new Cerebras({ apiKey: Deno.env.get("vishu_singh") });
973 const completion = await client.chat.completions.create({
974 messages: [
1095 <meta name="viewport" content="width=device-width, initial-scale=1.0">
1096 <title>CerebrasCoder</title>
1097 <link rel="preconnect" href="https://fonts.googleapis.com" />
1098 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
1099 <link
1100 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"
1101 rel="stylesheet"
1102 />
1111 <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."">
1112 <meta property="og:type" content="website">
1113 <meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">
1114
1115
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`
1/**
2 * Unsplash API Random Photo Endpoint Implementation
3 * Generates random images using the official Unsplash API with caching
4 * Restricted to Val Town and specific origins
5 */
52 }
53
54 // Retrieve Unsplash API access key from environment
55 const UNSPLASH_ACCESS_KEY = Deno.env.get("UNSPLASH_ACCESS_KEY");
56
57 if (!UNSPLASH_ACCESS_KEY) {
58 return new Response("Unsplash API key not configured", { status: 500 });
59 }
60
165 "X-Unsplash-User": cachedResponse.username,
166 "X-Unsplash-Description": cachedResponse.description || "Random Unsplash Image",
167 "X-Powered-By": "Val Town Unsplash API",
168 "Link": `<${cachedResponse.originalLink}>; rel="describedby"`, // Updated link relation type
169 },
175 }
176
177 // Construct Unsplash API URL
178 const unsplashApiUrl = new URL("https://api.unsplash.com/photos/random");
179
180 // Add parameters conditionally
226
227 // Set the search params on the URL
228 unsplashApiUrl.search = searchParams.toString();
229
230 try {
231 const response = await fetch(unsplashApiUrl, {
232 headers: {
233 "Accept-Version": "v1",
239 // Include the response body for more detailed error information
240 const errorBody = await response.text();
241 return new Response(`Failed to fetch from Unsplash API: ${errorBody}`, { status: response.status });
242 }
243
276 "X-Unsplash-User": photo.user.username,
277 "X-Unsplash-Description": photo.description || "Random Unsplash Image",
278 "X-Powered-By": "Val Town Unsplash API",
279 "Link": `<${photo.links.html}>; rel="describedby"`, // Updated link relation type
280 },
541 body { margin: 0; font-family: 'Press Start 2P', cursive; }
542 </style>
543 <link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap" rel="stylesheet">
544 </head>
545 <body>
148function client() {
149 const script = document.createElement('script');
150 script.src = `https://maps.googleapis.com/maps/api/js?key=${window.GOOGLE_MAPS_API_KEY}`;
151 script.async = true;
152 script.defer = true;
161}
162
163async function makeGoogleMapsApiCall(endpoint, params) {
164 const baseUrl = "https://maps.googleapis.com/maps/api";
165 const url = new URL(`${baseUrl}${endpoint}`);
166 url.searchParams.append("key", Deno.env.get("GOOGLE_MAPS_API_KEY"));
167
168 for (const [key, value] of Object.entries(params)) {
172 const response = await fetch(url.toString());
173 if (!response.ok) {
174 throw new Error(`Google Maps API error: ${response.statusText}`);
175 }
176 return await response.json();
183 const { OpenAI } = await import("https://esm.sh/openai");
184 const client = new OpenAI({
185 apiKey: Deno.env.get("CEREBRAS_API_KEY"),
186 baseURL: "https://api.cerebras.ai/v1",
187 });
188
193 {
194 role: "system",
195 content: `The user's current location is: Latitude ${location.lat}, Longitude ${location.lng}. You can use this information to provide location-specific responses. You can also request Google Maps data by responding with a JSON object in the format: {"action": "maps_api", "endpoint": "/maps/api/place/nearbysearch/json", "params": {"location": "${location.lat},${location.lng}", "radius": "1500", "type": "restaurant"}}`
196 }
197 ];
204 const generatedMessage = response.choices[0].message;
205
206 // Check if the response contains a Google Maps API request
207 let mapData = null;
208 try {
209 const jsonResponse = JSON.parse(generatedMessage.content);
210 if (jsonResponse.action === "maps_api") {
211 mapData = await makeGoogleMapsApiCall(jsonResponse.endpoint, jsonResponse.params);
212
213 // Process map data and create markers
228 return Response.json({ message: generatedMessage });
229 } catch (error) {
230 console.error("Error calling Cerebras API:", error);
231
232 if (error.status === 429) {
233 return Response.json({ error: "Cerebras API rate limit reached. Please try again later." }, { status: 429 });
234 } else {
235 return Response.json({ error: `API Error: ${error.message}` }, { status: 500 });
236 }
237 }
252 <script src="https://esm.town/v/std/catch"></script>
253 <script>
254 window.GOOGLE_MAPS_API_KEY = "${Deno.env.get("GOOGLE_MAPS_API_KEY")}";
255 </script>
256 <script type="module" src="${import.meta.url}"></script>
286 // Convert File to Blob explicitly
287 const audioBlob = await audioFile.arrayBuffer();
288 const deepgramResponse = await fetch("https://api.deepgram.com/v1/listen", {
289 method: "POST",
290 headers: {
291 "Authorization": `Token ${Deno.env.get("DEEPGRAM_API_KEY")}`,
292 "Content-Type": "audio/webm", // Ensure correct MIME type
293 },
297 if (!deepgramResponse.ok) {
298 const errorText = await deepgramResponse.text();
299 throw new Error(`Deepgram API error: ${errorText}`);
300 }
301
311 const { OpenAI } = await import("https://esm.sh/openai");
312 const llmClient = new OpenAI({
313 apiKey: Deno.env.get("CEREBRAS_API_KEY"),
314 baseURL: "https://api.cerebras.ai/v1",
315 });
316
387 // Eleven Labs Text to Speech
388 const elevenLabsResponse = await fetch(
389 `https://api.elevenlabs.io/v1/text-to-speech/${Deno.env.get("ELEVENLABS_VOICE_ID")}`,
390 {
391 method: "POST",
393 "Accept": "audio/webm",
394 "Content-Type": "application/json",
395 "xi-api-key": Deno.env.get("ELEVENLABS_API_KEY"),
396 },
397 body: JSON.stringify({
408 if (!elevenLabsResponse.ok) {
409 const errorText = await elevenLabsResponse.text();
410 throw new Error(`Eleven Labs API error: ${errorText}`);
411 }
412
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`
264 } catch (error) {
265 Toastify({
266 text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
267 position: "center",
268 duration: 3000,
1044 };
1045 } else {
1046 const client = new Cerebras({ apiKey: Deno.env.get("CEREBRAS_API_KEY") });
1047 const completion = await client.chat.completions.create({
1048 messages: [
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
1174 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"
1175 rel="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