add stream_api_test.py
This commit is contained in:
parent
d5fcc958b8
commit
0568e9be47
|
|
@ -0,0 +1,31 @@
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
url = 'http://localhost:7861/chat/chat'
|
||||||
|
headers = {
|
||||||
|
'accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
}
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"query": "请用100字左右的文字介绍自己",
|
||||||
|
"history": [
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": "你好"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "你好,我是 ChatGLM"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stream": True
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(url, headers=headers, data=json.dumps(data), stream=True)
|
||||||
|
if response.status_code == 200:
|
||||||
|
for line in response.iter_content(decode_unicode=True):
|
||||||
|
print(line, flush=True)
|
||||||
|
else:
|
||||||
|
print("Error:", response.status_code)
|
||||||
Loading…
Reference in New Issue