import { verifyJWT } from '../middleware/auth'; import { createErrorResponse, createSuccessResponse } from '../utils'; export async function onRequestGet(context) { try { // Verify the JWT token const authResult = await verifyJWT(context); if (authResult) { return authResult; // Return the error response from the middleware } // Use Cloudflare AI Gateway to proxy the request to Google AI Studio const ai = context.env.AI; const input = { prompt: '用繁體中文生成一句名言佳句' }; const response = await ai.run('@cf/meta/llama-3.2-1b-instruct', input); const motto = response.response; return createSuccessResponse({ motto }); } catch (error) { console.error("Gen motto error:", error); return createErrorResponse("Get motto failed", 500); } }