Spaces:
Sleeping
Sleeping
File size: 925 Bytes
43acfaf 0d78f52 43acfaf 0d78f52 43acfaf 0d78f52 43acfaf 0d78f52 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import chainlit as cl
import requests
import os
from dotenv import load_dotenv
load_dotenv()
@cl.on_message
async def main(message: cl.Message):
response = call_backend(message.content)
await cl.Message(
content = response
).send()
def call_backend(user_message):
try:
url = os.environ.get("RAG_MODEL")
headers = {"Content-Type": "application/json"}
data = {"query": user_message}
response = requests.post(url, json=data, headers=headers, timeout=(5, 50))
response.raise_for_status()
backend_response = response.json()
print(backend_response)
return backend_response['respuesta']
except requests.exceptions.RequestException as e:
print(f"Error al llamar al backend: {e}")
return {"error": str(e)}
except requests.exceptions.Timeout as e:
print(f"Error de timeout: {e}")
return {"error": str(e)} |