utils
This commit is contained in:
48
utils/send_query.py
Normal file
48
utils/send_query.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
# /// script
|
||||||
|
# requires-python = ">=3.11"
|
||||||
|
# dependencies = ["httpx", "rich"]
|
||||||
|
# ///
|
||||||
|
"""Send a message to the local RAG agent server.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
uv run utils/send_query.py "Hola, ¿cómo estás?"
|
||||||
|
uv run utils/send_query.py --phone 5551234 "¿Qué servicios ofrecen?"
|
||||||
|
uv run utils/send_query.py --base-url http://localhost:8080 "Hola"
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
import httpx
|
||||||
|
from rich import print as rprint
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
parser = argparse.ArgumentParser(description="Send a query to the RAG agent")
|
||||||
|
parser.add_argument("text", help="Message to send")
|
||||||
|
parser.add_argument("--phone", default="test-user", help="Phone number / session id")
|
||||||
|
parser.add_argument("--base-url", default="http://localhost:8000", help="Server base URL")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"phone_number": args.phone,
|
||||||
|
"text": args.text,
|
||||||
|
"type": "conversation",
|
||||||
|
"language_code": "es",
|
||||||
|
}
|
||||||
|
|
||||||
|
url = f"{args.base_url}/api/v1/query"
|
||||||
|
rprint(f"[bold]POST[/bold] {url}")
|
||||||
|
rprint(f"[dim]{payload}[/dim]\n")
|
||||||
|
|
||||||
|
resp = httpx.post(url, json=payload, timeout=120)
|
||||||
|
resp.raise_for_status()
|
||||||
|
data = resp.json()
|
||||||
|
|
||||||
|
rprint(f"[green bold]Response ([/green bold]{data['response_id']}[green bold]):[/green bold]")
|
||||||
|
rprint(data["response_text"])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user