-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate the ai service to the new repo
- Loading branch information
Showing
56 changed files
with
3,328 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a single version of Python | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | ||
|
||
name: AI Service CI | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
ci: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: [ "3.12" ] | ||
poetry-version: [ "1.7.1" ] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python 3.12 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Run image | ||
uses: abatilo/actions-poetry@v2 | ||
with: | ||
poetry-version: ${{ matrix.poetry-version }} | ||
- name: Install the project dependencies | ||
run: poetry install | ||
- name: Run Qdrant | ||
run: docker run -p 6333:6333 -p 6334:6334 -d --name qdrant qdrant/qdrant:v1.7.4 | ||
- name: Test with pytest | ||
run: poetry run pytest -s | ||
env: | ||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | ||
ENV: dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# vectorstore | ||
vectorstore | ||
retrieve_db/ | ||
wren-ai-service/qdrant_storage/ | ||
|
||
# app | ||
.env | ||
.env.* | ||
!.env.*.example | ||
!src/eval/vulcansql-core-server/.env | ||
src/eval/vulcansql-core-server/config.properties | ||
outputs/ | ||
spider/ | ||
data/ | ||
!tests/data | ||
!src/eval/data | ||
poetry.lock | ||
assertion.log | ||
|
||
# cache | ||
__pycache__ | ||
local_cache | ||
.ruff_cache | ||
.pytest_cache | ||
|
||
# ide | ||
.idea | ||
.vscode/ | ||
|
||
# os | ||
.DS_Store | ||
__MACOSX/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
* | ||
src/eval | ||
!src | ||
!pyproject.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# fastapi related | ||
UVICORN_HOST=127.0.0.1 | ||
UVICORN_PORT=8080 | ||
|
||
# app related | ||
OPENAI_API_KEY= | ||
LANGFUSE_PUBLIC_KEY= | ||
LANGFUSE_SECRET_KEY= | ||
ENABLE_TRACE= | ||
|
||
# evaluation related | ||
DATASET_NAME=book_2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# docker related | ||
# This will determine the prefix of container name. | ||
# If the service name in docker-compose.yaml is copilot, | ||
# then the container name will be vulcansql-copilot-1. | ||
# If COMPOSE_PROJECT_NAME is not set, the default prefix name is docker. | ||
COMPOSE_PROJECT_NAME=vulcansql | ||
|
||
# fastapi related | ||
UVICORN_PORT=8080 | ||
|
||
# app related | ||
OPENAI_API_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
repos: | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
# Ruff version. | ||
rev: v0.2.2 | ||
hooks: | ||
# Run the linter. | ||
- id: ruff | ||
args: [ --fix ] | ||
# Run the formatter. | ||
- id: ruff-format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
args ?= | ||
|
||
start: | ||
poetry run python -m src.__main__ | ||
|
||
build: | ||
docker compose -f docker/docker-compose.yml build | ||
|
||
up: | ||
docker compose -f docker/docker-compose.yml --env-file .env.prod up -d | ||
|
||
down: | ||
docker compose -f docker/docker-compose.yml --env-file .env.prod down | ||
|
||
run-qdrant: | ||
docker run \ | ||
-p 6333:6333 \ | ||
-p 6334:6334 \ | ||
-d \ | ||
--name qdrant \ | ||
qdrant/qdrant:v1.7.4 | ||
|
||
stop-qdrant: | ||
docker stop qdrant && docker rm qdrant | ||
|
||
# evaluation related | ||
eval: | ||
poetry run python -m src.eval.ask $(args) | ||
|
||
run-vulcansql-core-server: | ||
docker compose -f ./src/eval/vulcansql-core-server/docker-compose.yml --env-file .env.dev --env-file ./src/eval/vulcansql-core-server/.env up -d | ||
|
||
stop-vulcansql-core-server: | ||
docker compose -f ./src/eval/vulcansql-core-server/docker-compose.yml --env-file .env.dev --env-file ./src/eval/vulcansql-core-server/.env down | ||
|
||
psql: | ||
docker exec -it vulcansql-engine-1 bash launch-cli.sh | ||
|
||
run-all: | ||
make run-qdrant && \ | ||
make run-vulcansql-core-server | ||
|
||
stop-all: | ||
make stop-qdrant && \ | ||
make stop-vulcansql-core-server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
## Introduction | ||
|
||
## Environment Setup | ||
|
||
- Python 3.12 or later | ||
- follow the instructions at https://pipx.pypa.io/stable/ install `pipx` | ||
- execute `pipx install poetry` to install `poetry` | ||
- 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 | ||
|
||
## Start the service for development | ||
|
||
- execute `make start` to start the service | ||
- go to `http://UVICORN_HOST:UVICORN_PORT/docs` to see the API documentation and try the API | ||
|
||
## 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 down` to stop the docker container | ||
|
||
## Pipeline Evaluation(for development) | ||
|
||
- fill in environment variables: `.env.dev` in the src folder and `config.properties` in the src/eval/vulcansql-core-server folder | ||
- start docker | ||
- run qdrant and vulcansql-core-server docker containers: `make run-all` | ||
- evaluation: `make eval` and check out the outputs folder | ||
- to run individual pipeline: `poetry run python -m src.pipelines.ask.[pipeline_name]` (e.g. `poetry run python -m src.pipelines.ask.retrieval_pipeline`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM python:3.12.2-bookworm | ||
|
||
RUN pip install poetry==1.7.1 | ||
|
||
WORKDIR /app | ||
|
||
COPY pyproject.toml poetry.lock ./ | ||
|
||
RUN poetry install --without dev | ||
|
||
COPY src/ src/ | ||
|
||
ENTRYPOINT [ "poetry", "run", "uvicorn", "src.__main__:app", "--host", "0.0.0.0", "--port", "80" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
version: '3.8' | ||
|
||
services: | ||
copilot: | ||
image: vulcansql-copilot:latest | ||
build: | ||
context: .. | ||
dockerfile: docker/Dockerfile | ||
environment: | ||
UVICORN_PORT: ${UVICORN_PORT} | ||
OPENAI_API_KEY: ${OPENAI_API_KEY} | ||
# sometimes the console won't show print messages, | ||
# using PYTHONUNBUFFERED: 1 can fix this | ||
PYTHONUNBUFFERED: 1 | ||
ports: | ||
- ${UVICORN_PORT}:80 | ||
depends_on: | ||
- qdrant | ||
|
||
qdrant: | ||
image: qdrant/qdrant:v1.7.4 | ||
ports: | ||
- 6333:6333 | ||
- 6334:6334 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[tool.poetry] | ||
name = "wren-ai-service" | ||
version = "0.1.0" | ||
description = "" | ||
authors = ["Jimmy Yeh <[email protected]>", "Pao Sheng Wang <[email protected]>"] | ||
readme = "README.md" | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.12" | ||
fastapi = "^0.109.2" | ||
uvicorn = "^0.27.1" | ||
python-dotenv = "^1.0.1" | ||
setuptools = "^69.1.0" | ||
haystack-ai = "^2.0.0" | ||
openai = "^1.12.0" | ||
langfuse = "^2.19.1" | ||
ragas = "^0.1.1" | ||
qdrant-haystack = "^3.0.0" | ||
backoff = "^2.2.1" | ||
ragas-haystack = "^0.1.1" | ||
tqdm = "^4.66.2" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
pytest = "^8.0.0" | ||
pre-commit = "^3.6.1" | ||
pytest-cov = "^4.1.0" | ||
gdown = "^5.1.0" | ||
sqlglot = "^22.1.0" | ||
httpx = "^0.27.0" | ||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Exclude a variety of commonly ignored directories. | ||
exclude = [ | ||
".bzr", | ||
".direnv", | ||
".eggs", | ||
".git", | ||
".git-rewrite", | ||
".hg", | ||
".ipynb_checkpoints", | ||
".mypy_cache", | ||
".nox", | ||
".pants.d", | ||
".pyenv", | ||
".pytest_cache", | ||
".pytype", | ||
".ruff_cache", | ||
".svn", | ||
".tox", | ||
".venv", | ||
".vscode", | ||
"__pypackages__", | ||
"_build", | ||
"buck-out", | ||
"build", | ||
"dist", | ||
"node_modules", | ||
"site-packages", | ||
"venv", | ||
] | ||
|
||
# Same as Black. | ||
line-length = 88 | ||
indent-width = 4 | ||
|
||
# Assume Python 3.8 | ||
target-version = "py38" | ||
|
||
[lint] | ||
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. | ||
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or | ||
# McCabe complexity (`C901`) by default. | ||
select = ["E4", "E7", "E9", "F", "I001"] | ||
ignore = [] | ||
|
||
# Allow fix for all enabled rules (when `--fix`) is provided. | ||
fixable = ["ALL"] | ||
unfixable = [] | ||
|
||
# Allow unused variables when underscore-prefixed. | ||
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" | ||
|
||
[format] | ||
# Like Black, use double quotes for strings. | ||
quote-style = "double" | ||
|
||
# Like Black, indent with spaces, rather than tabs. | ||
indent-style = "space" | ||
|
||
# Like Black, respect magic trailing commas. | ||
skip-magic-trailing-comma = false | ||
|
||
# Like Black, automatically detect the appropriate line ending. | ||
line-ending = "auto" | ||
|
||
# Enable auto-formatting of code examples in docstrings. Markdown, | ||
# reStructuredText code/literal blocks and doctests are all supported. | ||
# | ||
# This is currently disabled by default, but it is planned for this | ||
# to be opt-out in the future. | ||
docstring-code-format = false | ||
|
||
# Set the line length limit used when formatting code snippets in | ||
# docstrings. | ||
# | ||
# This only has an effect when the `docstring-code-format` setting is | ||
# enabled. | ||
docstring-code-line-length = "dynamic" |
Empty file.
Oops, something went wrong.