diff --git a/docker-compose.local.yml b/docker-compose.local.yml index f957782..7fedffa 100644 --- a/docker-compose.local.yml +++ b/docker-compose.local.yml @@ -10,8 +10,7 @@ services: - DEV_MODE=true networks: - invariant-explorer-web - ports: - - "8002:8000" + ports: [] labels: - "traefik.enable=true" - "traefik.http.routers.explorer-proxy-api.rule=(Host(`localhost`) && PathPrefix(`/api/v1/proxy/`)) || (Host(`127.0.0.1`) && PathPrefix(`/api/v1/proxy/`))" diff --git a/proxy/Dockerfile.proxy b/proxy/Dockerfile.proxy index 906df0e..0cc24c6 100644 --- a/proxy/Dockerfile.proxy +++ b/proxy/Dockerfile.proxy @@ -6,4 +6,7 @@ WORKDIR /srv/proxy RUN pip install --no-cache-dir -r requirements.txt COPY . /srv/proxy +# Ensure run.sh is executable +RUN chmod +x /srv/proxy/run.sh + ENTRYPOINT ./run.sh \ No newline at end of file diff --git a/proxy/llm_providers/__init__.py b/proxy/llm_providers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/proxy/llm_providers/llm_provider.py b/proxy/llm_providers/llm_provider.py new file mode 100644 index 0000000..e69de29 diff --git a/proxy/llm_providers/open_ai.py b/proxy/llm_providers/open_ai.py new file mode 100644 index 0000000..e69de29 diff --git a/proxy/requirements.txt b/proxy/requirements.txt index f0615cf..3094bf0 100644 --- a/proxy/requirements.txt +++ b/proxy/requirements.txt @@ -1,2 +1,2 @@ -fastapi -uvicorn \ No newline at end of file +fastapi==0.115.7 +uvicorn==0.34.0 \ No newline at end of file diff --git a/proxy/routes/__init__.py b/proxy/routes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/proxy/proxy.py b/proxy/routes/proxy.py similarity index 73% rename from proxy/proxy.py rename to proxy/routes/proxy.py index 0ba465b..1af476f 100644 --- a/proxy/proxy.py +++ b/proxy/routes/proxy.py @@ -1,11 +1,11 @@ """Proxy service to forward requests to the appropriate language model provider""" -from fastapi import FastAPI +from fastapi import APIRouter -proxy = FastAPI() +proxy = APIRouter() -@proxy.post("/u/{username}/{dataset_name}/{llm_provider}") +@proxy.post("/{username}/{dataset_name}/{llm_provider}") async def chat_completion(username: str, dataset_name: str, llm_provider: str): """Proxy call to a language model provider""" return {"message": f"Upload {dataset_name} for {username} to {llm_provider}"} diff --git a/proxy/run.sh b/proxy/run.sh index bd58041..583ef78 100755 --- a/proxy/run.sh +++ b/proxy/run.sh @@ -1,8 +1,8 @@ -#/bin/bash +#!/bin/bash # if DEV_MODE is true, then run the app with auto-reload if [ "$DEV_MODE" = "true" ]; then - uvicorn serve:proxy_app --host 0.0.0.0 --port 8000 --reload + uvicorn serve:app --host 0.0.0.0 --port 8000 --reload else - uvicorn serve:proxy_app --host 0.0.0.0 --port 8000 + uvicorn serve:app --host 0.0.0.0 --port 8000 fi diff --git a/proxy/serve.py b/proxy/serve.py index 3ed090e..11e5aa2 100644 --- a/proxy/serve.py +++ b/proxy/serve.py @@ -2,17 +2,16 @@ import fastapi import uvicorn -from proxy import proxy +from routes.proxy import proxy -v1 = fastapi.FastAPI() +app = fastapi.FastAPI() -# install the API routes -v1.mount("/proxy", proxy) +router = fastapi.APIRouter(prefix="/api/v1") -# mount the API under /api/v1 -proxy_app = fastapi.FastAPI() -proxy_app.mount("/api/v1", v1) +router.include_router(proxy, prefix="/proxy", tags=["proxy"]) -# serve the API +app.include_router(router) + +# Serve the API if __name__ == "__main__": - uvicorn.run(proxy_app, host="0.0.0.0", port=8000) + uvicorn.run(app, host="0.0.0.0", port=8000)