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`
loyalOrangeCanidaemain.tsx5 matches
217} catch (error) {
218Toastify({
219text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
220position: "center",
221duration: 3000,
970};
971} else {
972const client = new Cerebras({ apiKey: Deno.env.get("vishu_singh") });
973const completion = await client.chat.completions.create({
974messages: [
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
1100href="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"
1101rel="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
loyalOrangeCanidaeREADME.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`
unsplashSourceReimplementationmain.tsx11 matches
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}
5354// Retrieve Unsplash API access key from environment
55const UNSPLASH_ACCESS_KEY = Deno.env.get("UNSPLASH_ACCESS_KEY");
5657if (!UNSPLASH_ACCESS_KEY) {
58return new Response("Unsplash API key not configured", { status: 500 });
59}
60165"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}
176177// Construct Unsplash API URL
178const unsplashApiUrl = new URL("https://api.unsplash.com/photos/random");
179180// Add parameters conditionally
226227// Set the search params on the URL
228unsplashApiUrl.search = searchParams.toString();
229230try {
231const response = await fetch(unsplashApiUrl, {
232headers: {
233"Accept-Version": "v1",
239// Include the response body for more detailed error information
240const errorBody = await response.text();
241return new Response(`Failed to fetch from Unsplash API: ${errorBody}`, { status: response.status });
242}
243276"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},
541body { 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() {
149const script = document.createElement('script');
150script.src = `https://maps.googleapis.com/maps/api/js?key=${window.GOOGLE_MAPS_API_KEY}`;
151script.async = true;
152script.defer = true;
161}
162163async function makeGoogleMapsApiCall(endpoint, params) {
164const baseUrl = "https://maps.googleapis.com/maps/api";
165const url = new URL(`${baseUrl}${endpoint}`);
166url.searchParams.append("key", Deno.env.get("GOOGLE_MAPS_API_KEY"));
167
168for (const [key, value] of Object.entries(params)) {
172const response = await fetch(url.toString());
173if (!response.ok) {
174throw new Error(`Google Maps API error: ${response.statusText}`);
175}
176return await response.json();
183const { OpenAI } = await import("https://esm.sh/openai");
184const client = new OpenAI({
185apiKey: Deno.env.get("CEREBRAS_API_KEY"),
186baseURL: "https://api.cerebras.ai/v1",
187});
188193{
194role: "system",
195content: `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];
204const generatedMessage = response.choices[0].message;
205206// Check if the response contains a Google Maps API request
207let mapData = null;
208try {
209const jsonResponse = JSON.parse(generatedMessage.content);
210if (jsonResponse.action === "maps_api") {
211mapData = await makeGoogleMapsApiCall(jsonResponse.endpoint, jsonResponse.params);
212
213// Process map data and create markers
228return Response.json({ message: generatedMessage });
229} catch (error) {
230console.error("Error calling Cerebras API:", error);
231232if (error.status === 429) {
233return Response.json({ error: "Cerebras API rate limit reached. Please try again later." }, { status: 429 });
234} else {
235return Response.json({ error: `API Error: ${error.message}` }, { status: 500 });
236}
237}
252<script src="https://esm.town/v/std/catch"></script>
253<script>
254window.GOOGLE_MAPS_API_KEY = "${Deno.env.get("GOOGLE_MAPS_API_KEY")}";
255</script>
256<script type="module" src="${import.meta.url}"></script>
AlwaysHere_migratedmain.tsx8 matches
286// Convert File to Blob explicitly
287const audioBlob = await audioFile.arrayBuffer();
288const deepgramResponse = await fetch("https://api.deepgram.com/v1/listen", {
289method: "POST",
290headers: {
291"Authorization": `Token ${Deno.env.get("DEEPGRAM_API_KEY")}`,
292"Content-Type": "audio/webm", // Ensure correct MIME type
293},
297if (!deepgramResponse.ok) {
298const errorText = await deepgramResponse.text();
299throw new Error(`Deepgram API error: ${errorText}`);
300}
301311const { OpenAI } = await import("https://esm.sh/openai");
312const llmClient = new OpenAI({
313apiKey: Deno.env.get("CEREBRAS_API_KEY"),
314baseURL: "https://api.cerebras.ai/v1",
315});
316387// Eleven Labs Text to Speech
388const elevenLabsResponse = await fetch(
389`https://api.elevenlabs.io/v1/text-to-speech/${Deno.env.get("ELEVENLABS_VOICE_ID")}`,
390{
391method: "POST",
393"Accept": "audio/webm",
394"Content-Type": "application/json",
395"xi-api-key": Deno.env.get("ELEVENLABS_API_KEY"),
396},
397body: JSON.stringify({
408if (!elevenLabsResponse.ok) {
409const errorText = await elevenLabsResponse.text();
410throw new Error(`Eleven Labs API error: ${errorText}`);
411}
412
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
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