From 0568e9be474723795e3db1d0bc9816693d65471d Mon Sep 17 00:00:00 2001 From: imClumsyPanda Date: Mon, 14 Aug 2023 20:08:37 +0800 Subject: [PATCH] add stream_api_test.py --- tests/api/stream_api_test.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/api/stream_api_test.py diff --git a/tests/api/stream_api_test.py b/tests/api/stream_api_test.py new file mode 100644 index 0000000..06a9654 --- /dev/null +++ b/tests/api/stream_api_test.py @@ -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) \ No newline at end of file