Spaces:
Sleeping
Sleeping
[update]add express delivery check
Browse files- examples.json +10 -0
- functions/get_current_weather.py +5 -0
- functions/get_express_delivery_information.py +199 -0
- functions/get_pizza_restaurant_menu.py +6 -0
- main.py +1 -3
examples.json
CHANGED
@@ -40,5 +40,15 @@
|
|
40 |
"gpt-4-1106-preview",
|
41 |
"你好。",
|
42 |
"相比于知识问答机器人,客服机器人需要主题向客户提问以引导客户,此示例主要测试客服机器人的配置技巧。"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
]
|
44 |
]
|
|
|
40 |
"gpt-4-1106-preview",
|
41 |
"你好。",
|
42 |
"相比于知识问答机器人,客服机器人需要主题向客户提问以引导客户,此示例主要测试客服机器人的配置技巧。"
|
43 |
+
],
|
44 |
+
[
|
45 |
+
"快递查询",
|
46 |
+
"请你帮助用户查询快递信息,国内快递和国际快递都可以查。",
|
47 |
+
null,
|
48 |
+
"{\"type\": \"function\", \"function\": {\"name\": \"get_express_delivery_information\", \"description\": \"在此根据跟踪号查询物流信息。\", \"parameters\": {\"type\": \"object\", \"properties\": {\"track_id\": {\"type\": \"string\", \"description\": \"物流跟踪号码。\"}, \"four_digits\": {\"type\": \"string\", \"description\": \"出于对用户隐私的考虑,有些物流商可能会要求你提供收件人或寄件人手机号码后四位。\"}, \"captcha\": {\"type\": \"string\", \"description\": \"有些物流商的查询可能要求你提供图像验证码。\"}}, \"required\": [\"track_id\"]}}}",
|
49 |
+
null,
|
50 |
+
"gpt-4-1106-preview",
|
51 |
+
"你好。",
|
52 |
+
"快递查询函数通过联网调用API来实现。"
|
53 |
]
|
54 |
]
|
functions/get_current_weather.py
CHANGED
@@ -5,6 +5,11 @@ from typing import List
|
|
5 |
|
6 |
|
7 |
def get_current_weather(location: str, unit: str = None):
|
|
|
|
|
|
|
|
|
|
|
8 |
unit = unit or "fahrenheit"
|
9 |
|
10 |
if "tokyo" in location.lower():
|
|
|
5 |
|
6 |
|
7 |
def get_current_weather(location: str, unit: str = None):
|
8 |
+
"""
|
9 |
+
如果函数的名字叫作 “get_current_weather” ,
|
10 |
+
那么就需要一个同名 python 脚本 “get_current_weather.py” ,
|
11 |
+
同时其中应包含一个名为 “get_current_weather” 的函数。
|
12 |
+
"""
|
13 |
unit = unit or "fahrenheit"
|
14 |
|
15 |
if "tokyo" in location.lower():
|
functions/get_express_delivery_information.py
ADDED
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/python3
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
import json
|
4 |
+
import re
|
5 |
+
import time
|
6 |
+
|
7 |
+
import requests
|
8 |
+
|
9 |
+
|
10 |
+
def get_operator_by_track_id_baidu(track_id: str):
|
11 |
+
url = "https://alayn.baidu.com/express/appdetail/get_com"
|
12 |
+
|
13 |
+
params = {
|
14 |
+
"num": track_id
|
15 |
+
}
|
16 |
+
resp = requests.request(
|
17 |
+
"GET",
|
18 |
+
url=url,
|
19 |
+
params=params
|
20 |
+
)
|
21 |
+
|
22 |
+
if resp.status_code == 200:
|
23 |
+
match = re.search(r"\{.*\}", resp.text, flags=re.IGNORECASE)
|
24 |
+
if match is not None:
|
25 |
+
json_str = match.group(0)
|
26 |
+
js = json.loads(json_str)
|
27 |
+
message = js["message"]
|
28 |
+
if message == "fail":
|
29 |
+
return None
|
30 |
+
else:
|
31 |
+
company = js["data"]["company"]
|
32 |
+
return company
|
33 |
+
|
34 |
+
return None
|
35 |
+
|
36 |
+
|
37 |
+
def get_operator_by_track_id(track_id: str):
|
38 |
+
url = "https://trace.fkdex.com/auto/{}".format(track_id)
|
39 |
+
|
40 |
+
headers = {
|
41 |
+
# 不给出 Referer 时,它会生成随机的物流信息。
|
42 |
+
"Referer": "https://www.ickd.cn/",
|
43 |
+
}
|
44 |
+
|
45 |
+
params = {
|
46 |
+
"mailNo": track_id,
|
47 |
+
}
|
48 |
+
resp = requests.request(
|
49 |
+
"GET",
|
50 |
+
url=url,
|
51 |
+
headers=headers,
|
52 |
+
params=params
|
53 |
+
)
|
54 |
+
print(resp.status_code)
|
55 |
+
print(resp.text)
|
56 |
+
|
57 |
+
if resp.status_code == 200:
|
58 |
+
js = resp.json()
|
59 |
+
exp_text_name = js["expTextName"]
|
60 |
+
exp_spell_name = js["expSpellName"]
|
61 |
+
message = js["message"]
|
62 |
+
|
63 |
+
return exp_spell_name
|
64 |
+
return resp.text
|
65 |
+
|
66 |
+
|
67 |
+
def get_express_delivery_information(track_id: str, four_digits: str = None, captcha: str = None):
|
68 |
+
"""
|
69 |
+
如果函数的名字叫作 “get_express_delivery_information” ,
|
70 |
+
那么就需要一个同名 python 脚本 “get_express_delivery_information.py” ,
|
71 |
+
同时其中应包含一个名为 “get_express_delivery_information” 的函数。
|
72 |
+
|
73 |
+
https://www.ickd.cn/
|
74 |
+
|
75 |
+
:param track_id: str, egs: 433542074086264.
|
76 |
+
:param four_digits: str, 收件人或寄件人手机号码后四位. egs: 4154.
|
77 |
+
:param captcha: str, egs: b2Nbm.
|
78 |
+
:return: info: str.
|
79 |
+
"""
|
80 |
+
|
81 |
+
operator = get_operator_by_track_id(track_id)
|
82 |
+
|
83 |
+
if four_digits is None:
|
84 |
+
url = "https://trace.fkdex.com/{}/{}".format(operator, track_id)
|
85 |
+
else:
|
86 |
+
url = "https://trace.fkdex.com/{}/{}:{}".format(operator, track_id, four_digits)
|
87 |
+
|
88 |
+
headers = {
|
89 |
+
# 不给出 Referer 时,它会生成随机的物流信息。
|
90 |
+
"Referer": "https://www.ickd.cn/",
|
91 |
+
"Cookie": "PHPSESSID=95c179f9fa0c117c31a8e3f440257d24"
|
92 |
+
}
|
93 |
+
|
94 |
+
params = {
|
95 |
+
"mailNo": "{}:{}".format(track_id, four_digits),
|
96 |
+
"verifyCode": captcha
|
97 |
+
}
|
98 |
+
|
99 |
+
resp = requests.request(
|
100 |
+
"GET",
|
101 |
+
url=url,
|
102 |
+
headers=headers,
|
103 |
+
params=params
|
104 |
+
)
|
105 |
+
|
106 |
+
print(resp.status_code)
|
107 |
+
print(resp.text)
|
108 |
+
if resp.status_code == 200:
|
109 |
+
js = resp.json()
|
110 |
+
error_code = js["errCode"]
|
111 |
+
message = js["message"]
|
112 |
+
exp_text_name = js["expTextName"]
|
113 |
+
exp_spell_name = js["expSpellName"]
|
114 |
+
data = js["data"]
|
115 |
+
|
116 |
+
if error_code == 1:
|
117 |
+
# 请输入正确的单号
|
118 |
+
return message
|
119 |
+
elif error_code == 2:
|
120 |
+
# 请输入【收件人】或【寄件人】\n电话号码后4位
|
121 |
+
return message
|
122 |
+
elif error_code == 14:
|
123 |
+
# 需要验证码
|
124 |
+
message_ = """需要验证码: 请输入此链接中展示的图像中的验证码。\nhttps://trace.fkdex.com/captcha"""
|
125 |
+
return message_
|
126 |
+
|
127 |
+
track_info = ""
|
128 |
+
for row in data:
|
129 |
+
date = row["time"]
|
130 |
+
context = row["context"]
|
131 |
+
row_ = "{}: {}".format(date, context)
|
132 |
+
track_info += row_
|
133 |
+
track_info += "\n"
|
134 |
+
|
135 |
+
result = "快递公司名称: {}\n快递单号: {}\n手机号码后四位: {}\n物流信息如下: \n\n{}".format(
|
136 |
+
exp_text_name, track_id, four_digits, track_info
|
137 |
+
)
|
138 |
+
print(result)
|
139 |
+
return result
|
140 |
+
|
141 |
+
return "物流信息查询失败。"
|
142 |
+
|
143 |
+
|
144 |
+
def kwargs():
|
145 |
+
return ["track_id", "four_digits", "captcha"]
|
146 |
+
|
147 |
+
|
148 |
+
def main():
|
149 |
+
tools = [
|
150 |
+
{
|
151 |
+
"type": "function",
|
152 |
+
"function": {
|
153 |
+
"name": "get_express_delivery_information",
|
154 |
+
"description": "在此根据跟踪号查询物流信息。",
|
155 |
+
"parameters": {
|
156 |
+
"type": "object",
|
157 |
+
"properties": {
|
158 |
+
"track_id": {
|
159 |
+
"type": "string",
|
160 |
+
"description": "物流跟踪号码。",
|
161 |
+
},
|
162 |
+
"four_digits": {
|
163 |
+
"type": "string",
|
164 |
+
"description": "出于对用户隐私的考虑,有些物流商可能会要求你提供收件人或寄件人手机号码后四位。",
|
165 |
+
},
|
166 |
+
"captcha": {
|
167 |
+
"type": "string",
|
168 |
+
"description": "有些物流商的查询可能要求你提供图像验证码。",
|
169 |
+
}
|
170 |
+
},
|
171 |
+
"required": ["track_id"],
|
172 |
+
},
|
173 |
+
},
|
174 |
+
}
|
175 |
+
]
|
176 |
+
tools_ = json.dumps(tools, ensure_ascii=False)
|
177 |
+
print(tools_)
|
178 |
+
print(tools_.replace("\"", "\\\""))
|
179 |
+
|
180 |
+
# track_id = "33212432323"
|
181 |
+
# four_digits = None
|
182 |
+
|
183 |
+
# track_id = "433542074086264"
|
184 |
+
# four_digits = "4154"
|
185 |
+
# four_digits = None
|
186 |
+
|
187 |
+
track_id = "4577035024"
|
188 |
+
four_digits = None
|
189 |
+
captcha = "VWDYW"
|
190 |
+
|
191 |
+
# result = get_operator_by_track_id(track_id)
|
192 |
+
# print(result)
|
193 |
+
result = get_express_delivery_information(track_id, four_digits, captcha)
|
194 |
+
print(result)
|
195 |
+
return
|
196 |
+
|
197 |
+
|
198 |
+
if __name__ == '__main__':
|
199 |
+
main()
|
functions/get_pizza_restaurant_menu.py
CHANGED
@@ -5,6 +5,12 @@ from typing import List
|
|
5 |
|
6 |
|
7 |
def get_pizza_restaurant_menu():
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
result = """
|
9 |
菜单包括:
|
10 |
|
|
|
5 |
|
6 |
|
7 |
def get_pizza_restaurant_menu():
|
8 |
+
"""
|
9 |
+
如果函数的名字叫作 “get_pizza_restaurant_menu” ,
|
10 |
+
那么就需要一个同名 python 脚本 “get_pizza_restaurant_menu.py” ,
|
11 |
+
同时其中应包含一个名为 “get_pizza_restaurant_menu” 的函数。
|
12 |
+
"""
|
13 |
+
|
14 |
result = """
|
15 |
菜单包括:
|
16 |
|
main.py
CHANGED
@@ -23,9 +23,6 @@ logging.basicConfig(
|
|
23 |
import gradio as gr
|
24 |
import openai
|
25 |
from openai import OpenAI
|
26 |
-
from threading import Thread
|
27 |
-
import _queue
|
28 |
-
from queue import Queue
|
29 |
|
30 |
import project_settings as settings
|
31 |
from project_settings import project_path
|
@@ -62,6 +59,7 @@ def dynamic_import_function(package_name: str, function_name: str):
|
|
62 |
|
63 |
function = getattr(lib, function_name)
|
64 |
|
|
|
65 |
return function
|
66 |
|
67 |
|
|
|
23 |
import gradio as gr
|
24 |
import openai
|
25 |
from openai import OpenAI
|
|
|
|
|
|
|
26 |
|
27 |
import project_settings as settings
|
28 |
from project_settings import project_path
|
|
|
59 |
|
60 |
function = getattr(lib, function_name)
|
61 |
|
62 |
+
# del lib
|
63 |
return function
|
64 |
|
65 |
|