AI_Chatbot / ask_question.py
Hamza-Naimat's picture
Integrated Unified Digital FTE Features: Enhanced Playwright crawler for Shopify/e-commerce, upgraded UI with SSE streaming & Rich Cards, added CSAT surveys, and corrected agentfactory crawl parameters.
b2d2574
Raw
History Blame Contribute Delete
951 Bytes
import httpx
import json
url = "http://localhost:8000/chat"
question = "Summarize the 'Turing LLMOps Proprietary Intelligence' curriculum, focusing on the 'data engineering fine-tuning' section. Provide this summary in Spanish."
payload = {"question": question, "stream": False}
headers = {"Content-Type": "application/json"}
try:
response = httpx.post(url, json=payload, headers=headers, timeout=60)
response.raise_for_status()
answer = response.json().get("answer", "No answer received.")
print("Question:", question)
print("Answer:", answer)
except httpx.RequestError as e:
print(f"An error occurred while requesting {e.request.url!r}: {e}")
except httpx.HTTPStatusError as e:
print(f"Error response {e.response.status_code} while requesting {e.request.url!r}.")
except json.JSONDecodeError:
print("Error: Could not decode JSON response.")
except Exception as e:
print(f"An unexpected error occurred: {e}")