-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('、')}。`, | ||
); | ||
}; |