Skip to content

Commit

Permalink
feature(ai-service): wren-ui dry-run SQL API instead of wren-engine A…
Browse files Browse the repository at this point in the history
…PI (#400)

* feat(ai-service): change dryrun api

* feat: change the docker env
  • Loading branch information
paopa authored Jun 12, 2024
1 parent a362757 commit b86cd6f
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docker/docker-compose-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ services:
OPENAI_API_KEY: ${OPENAI_API_KEY}
OPENAI_GENERATION_MODEL: ${OPENAI_GENERATION_MODEL}
QDRANT_HOST: qdrant
WREN_ENGINE_ENDPOINT: http://wren-engine:${WREN_ENGINE_PORT}
WREN_UI_ENDPOINT: http://wren-ui:${WREN_UI_PORT}
REDIS_HOST: ${AI_SERVICE_REDIS_HOST}
REDIS_PORT: ${AI_SERVICE_REDIS_PORT}
ENABLE_TIMER: ${AI_SERVICE_ENABLE_TIMER}
Expand Down
4 changes: 2 additions & 2 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ services:
platform: ${PLATFORM}
expose:
- ${WREN_AI_SERVICE_PORT}
ports:
ports:
- ${AI_SERVICE_FORWARD_PORT}:${WREN_AI_SERVICE_PORT}
environment:
WREN_AI_SERVICE_PORT: ${WREN_AI_SERVICE_PORT}
OPENAI_API_KEY: ${OPENAI_API_KEY}
OPENAI_API_BASE: ${OPENAI_API_BASE}
OPENAI_GENERATION_MODEL: ${OPENAI_GENERATION_MODEL}
QDRANT_HOST: qdrant
WREN_ENGINE_ENDPOINT: http://wren-engine:${WREN_ENGINE_PORT}
WREN_UI_ENDPOINT: http://wren-ui:${WREN_UI_PORT}
REDIS_HOST: ${AI_SERVICE_REDIS_HOST}
REDIS_PORT: ${AI_SERVICE_REDIS_PORT}
ENABLE_TIMER: ${AI_SERVICE_ENABLE_TIMER}
Expand Down
3 changes: 2 additions & 1 deletion wren-ai-service/.env.dev.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ AZURE_EMBED_VERSION=
QDRANT_HOST=localhost

WREN_ENGINE_ENDPOINT=http://localhost:8080
WREN_UI_ENDPOINT=

# evaluation related
DATASET_NAME=book_2
Expand All @@ -36,4 +37,4 @@ REDIS_HOST=localhost
REDIS_PORT=6379
ENABLE_TIMER=
LOGGING_LEVEL=INFO
WORKERS=1
WORKERS=1
3 changes: 2 additions & 1 deletion wren-ai-service/.env.prod.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ AZURE_EMBED_VERSION=
QDRANT_HOST=qdrant

WREN_ENGINE_ENDPOINT=http://wren-engine:8080
WREN_UI_ENDPOINT=

REDIS_HOST=redis
REDIS_PORT=6379
ENABLE_TIMER=
LOGGING_LEVEL=INFO
WORKERS=1
WORKERS=1
2 changes: 1 addition & 1 deletion wren-ai-service/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
OPENAI_API_BASE: ${OPENAI_API_BASE}
OPENAI_GENERATION_MODEL: ${OPENAI_GENERATION_MODEL}
QDRANT_HOST: ${QDRANT_HOST}
WREN_ENGINE_ENDPOINT: ${WREN_ENGINE_ENDPOINT}
WREN_UI_ENDPOINT: ${WREN_UI_ENDPOINT}
REDIS_HOST: ${REDIS_HOST}
REDIS_PORT: ${REDIS_PORT}
ENABLE_TIMER: ${ENABLE_TIMER}
Expand Down
14 changes: 10 additions & 4 deletions wren-ai-service/src/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ async def dry_run_sql(
session: aiohttp.ClientSession,
endpoint: str,
) -> Dict[str, str]:
async with session.get(
f"{endpoint}/v1/mdl/dry-run",
async with session.post(
f"{endpoint}/api/graphql",
json={
"sql": _remove_limit_statement(add_quotes(sql)),
"limit": 1,
"query": "mutation PreviewSql($data: PreviewSQLDataInput) { previewSql(data: $data) }",
"variables": {
"data": {
"dryRun": True,
"limit": 1,
"sql": _remove_limit_statement(add_quotes(sql)),
}
},
},
) as response:
return {"status": response.status, "body": await response.json()}
Expand Down
2 changes: 1 addition & 1 deletion wren-ai-service/src/eval/ask/eval_sampledata.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

def get_mdl_from_wren_engine():
response = requests.get(
f'{os.getenv("WREN_ENGINE_ENDPOINT")}/v1/mdl',
f'{os.getenv("WREN_UI_ENDPOINT")}/v1/mdl',
)
assert response.status_code == 200

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async def _task(result: Dict[str, str]):
quoted_sql = add_quotes(result["sql"])

response = await dry_run_sql(
quoted_sql, session, endpoint=os.getenv("WREN_ENGINE_ENDPOINT")
quoted_sql, session, endpoint=os.getenv("WREN_UI_ENDPOINT")
)

if response.get("status") == 200:
Expand Down
2 changes: 1 addition & 1 deletion wren-ai-service/src/pipelines/ask_details/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async def _check_if_sql_executable(
):
async with aiohttp.ClientSession() as session:
response = await dry_run_sql(
sql, session, endpoint=os.getenv("WREN_ENGINE_ENDPOINT")
sql, session, endpoint=os.getenv("WREN_UI_ENDPOINT")
)

if response.get("status") != 200:
Expand Down

0 comments on commit b86cd6f

Please sign in to comment.