diff --git a/.github/workflows/ai-service-ci.yaml b/.github/workflows/ai-service-ci.yaml index f2bf004b4..6a130b539 100644 --- a/.github/workflows/ai-service-ci.yaml +++ b/.github/workflows/ai-service-ci.yaml @@ -29,7 +29,7 @@ jobs: fail-fast: false matrix: python-version: [ "3.12.0" ] - poetry-version: [ "1.7.1" ] + poetry-version: [ "1.8.3" ] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/ai-service-release-stable-image.yaml b/.github/workflows/ai-service-release-stable-image.yaml index 58263ee26..b6d88b02d 100644 --- a/.github/workflows/ai-service-release-stable-image.yaml +++ b/.github/workflows/ai-service-release-stable-image.yaml @@ -36,7 +36,7 @@ jobs: - name: Install Poetry uses: abatilo/actions-poetry@v2 with: - poetry-version: 1.7.1 + poetry-version: 1.8.3 - name: Upgrade AI Service version run: | version=${{ github.event.inputs.version }} diff --git a/wren-ai-service/Makefile b/wren-ai-service/Makefile index 02d79a642..cd9376f05 100644 --- a/wren-ai-service/Makefile +++ b/wren-ai-service/Makefile @@ -49,6 +49,13 @@ stop-all: make stop-wren-engine && \ make stop-redis +ui: + cd ../wren-ui; export DB_TYPE=sqlite export SQLITE_FILE=db.sqlite3 export WREN_AI_ENDPOINT=http://localhost:5556 && \ + yarn install && yarn rollback --all && yarn migrate && yarn dev + +demo: + cd demo; poetry run streamlit run app.py + # present the evaluation result on the streamlit app # example: make streamlit pipeline=ask_details streamlit: diff --git a/wren-ai-service/README.md b/wren-ai-service/README.md index 80778b5c7..4b558a0c5 100644 --- a/wren-ai-service/README.md +++ b/wren-ai-service/README.md @@ -7,7 +7,7 @@ Please read the [documentation](https://docs.getwren.ai/concept/wren_ai_service) ## Environment Setup - Python 3.12.0, recommended to use [`pyenv`](https://github.com/pyenv/pyenv?tab=readme-ov-file#installation) to manage the Python versions -- install `poetry` with version 1.7.1: `curl -sSL https://install.python-poetry.org | python3 - --version 1.7.1` +- install `poetry` with version 1.8.3: `curl -sSL https://install.python-poetry.org | python3 - --version 1.8.3` - execute `poetry install` to install the dependencies - copy `.env.example` file to `.env`, and `.env.dev.example` file to `.env.dev` and fill in the environment variables - [for development] execute `poetry run pre-commit install` to install the pre-commit hooks and `poetry run pre-commit run --all-files` to run the pre-commit checks at the first time to check if everything is set up correctly @@ -15,13 +15,15 @@ Please read the [documentation](https://docs.getwren.ai/concept/wren_ai_service) ## Start the service for development +- execute `make run-all` to start needed containers (e.g. qdrant, wren-engine) +- execute `make ui` to start the ui - execute `make start` to start the service and go to `http://WREN_AI_SERVICE_HOST:WREN_AI_SERVICE_PORT` to see the API documentation and try the APIs ## Production Environment Setup - copy `.env.prod.example` file to `.env.prod` and fill in the environment variables - `make build` to build the docker image -- `make up` to run the docker container +- `make up` to run the wren-ai-service - `make down` to stop the docker container ## Pipeline Evaluation(for development) @@ -56,17 +58,11 @@ Please read the [documentation](https://docs.getwren.ai/concept/wren_ai_service) ## Demo -- prerequisites - - install and run the docker service, and you should stop all WrenAI services first before running the demo - - go to the `../docker` folder and prepare the `.env.local` file - - make sure the node version is v16.19.0 - - if you are using Python 3.12+, please also install `setuptools` in order to successfully install the dependencies of the wren-ui service - - go to the `demo` folder and create a `.env` file and fill in the environment variables if you want to use BigQuery as data source - go to the `demo` folder and run `poetry install` to install the dependencies -- in the `demo` folder, open three terminals - - in the first terminal, run `make prepare` to start the docker containers and `make run` to start the demo service - - in the second terminal, run `make ui` to start the wren-ui service - - in the third terminal, run `make ai` to start the wren-ai service +- in the `wren-ai-service` folder, open three terminals + - in the first terminal, run `make run-all` to start the docker containers and `make ui` to start the wren-ui service + - in the second terminal, run `make start` to start the wren-ai service + - in the third terminal, run `make demo` to start the demo service - ports of the services: - wren-engine: ports should be 8080 - wren-ai-service: port should be 5556 diff --git a/wren-ai-service/demo/Makefile b/wren-ai-service/demo/Makefile deleted file mode 100644 index 1e6376adf..000000000 --- a/wren-ai-service/demo/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -prepare: - cd ../../docker; docker compose --env-file .env.local -f docker-compose-dev.yaml up -d - -stop: - cd ../../docker; docker compose --env-file .env.local -f docker-compose-dev.yaml down - -ui: - cd ../../wren-ui; export DB_TYPE=sqlite export SQLITE_FILE=db.sqlite3 export WREN_AI_ENDPOINT=http://localhost:5556 && \ - yarn install && yarn rollback --all && yarn migrate && yarn dev - -ai: - cd ..; make start - -run: - poetry run streamlit run app.py diff --git a/wren-ai-service/docker/Dockerfile b/wren-ai-service/docker/Dockerfile index 3693e73af..39d98f0bd 100644 --- a/wren-ai-service/docker/Dockerfile +++ b/wren-ai-service/docker/Dockerfile @@ -23,4 +23,4 @@ COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV} COPY src src -ENTRYPOINT python -m src.pre_run && uvicorn src.__main__:app --host 0.0.0.0 --port $WREN_AI_SERVICE_PORT --workers $WORKERS \ No newline at end of file +ENTRYPOINT python -m src.pre_run && uvicorn src.__main__:app --host 0.0.0.0 --port $WREN_AI_SERVICE_PORT --workers $WORKERS --loop uvloop --http httptools \ No newline at end of file diff --git a/wren-ai-service/src/__main__.py b/wren-ai-service/src/__main__.py index 464e1c324..573173245 100644 --- a/wren-ai-service/src/__main__.py +++ b/wren-ai-service/src/__main__.py @@ -6,7 +6,7 @@ import uvicorn from fastapi import FastAPI from fastapi.exceptions import RequestValidationError from fastapi.middleware.cors import CORSMiddleware -from fastapi.responses import JSONResponse, RedirectResponse +from fastapi.responses import ORJSONResponse, RedirectResponse import src.globals as container from src.utils import load_env_vars, setup_custom_logger @@ -32,7 +32,7 @@ async def lifespan(app: FastAPI): # shutdown events -app = FastAPI(lifespan=lifespan, redoc_url=None) +app = FastAPI(lifespan=lifespan, redoc_url=None, default_response_class=ORJSONResponse) app.add_middleware( CORSMiddleware, @@ -50,7 +50,7 @@ if env == "dev": @app.exception_handler(Exception) async def exception_handler(request, exc: Exception): - return JSONResponse( + return ORJSONResponse( status_code=500, content={"detail": str(exc)}, ) @@ -58,7 +58,7 @@ async def exception_handler(request, exc: Exception): @app.exception_handler(RequestValidationError) async def request_exception_handler(request, exc: Exception): - return JSONResponse( + return ORJSONResponse( status_code=400, content={"detail": str(exc)}, ) @@ -92,4 +92,6 @@ if __name__ == "__main__": reload=should_reload, reload_dirs=["src"] if should_reload else None, workers=num_workers, + loop="uvloop", + http="httptools", )