Spaces:
Runtime error
Runtime error
Commit
·
2a93774
1
Parent(s):
f6379c4
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,10 +7,11 @@ def call_chatbot_api(query):
|
|
| 7 |
# url = 'https://newaichatapi.onrender.com/api/chat' #Failed: JSONDecodeError: Expecting value: line 1 column 1 (char 0)
|
| 8 |
#data = {'query': query}
|
| 9 |
#在API设置中,将#user_query = data['query']中的query修改为user_question,因此在此处的API调用代码中,需要相应的使用data = {'user_question': query}
|
| 10 |
-
|
| 11 |
#data sample示例: {'query': 'Hello'},这个就是json格式,然后,这个data将作为json传递给API(在API设置的data = request.get_json()中被提取并赋值给data)
|
| 12 |
#这个API调用程序代码,首先是为API准备数据,并且是json格式的
|
| 13 |
-
response = requests.post(url, json=
|
|
|
|
| 14 |
result = response.json()
|
| 15 |
return result['response']
|
| 16 |
|
|
|
|
| 7 |
# url = 'https://newaichatapi.onrender.com/api/chat' #Failed: JSONDecodeError: Expecting value: line 1 column 1 (char 0)
|
| 8 |
#data = {'query': query}
|
| 9 |
#在API设置中,将#user_query = data['query']中的query修改为user_question,因此在此处的API调用代码中,需要相应的使用data = {'user_question': query}
|
| 10 |
+
json_data_for_api = {'user_question': query}
|
| 11 |
#data sample示例: {'query': 'Hello'},这个就是json格式,然后,这个data将作为json传递给API(在API设置的data = request.get_json()中被提取并赋值给data)
|
| 12 |
#这个API调用程序代码,首先是为API准备数据,并且是json格式的
|
| 13 |
+
response = requests.post(url, json=json_data_for_api) #json=...这里的json是内置词,不得修改
|
| 14 |
+
#上面这行代码的意思就是,使用post方式调用API,API的路径是url,输入给API的json数据由json_data_for_api赋值(然后在API端,json中的键值会被user_query = data['user_question']提取出来)
|
| 15 |
result = response.json()
|
| 16 |
return result['response']
|
| 17 |
|