From b55cd15de23ffc3ca4c9084d50c87c843ba7f53f Mon Sep 17 00:00:00 2001 From: Nenad Ilic Date: Sat, 26 Apr 2025 14:24:26 +0200 Subject: [PATCH] Add setup.py for pip installation compatibility and example scripts --- scripts/check_health.py | 39 +++++++++++++++++++++++++++++++++++++++ scripts/run_proxy.py | 22 ++++++++++++++++++++++ setup.py | 4 ++++ 3 files changed, 65 insertions(+) create mode 100755 scripts/check_health.py create mode 100644 scripts/run_proxy.py create mode 100644 setup.py diff --git a/scripts/check_health.py b/scripts/check_health.py new file mode 100755 index 0000000..5e289e0 --- /dev/null +++ b/scripts/check_health.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +import os +import unittest.mock +import requests + +# Mock environment variables to allow proxy to initialize +with unittest.mock.patch.dict(os.environ, { + 'TARGET_API_BASE': 'https://api.example.com', + 'TARGET_API_KEY': 'mock-api-key', + 'BIG_MODEL_TARGET': 'model-large', + 'SMALL_MODEL_TARGET': 'model-small' +}): + # Import claudex with mocked environment + import uvicorn + import claudex.proxy + + if __name__ == "__main__": + # Start server in the background + import threading + import time + + server_thread = threading.Thread( + target=uvicorn.run, + args=("claudex.proxy:app",), + kwargs={"host": "127.0.0.1", "port": 8082, "log_level": "error"}, + daemon=True + ) + server_thread.start() + + # Wait for server to start + time.sleep(2) + + # Check health endpoint + try: + response = requests.get("http://127.0.0.1:8082/") + print(f"Status code: {response.status_code}") + print(f"Response: {response.json()}") + except Exception as e: + print(f"Error: {e}") \ No newline at end of file diff --git a/scripts/run_proxy.py b/scripts/run_proxy.py new file mode 100644 index 0000000..2794640 --- /dev/null +++ b/scripts/run_proxy.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +# Get directory containing this script +script_dir = os.path.dirname(os.path.abspath(__file__)) +# Get project root directory (parent of script directory) +project_dir = os.path.abspath(os.path.join(script_dir, "..")) +# Add project directory to path to ensure module can be found +sys.path.insert(0, project_dir) + +# Set environment variables for testing +os.environ.setdefault("TARGET_API_BASE", "https://api.example.com") +os.environ.setdefault("TARGET_API_KEY", "mock-api-key") +os.environ.setdefault("BIG_MODEL_TARGET", "model-large") +os.environ.setdefault("SMALL_MODEL_TARGET", "model-small") + +# Now import and run +from claudex.main import main + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..57c026b --- /dev/null +++ b/setup.py @@ -0,0 +1,4 @@ +from setuptools import setup + +if __name__ == "__main__": + setup() \ No newline at end of file