feat: daily motto

This commit is contained in:
Tony Yang
2025-04-15 12:01:53 +08:00
parent d227288d14
commit b8ae97e49b
5 changed files with 101 additions and 1 deletions
+25
View File
@@ -0,0 +1,25 @@
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);
}
}