diff --git a/public/manifest-markdown.json b/public/manifest-markdown.json new file mode 100644 index 0000000..4464f70 --- /dev/null +++ b/public/manifest-markdown.json @@ -0,0 +1,38 @@ +{ + "$schema": "../node_modules/@lobehub/chat-plugin-sdk/schema.json", + "api": [ + { + "url": "http://localhost:3400/api/clothes-md", + "name": "recommendClothes", + "description": "根据用户的心情,给用户推荐他有的衣服", + "parameters": { + "properties": { + "mood": { + "description": "用户当前的心情,可选值有:开心(happy), 难过(sad),生气 (anger),害怕(fear),惊喜( surprise),厌恶 (disgust)", + "enum": ["happy", "sad", "anger", "fear", "surprise", "disgust"], + "type": "string" + }, + "gender": { + "type": "string", + "enum": ["man", "woman"], + "description": "对话用户的性别,需要询问用户后才知道这个信息" + } + }, + "required": ["mood", "gender"], + "type": "object" + } + } + ], + "author": "LobeHub", + "createdAt": "2023-09-03", + "identifier": "plugin-identifier-markdown", + "meta": { + "avatar": "🚀", + "tags": ["template"], + "title": "Chat Plugin Template", + "description": "This is the plugin template for LobeChat plugin development" + }, + "systemRole": "根据用户的心情,给用户推荐适合他穿的衣服,你需要知道他的性别后才进行推荐,否则推荐不准确。", + "type": "markdown", + "version": "1" +} diff --git a/src/pages/api/clothes-md.ts b/src/pages/api/clothes-md.ts new file mode 100644 index 0000000..2634501 --- /dev/null +++ b/src/pages/api/clothes-md.ts @@ -0,0 +1,26 @@ +import { PluginErrorType, createErrorResponse } from '@lobehub/chat-plugin-sdk'; + +import { manClothes, womanClothes } from '@/data'; +import { RequestData, ResponseData } from '@/type'; + +export const config = { + runtime: 'edge', +}; + +export default async (req: Request) => { + if (req.method !== 'POST') return createErrorResponse(PluginErrorType.MethodNotAllowed); + + const { gender, mood } = (await req.json()) as RequestData; + + const clothes = gender === 'man' ? manClothes : womanClothes; + + const result: ResponseData = { + clothes: mood ? clothes[mood] : Object.values(clothes).flat(), + mood, + today: Date.now(), + }; + + return new Response( + `由于你的心情是${result.mood},我推荐你穿 ${result.clothes.map((c) => c.name).join('、')}。`, + ); +};