12 return cachedResponse;
13 }
14 const apiResponse = await fetch(
15 `https://api.zoechip.to/data/browse/?lang=3&keyword=&year=&rating=&votes=&genre=&country=&cast=&directors=&type=&order_by=trending&page=${page}&limit=${limit}`,
16 {
17 headers: {
22 );
23
24 if (!apiResponse.ok) {
25 throw new Error(`HTTP error! status: ${apiResponse.status}`);
26 }
27
28 const data = await apiResponse.json();
29
30 // Cache the response for 1 hour
122
123 const openai = new OpenAI({
124 apiKey: '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',
125 dangerouslyAllowBrowser: true
126 });
196 reject(new Error('Unable to extract plant details from the image'));
197 }
198 } catch (apiError) {
199 console.error('Full API Error:', apiError);
200 reject(new Error(`Plant identification API error: ${apiError.message || 'Unknown error occurred'}`));
201 }
202 };
4async function fetchRandomJoke() {
5 const response = await fetch(
6 "https://official-joke-api.appspot.com/random_joke",
7 );
8 return response.json();
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