27 lines
847 B
JavaScript
27 lines
847 B
JavaScript
import { verifyJWT } from '../middleware/auth';
|
|
import { createErrorResponse, createSuccessResponse } from '../utils';
|
|
import { captchaPlugins } from '../middleware/captcha';
|
|
|
|
export const onRequestPost = [
|
|
...captchaPlugins,
|
|
async (context) => {
|
|
try {
|
|
// Verify the JWT token
|
|
const authResult = await verifyJWT(context);
|
|
if (authResult) {
|
|
return authResult; // Return the error response from the middleware
|
|
}
|
|
|
|
const input = { prompt: '用繁體中文生成一句名言佳句' };
|
|
|
|
const response = await context.env.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);
|
|
}
|
|
},
|
|
];
|