import requests
url = "https://backend.chatfly.co/api/chat/get-streaming-response-with-chat-history"
headers = {
'Content-Type': 'application/json',
}
data = {
"bot_id": "xxxx-xxxx-xxxx-xxxx",
"message": "string",
"chat_history": [
{"sender_type": "user", "content":"What is ChatFly?"},
{"sender_type": "agent", "content":"ChatFly is an AI chatbot builder"},
],
}
response = requests.post(url, headers=headers, json=data, stream=True)
if response.status_code == 200:
print("Request successful!")
# Process the streaming response as needed
for chunk in response.iter_content(chunk_size=1024):
if chunk:
# Process each chunk of the streaming response
print(chunk.decode('utf-8'), end="", flush=True)
else:
print("Request failed with status code:", response.status_code)
print(response.text)