Dify接入微信

需求前瞻

  1. Dify如何把普通聊天机器人接入微信
  2. 自定义编排工作流机器人如何联网搜索
  3. 搜索获取的数据如何展示

Dify接入

github项目地址 dify-on-wechat

自定义Dify工具: Serper API

Dify没有直接提供SerperAPI的工具, 于是对着给的例子写了个勉强能用的openapi json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{
"openapi": "3.1.0",
"info": {
"title": "Search Function",
"description": "Performs a search operation",
"version": "v1.0.0"
},
"servers": [
{
"url": "https://google.serper.dev"
}
],
"paths": {
"/search": {
"post": {
"description": "Execute a search",
"operationId": "googleSearch",
"parameters": [],
"requestBody": {
"content": {
"application/json": {
"schema": {
"properties": {
"q": {
"type": "string",
"description": "The search query"
}
},
"required": [
"q"
]
}
}
},
"required": true
},
"deprecated": false
}
}
},
"components": {
"schemas": {}
}
}

搜索结果数据处理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import json

def main(arg1: str) -> dict:
try:
data = json.loads(arg1)
text_data = json.loads(data['text'])
organic = text_data.get('organic', [])
return {
"result": organic
}
except json.JSONDecodeError:
return {
"result": []
}

全局流程图

image.png