Skip to content

Commit

Permalink
✨ feat: support markdown type
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Dec 29, 2023
1 parent 0f51c54 commit 0a6e154
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
38 changes: 38 additions & 0 deletions public/manifest-markdown.json
Original file line number Diff line number Diff line change
@@ -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"
}
26 changes: 26 additions & 0 deletions src/pages/api/clothes-md.ts
Original file line number Diff line number Diff line change
@@ -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('、')}。`,
);
};

0 comments on commit 0a6e154

Please sign in to comment.