|
import json |
|
|
|
import requests |
|
|
|
|
|
url = "http://localhost:8002/solve" |
|
headers = {"Content-Type": "application/json"} |
|
|
|
|
|
|
|
def get_response(query): |
|
|
|
data = {"inputs": query} |
|
|
|
|
|
response = requests.post(url, headers=headers, data=json.dumps(data), timeout=20, stream=True) |
|
|
|
|
|
for chunk in response.iter_lines(chunk_size=8192, decode_unicode=False, delimiter=b"\n"): |
|
if chunk: |
|
decoded = chunk.decode("utf-8") |
|
if decoded == "\r": |
|
continue |
|
if decoded[:6] == "data: ": |
|
decoded = decoded[6:] |
|
elif decoded.startswith(": ping - "): |
|
continue |
|
response_data = json.loads(decoded) |
|
agent_return = response_data["response"] |
|
node_name = response_data["current_node"] |
|
print(f"Node: {node_name}, Response: {agent_return['response']}") |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
query = "What is the weather like today in New York?" |
|
get_response(query) |
|
|