8 "https://www.ikea.com/de/de/customer-service/services/buy-back/zweite-chance-markt-online-pub67d33610";
9
10 const apiUrl = `https://web-api.ikea.com/circular/circular-asis/offers/public/${locale}?size=64&stores=${
11 stores.join(",")
12 }&column=id&direction=desc&page=0`;
13 const storageKey = `ikeaSecondChanceOffers-${locale}-${stores.join(",")}-lastKnownItem`;
14
15 const response = await fetch(apiUrl);
16 const data: {
17 content: {
1# Research Agent over email
2
3This is a lightweight wrapper around Perplexity's web search API that you can interact with via email.
16 );
17
18 const client = new OpenAI({ apiKey: process.env.PERPLEXITY_API_KEY, baseURL: "https://api.perplexity.ai" });
19 const response = await client.chat.completions.create({
20 model: "sonar",
9
101. Add ability for users to input their own username
112. Add ability for users to input their API token so they can see private projects
7## Hono
8
9This app uses [Hono](https://hono.dev/) as the API framework. You can think of Hono as a replacement for [ExpressJS](https://expressjs.com/) that works in serverless environments like Val Town or Cloudflare Workers. If you come from Python or Ruby, Hono is also a lot like [Flask](https://github.com/pallets/flask) or [Sinatra](https://github.com/sinatra/sinatra), respectively.
10
11## Serving assets to the frontend
19### `index.html`
20
21The most complicated part of this backend API is serving index.html. In this app (like most apps) we serve it at the root, ie `GET /`.
22
23We *bootstrap* `index.html` with some initial data from the server, so that it gets dynamically injected JSON data without having to make another round-trip request to the server to get that data on the frontend. This is a common pattern for client-side rendered apps.
24
25## CRUD API Routes
26
27This app has two CRUD API routes: for reading and inserting into the messages table. They both speak JSON, which is standard. They import their functions from `/backend/database/queries.ts`. These routes are called from the React app to refresh and update data.
28
29## Errors
30
31Hono and other API frameworks have a habit of swallowing up Errors. We turn off this default behavior by re-throwing errors, because we think most of the time you'll want to see the full stack trace instead of merely "Internal Server Error". You can customize how you want errors to appear.
57
58 try {
59 // Make the API call to OpenAI
60 const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
61
62 const response = await fetch("https://api.openai.com/v1/chat/completions", {
63 method: "POST",
64 headers: {
65 "Content-Type": "application/json",
66 "Authorization": `Bearer ${OPENAI_API_KEY}`,
67 },
68 body: JSON.stringify({
85 if (!response.ok) {
86 const errorData = await response.json();
87 console.error("OpenAI API error:", errorData);
88 throw new Error(`OpenAI API error: ${errorData.error?.message || "Unknown error"}`);
89 }
90
24 setIsLoading(true);
25 setError(null);
26 const response = await fetch("/api/reviews");
27 if (!response.ok) {
28 throw new Error(`HTTP error! status: ${response.status}`);
41 e.preventDefault();
42 try {
43 const response = await fetch("/api/submit-review", {
44 method: "POST",
45 headers: { "Content-Type": "application/json" },
64 setIsAnalyzing(true);
65 setError(null);
66 const response = await fetch("/api/analyze-reviews", { method: "POST" });
67 if (!response.ok) {
68 throw new Error(`HTTP error! status: ${response.status}`);
82 setIsClearing(true);
83 setError(null);
84 const response = await fetch("/api/clear-reviews", { method: "POST" });
85 if (!response.ok) {
86 throw new Error(`HTTP error! status: ${response.status}`);
37
38// Provide an endpoint for the frontend to get reviews as JSON
39app.get("/api/reviews", async (c) => {
40 const reviews = await getReviews();
41 return c.json({ reviews });
43
44// Provide an endpoint for the frontend to insert a new review
45app.post("/api/submit-review", async (c) => {
46 const { name, cake1Review, cake2Review } = await c.req.json();
47 if (
56
57// Provide an endpoint for analyzing reviews
58app.post("/api/analyze-reviews", async (c) => {
59 const winner = await analyzeReviews();
60 return c.json({ winner });
62
63// Provide an endpoint for clearing all reviews
64app.post("/api/clear-reviews", async (c) => {
65 await clearReviews();
66 return c.json({ success: true });
9
101. Add ability for users to input their own username
112. Add ability for users to input their API token so they can see private projects
11 },
12 {
13 "prompt": "weather dashboard for nyc using open-meteo API for NYC with icons",
14 "title": "Weather App",
15 "code": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>NYC Weather</title>\n <link href=\"https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css\" rel=\"stylesheet\">\n <style>\n .weather-icon {\n font-size: 48px;\n margin-bottom: 16px;\n }\n </style>\n</head>\n<body class=\"h-screen bg-blue-100 flex justify-center items-center p-4\">\n <div class=\"bg-white p-8 rounded-md shadow-md w-full max-w-sm md:p-12 lg:p-16 xl:p-20\">\n <h1 class=\"text-2xl font-bold mb-4 text-center text-blue-500\">NYC Weather</h1>\n <div id=\"weather\" class=\"mb-4 p-4 text-center\">\n <div id=\"temperature\" class=\"text-4xl font-bold mb-4\"></div>\n <div id=\"condition\" class=\"text-xl font-medium mb-4\"></div>\n <div id=\"humidity\" class=\"text-lg font-light mb-2\">Humidity: <span id=\"humidity-value\"></span>%</div>\n <div id=\"wind\" class=\"text-lg font-light mb-2\">Wind: <span id=\"wind-value\"></span> mph</div>\n <i id=\"weather-icon\" class=\"weather-icon text-blue-500\"></i>\n </div>\n </div>\n <p class=\"fixed bottom-0 left-0 right-0 text-center p-4 text-gray-600 md:p-6 lg:p-8 xl:p-10\">\n Built on <a class=\"text-blue-600\" href=\"https://cerebrascoder.com\">Cerebras Coder</a>\n </p>\n\n <script>\n // Sample weather data\n const weatherData = {\n temperature: 75,\n condition: 'Sunny',\n humidity: 60,\n wind: 10,\n icon: 'sun'\n };\n\n document.getElementById('temperature').innerText = `${weatherData.temperature}°F`;\n document.getElementById('condition').innerText = weatherData.condition;\n document.getElementById('humidity-value').innerText = weatherData.humidity;\n document.getElementById('wind-value').innerText = weatherData.wind;\n\n // Map weather icon\n const weatherIcons = {\n 'sun': '☀',\n 'cloud': '☀',\n 'rain': '☃',\n 'snow': '☄'\n };\n\n document.getElementById('weather-icon').innerHTML = weatherIcons[weatherData.icon] || '';\n </script>\n</body>\n</html>",