aetherwu commited on
Commit
bdfe5af
1 Parent(s): 4f3c434

Update bot-api.md

Browse files
Files changed (1) hide show
  1. bot-api.md +24 -1
bot-api.md CHANGED
@@ -12,9 +12,15 @@ https://www.my-bot.com/api/v1/chat
12
 
13
 
14
 
15
-
16
  ## [方案一] 标准接口
17
 
 
 
 
 
 
 
 
18
  **POST** `~/chat` (接口地址必须以 `chat` 结尾)
19
 
20
  请求体(JSON):
@@ -42,6 +48,10 @@ https://www.my-bot.com/api/v1/chat
42
  }
43
  ```
44
 
 
 
 
 
45
 
46
 
47
  ## [方案二] Hugging Face 风格接口
@@ -75,5 +85,18 @@ https://www.my-bot.com/api/v1/chat
75
  }
76
  ```
77
 
 
78
 
 
 
 
 
 
 
 
 
 
 
 
79
 
 
12
 
13
 
14
 
 
15
  ## [方案一] 标准接口
16
 
17
+ 这是平台向机器人(也就是提供服务的第三方)发起的请求。
18
+ 在这个请求里,平台会向机器人提供本次对话的唯一标识 qid(query id) 和唯一用户标识 uid(user id)。
19
+ 机器人需要自行储存或处理 qid 和 uid,以便支持以下需求:
20
+
21
+ - qid:单个用户的多轮对话。
22
+ - uid:区别多个用户的对话。
23
+
24
  **POST** `~/chat` (接口地址必须以 `chat` 结尾)
25
 
26
  请求体(JSON):
48
  }
49
  ```
50
 
51
+ 字段名 | 类型 | 必填 | 含义 | 示例 | 备注
52
+ ---|---|:---:|---|---|---
53
+ `type` | String | ✓ | 返回类型 |`text`| 目前支持 text 和 markdown
54
+ `content` | String | | 机器人所返回的内容 |`很高兴见到你,我是……`|
55
 
56
 
57
  ## [方案二] Hugging Face 风格接口
85
  }
86
  ```
87
 
88
+ 在 Hugging Face 里,你可以通过一下方式来完成:
89
 
90
+ ```
91
+ def chat(p, qid, uid):
92
+ #your process
93
+ return ["text", response]
94
+
95
+ iface = gr.Interface(fn=chat,
96
+ inputs=["text", "text", "text"],
97
+ outputs=["text", "text"],
98
+ description="""这是我的机器人""")
99
+ iface.launch()
100
+ ```
101
 
102
+ 其中,gr.Interface 的 inputs 对应了 chat 的三个输入参数, outputs 对应了 chat 返回的两个变量。