Skip to content

Instantly share code, notes, and snippets.

@CashWilliams
Created January 2, 2026 00:33
Show Gist options
  • Select an option

  • Save CashWilliams/ab35728e824c68fa1a9acb7425c1cf83 to your computer and use it in GitHub Desktop.

Select an option

Save CashWilliams/ab35728e824c68fa1a9acb7425c1cf83 to your computer and use it in GitHub Desktop.
from __future__ import annotations
import argparse
import sys
from typing import Any
import httpx
def send_prompt(base_url: str, prompt: str, user_context: str | None = None) -> dict[str, Any]:
payload: dict[str, Any] = {"prompt": prompt, "conversation_id": 'local_cli'}
if user_context:
payload["user_context"] = user_context
response = httpx.post(f"{base_url.rstrip('/')}/prompt", json=payload, timeout=60)
response.raise_for_status()
return response.json()
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Send a prompt to the Cortana server")
parser.add_argument("prompt", help="Prompt text to send")
parser.add_argument(
"--base-url",
help="Server base URL",
default="http://localhost:8000",
)
parser.add_argument(
"--user-context",
help="Additional context to send with the prompt",
)
return parser.parse_args()
def main() -> None:
args = parse_args()
try:
data = send_prompt(args.base_url, args.prompt, user_context=args.user_context)
except httpx.HTTPStatusError as exc:
print(f"Server returned error {exc.response.status_code}: {exc.response.text}", file=sys.stderr)
raise SystemExit(1) from exc
except httpx.HTTPError as exc:
print(f"Failed to reach server: {exc}", file=sys.stderr)
raise SystemExit(1) from exc
print(data.get('response'))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment