import requests import json url = "http://127.0.0.1:8000/chat" payload = { "model": "your-model-name", "message": "Create a json object of top 10 anime! answer in json only!", "messages": [] } headers = { "Content-Type": "application/json" } # Send streaming POST request with requests.post(url, data=json.dumps(payload), headers=headers, stream=True) as response: if response.status_code == 200: for line in response.iter_lines(decode_unicode=True): if line and line.startswith('data: '): try: # Remove 'data: ' prefix and parse JSON json_data = json.loads(line[6:]) # Extract text from choices if available if json_data.get('choices') and len(json_data['choices']) > 0: text = json_data['choices'][0].get('text', '') if text: print(text, end='') except json.JSONDecodeError: continue else: print("Error:", response.status_code, response.text)