|
|
import requests |
|
|
import json |
|
|
|
|
|
headers = { |
|
|
"Content-Type": "application/json" |
|
|
} |
|
|
|
|
|
data = {'model': 'gpt-3.5-turbo', 'messages': [{'role': 'user', 'content': '你好'}],'stream':True} |
|
|
|
|
|
|
|
|
|
|
|
response = requests.post('https://api.zhtec.xyz/xht/chatWith16k.php', headers=headers, data=json.dumps(data), stream=True) |
|
|
|
|
|
|
|
|
for chunk in response.iter_lines(): |
|
|
if chunk: |
|
|
decoded_chunk = chunk.decode('utf-8') |
|
|
if decoded_chunk.startswith('data:'): |
|
|
|
|
|
try: |
|
|
parsed_chunk = json.loads(decoded_chunk[5:]) |
|
|
print(parsed_chunk['choices'][0]['delta']['content'], end='') |
|
|
except: |
|
|
pass |