4async function fetchRandomJoke() {
5 const response = await fetch(
6 "https://official-joke-api.appspot.com/random_joke",
7 );
8 return response.json();
213 }
214
215 // 使用开放的翻译API作为备选方案
216 const translationResponse = await fetch(
217 `https://translate.googleapis.com/translate_a/single?client=gtx&sl=${source_lang === 'auto' ? 'auto' : source_lang}&tl=${target_lang}&dt=t&q=${encodeURIComponent(text)}`,
218 {
219 method: 'GET',
233 const translationData = await translationResponse.json();
234
235 // 从Google翻译API提取翻译文本
236 const translatedText = translationData[0].reduce((acc, item) => {
237 return acc + (item[0] || '');
75async function identifyPlant(imageFile) {
76 return new Promise((resolve, reject) => {
77 // Simulate API call with image processing
78 const reader = new FileReader();
79 reader.onloadend = () => {
3export default async function generatePoem() {
4 try {
5 // Retrieve the Anthropic API key from environment variables
6 const apiKey = Deno.env.get("ANTHROPIC_API_KEY");
7
8 // Check if API key is present
9 if (!apiKey) {
10 throw new Error("Anthropic API key is missing. Please set the ANTHROPIC_API_KEY environment variable.");
11 }
12
13 // Create Anthropic instance with the API key
14 const anthropic = new Anthropic({
15 apiKey: apiKey,
16 });
17
18 console.log("Anthropic API Key Status: Present ✅");
19 console.log("Attempting to create message...");
20
64 // More detailed error logging
65 if (error.response) {
66 console.error("API Response Error Details:", {
67 status: error.response.status,
68 body: error.response.body,
9export async function getGeminiModels(): Promise<GeminiModel[]> {
10 try {
11 const API_KEY = process.env.GEMINI_API_KEY;
12
13 const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${API_KEY}`);
14
15 const data = await response.json();
13## Authentication
14
15Login to your SQLite Explorer with [password authentication](https://www.val.town/v/pomdtr/password_auth) with your [Val Town API Token](https://www.val.town/settings/api) as the password.
16
17## Todos / Plans
27 <head>
28 <title>SQLite Explorer</title>
29 <link rel="preconnect" href="https://fonts.googleapis.com" />
30
31 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
32 <link
33 href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@300..700&family=Source+Sans+3:ital,wght@0,200..900;1,200..900&display=swap"
34 rel="stylesheet"
35 />
1/**
2 * This code creates a geocoder widget similar to the Google Maps API search widget.
3 * It uses React for the frontend, the Cerebras API for LLM-based geocoding,
4 * and Leaflet for displaying the map.
5 */
124 const { query } = await request.json();
125
126 const prompt = `You are a geocoding API. Return up to 5 possible matches.
127 Respond with only the completions, separated by newlines.`;
128
129 try {
130 const response = await fetch("https://api.cerebras.ai/v1/chat/completions", {
131 method: "POST",
132 headers: {
133 "Content-Type": "application/json",
134 "Authorization": `Bearer ${Deno.env.get("CEREBRAS_API_KEY")}`,
135 },
136 body: JSON.stringify({
146
147 if (!response.ok) {
148 throw new Error("Failed to fetch from Cerebras API");
149 }
150
157 });
158 } catch (error) {
159 console.error("Error calling Cerebras API:", error);
160 return new Response(JSON.stringify({ error: "Failed to fetch suggestions" }), {
161 status: 500,
63 const fetchStories = async () => {
64 try {
65 const response = await fetch("/api/stories");
66 if (!response.ok) throw new Error("Failed to fetch dates");
67 const data = await response.json();
77 try {
78 dispatch({ type: "loading", value: true });
79 const response = await fetch(`/api/comments?query=${encodeURIComponent(query)}&story=${story}&page=${page}`);
80 if (!response.ok) throw new Error("Failed to fetch comments");
81 const data = await response.json();
360export default async function(req: Request): Promise<Response> {
361 const url = new URL(req.url);
362 if (url.pathname === "/api/stories") {
363 const storySearch = await hnSearch({
364 search_by_date: true,
381 }
382
383 if (url.pathname === "/api/comments") {
384 const params = url.searchParams;
385 const query = params.get("query") || "";