Skip to content

Commit 0a6e154

Browse files
committed
✨ feat: support markdown type
1 parent 0f51c54 commit 0a6e154

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

public/manifest-markdown.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "../node_modules/@lobehub/chat-plugin-sdk/schema.json",
3+
"api": [
4+
{
5+
"url": "http://localhost:3400/api/clothes-md",
6+
"name": "recommendClothes",
7+
"description": "根据用户的心情,给用户推荐他有的衣服",
8+
"parameters": {
9+
"properties": {
10+
"mood": {
11+
"description": "用户当前的心情,可选值有:开心(happy), 难过(sad),生气 (anger),害怕(fear),惊喜( surprise),厌恶 (disgust)",
12+
"enum": ["happy", "sad", "anger", "fear", "surprise", "disgust"],
13+
"type": "string"
14+
},
15+
"gender": {
16+
"type": "string",
17+
"enum": ["man", "woman"],
18+
"description": "对话用户的性别,需要询问用户后才知道这个信息"
19+
}
20+
},
21+
"required": ["mood", "gender"],
22+
"type": "object"
23+
}
24+
}
25+
],
26+
"author": "LobeHub",
27+
"createdAt": "2023-09-03",
28+
"identifier": "plugin-identifier-markdown",
29+
"meta": {
30+
"avatar": "🚀",
31+
"tags": ["template"],
32+
"title": "Chat Plugin Template",
33+
"description": "This is the plugin template for LobeChat plugin development"
34+
},
35+
"systemRole": "根据用户的心情,给用户推荐适合他穿的衣服,你需要知道他的性别后才进行推荐,否则推荐不准确。",
36+
"type": "markdown",
37+
"version": "1"
38+
}

src/pages/api/clothes-md.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { PluginErrorType, createErrorResponse } from '@lobehub/chat-plugin-sdk';
2+
3+
import { manClothes, womanClothes } from '@/data';
4+
import { RequestData, ResponseData } from '@/type';
5+
6+
export const config = {
7+
runtime: 'edge',
8+
};
9+
10+
export default async (req: Request) => {
11+
if (req.method !== 'POST') return createErrorResponse(PluginErrorType.MethodNotAllowed);
12+
13+
const { gender, mood } = (await req.json()) as RequestData;
14+
15+
const clothes = gender === 'man' ? manClothes : womanClothes;
16+
17+
const result: ResponseData = {
18+
clothes: mood ? clothes[mood] : Object.values(clothes).flat(),
19+
mood,
20+
today: Date.now(),
21+
};
22+
23+
return new Response(
24+
`由于你的心情是${result.mood},我推荐你穿 ${result.clothes.map((c) => c.name).join('、')}。`,
25+
);
26+
};

0 commit comments

Comments
 (0)