Skip to content

Commit 0c8c933

Browse files
authored
fix(query_router): rename query_runner to query_router and fix service configuration (#24)
* query_runner -> query_router * fix query_router service * update docker compose and build action * update docs * dont bake in ENV vars into Dockerfile * fix default port * use default ports in README * update CI * update error message
1 parent d42b01c commit 0c8c933

File tree

11 files changed

+351
-302
lines changed

11 files changed

+351
-302
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ LLM_MODEL=gpt-3.5-turbo
1414
LLM_API_KEY=your-api-key-here
1515
LLM_ENGINE_PORT=8001
1616

17+
# Query Router Configuration
18+
QUERY_ROUTER_PORT=8002
19+
1720
RUST_LOG=debug

.github/workflows/build.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
cache-from: type=gha
4747
cache-to: type=gha,mode=max
4848

49-
build-query-runner:
49+
build-query-router:
5050
runs-on: ubuntu-latest
5151
steps:
5252
- name: Checkout repository
@@ -55,18 +55,18 @@ jobs:
5555
- name: Set up Docker Buildx
5656
uses: docker/setup-buildx-action@v2
5757

58-
- name: Build Query Runner service
58+
- name: Build Query Router service
5959
uses: docker/build-push-action@v4
6060
with:
61-
context: ./query_runner
61+
context: ./query_router
6262
push: false
6363
load: true
64-
tags: lucidata-query-runner:latest
64+
tags: lucidata-query-router:latest
6565
cache-from: type=gha
6666
cache-to: type=gha,mode=max
6767

6868
system-test:
69-
needs: [build-api, build-llm-engine, build-query-runner]
69+
needs: [build-api, build-llm-engine, build-query-router]
7070
runs-on: ubuntu-latest
7171
steps:
7272
- name: Checkout repository
@@ -95,20 +95,20 @@ jobs:
9595
cache-from: type=gha
9696
outputs: type=docker,dest=/tmp/llm-engine-image.tar
9797

98-
- name: Download Query Runner image
98+
- name: Download Query Router image
9999
uses: docker/build-push-action@v4
100100
with:
101-
context: ./query_runner
101+
context: ./query_router
102102
load: true
103-
tags: lucidata-query-runner:latest
103+
tags: lucidata-query-router:latest
104104
cache-from: type=gha
105-
outputs: type=docker,dest=/tmp/query-runner-image.tar
105+
outputs: type=docker,dest=/tmp/query-router-image.tar
106106

107107
- name: Load saved images
108108
run: |
109109
docker load < /tmp/api-image.tar
110110
docker load < /tmp/llm-engine-image.tar
111-
docker load < /tmp/query-runner-image.tar
111+
docker load < /tmp/query-router-image.tar
112112
docker images
113113
114114
- name: Start services with docker compose

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ jobs:
6262
working-directory: ./llm_engine
6363
run: cargo test
6464

65-
query_runner:
66-
name: Query Runner Service
65+
query_router:
66+
name: Query Router Service
6767
runs-on: ubuntu-latest
6868

6969
steps:
@@ -76,9 +76,9 @@ jobs:
7676
override: true
7777

7878
- name: Run cargo check
79-
working-directory: ./query_runner
79+
working-directory: ./query_router
8080
run: cargo check
8181

8282
- name: Run cargo test
83-
working-directory: ./query_runner
83+
working-directory: ./query_router
8484
run: cargo test

README.md

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,62 @@
44

55
Lucidata is an LLM based query tool designed to democratize data access. It translates natural language questions into SQL/API queries over structured datasets, returning clear, traceable answers and exports.
66

7-
## Features (WIP)
7+
## Features
88

99
- Natural Language Interface: Ask questions in plain English
10-
- Query Translation: Automatic conversion to SQL/API queries
11-
- Result Visualization: Clear tables and charts
12-
- Export Options: Download results in various formats (CSV, Excel, etc.)
13-
- Query Transparency: Track and export generated queries
10+
- Query Translation: Automatic conversion to SQL queries
11+
- Query Transparency: Track and export generated queries, explanations, and model confidence
12+
13+
### Road-Map
14+
15+
- Support for Generic WebAPI queries
16+
- Result Visualization
1417

1518
## Getting Started
1619

1720
### Prerequisites
1821

1922
- `docker` installed
20-
- OpenAPI `API_KEY`
23+
- An OpenAPI `API_KEY`
2124

2225
### Usage
2326

2427
1. Clone the repository
2528
```bash
26-
git clone https://github.com/jdhoffa/lucidata.git
29+
gh repo clone jdhoffa/lucidata
2730
cd lucidata
2831
```
2932

30-
2. Start the application with Docker Compose
33+
2. Build and start the application with `docker compose`:
3134
```bash
35+
docker compose build # it can take a while to compile, be patient :-)
3236
docker compose up
3337
```
3438

35-
3. Enter your natural language query in the input field and click "Submit"
39+
3. Send your query to the query_router endpoint, and check out the results!
40+
``` bash
41+
curl -X POST "http://localhost:8002/translate-and-execute" \
42+
-H "Content-Type: application/json" \
43+
-d '{
44+
"natural_query": "Show me the cars with the best power-to-weight ratio, sorted from highest to lowest"
45+
}'
46+
```
3647

37-
4. Review the results and use the export options as needed
48+
4. (Optional) Pipe the output to the `jq` CLI:
49+
``` bash
50+
curl -X POST "http://localhost:8002/translate-and-execute" \
51+
-H "Content-Type: application/json" \
52+
-d '{
53+
"natural_query": "Show me the cars with the best power-to-weight ratio, sorted from highest to lowest"
54+
}' | jq
55+
56+
# you can also select a specific tag
57+
curl -X POST "http://localhost:8002/translate-and-execute" \
58+
-H "Content-Type: application/json" \
59+
-d '{
60+
"natural_query": "Show me the cars with the best power-to-weight ratio, sorted from highest to lowest"
61+
}' | jq '.results'
62+
```
3863

3964
## System Architecture
4065

@@ -77,9 +102,18 @@ graph TD
77102
## Example Queries
78103

79104
```
80-
"What is the projected energy mix in 2030 according to IEA's Net Zero scenario?"
105+
# Query #1 tests mathematical operations (division of hp/wt)
106+
"Show me the cars with the best power-to-weight ratio, sorted from highest to lowest."
107+
108+
# Query #2 tests sorting and multi-column selection
109+
"Compare fuel efficiency (MPG) and horsepower for all cars, sorted by MPG."
110+
111+
# Query #3 tests aggregation functions with grouping
112+
"What's the average horsepower and MPG for automatic vs manual transmission cars?"
81113
82-
"How does natural gas production in the US compare to China over the next decade in WoodMac's base case?"
114+
# Query #4 tests more complex aggregation and grouping
115+
"Show me the relationship between number of cylinders and fuel efficiency with average MPG by cylinder count"
83116
84-
"Show me the top 5 countries by renewable energy growth in the next 5 years."
117+
# Query #5 tests limiting results and specific column selection
118+
"Find the top 5 cars with the highest horsepower and their quarter-mile time (qsec)"
85119
```

api/Dockerfile

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ RUN apt-get update && \
3434
# Copy the binary from the builder stage
3535
COPY --from=builder /app/target/release/lucidata-api /app/lucidata-api
3636

37-
# Create a .env file only if environment variables aren't provided
38-
RUN touch .env && \
39-
echo "DATABASE_URL=\${DATABASE_URL:-postgres://postgres:postgres@db:5432/pbtar}" > .env && \
40-
echo "RUST_LOG=\${RUST_LOG:-info}" >> .env
41-
4237
EXPOSE 8000
4338

4439
CMD ["/app/lucidata-api"]

docker-compose.yml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ services:
3737
db:
3838
condition: service_healthy
3939
healthcheck:
40-
test: ["CMD", "curl", "-f", "http://api:${API_PORT}/api/health"]
40+
test: ["CMD", "curl", "-f", "http://localhost:${API_PORT}/api/health"]
4141
interval: 10s
4242
timeout: 5s
4343
retries: 5
@@ -48,7 +48,7 @@ services:
4848
build:
4949
context: ./llm_engine
5050
ports:
51-
- "8001:8001"
51+
- "${LLM_ENGINE_PORT}:${LLM_ENGINE_PORT}"
5252
dns:
5353
- 8.8.8.8
5454
- 1.1.1.1
@@ -66,26 +66,33 @@ services:
6666
condition: service_healthy
6767
api:
6868
condition: service_healthy
69-
tty: true
70-
stdin_open: true
7169
healthcheck:
72-
test: ["CMD", "curl", "-f", "http://localhost:8001/health"]
70+
test: ["CMD", "curl", "-f", "http://localhost:${LLM_ENGINE_PORT}/health"]
7371
interval: 10s
7472
timeout: 5s
7573
retries: 3
7674
start_period: 5s
7775

78-
query_runner:
76+
query_router:
7977
build:
80-
context: ./query_runner
78+
context: ./query_router
79+
ports:
80+
- "${QUERY_ROUTER_PORT}:${QUERY_ROUTER_PORT}"
8181
env_file:
8282
- ./.env
8383
environment:
8484
DATABASE_URL: ${DATABASE_URL}
8585
API_URL: ${API_URL}
86+
QUERY_ROUTER_PORT: ${QUERY_ROUTER_PORT}
87+
LLM_ENGINE_URL: ${LLM_ENGINE_URL}
88+
RUST_LOG: ${RUST_LOG}
8689
depends_on:
90+
db:
91+
condition: service_healthy
8792
api:
88-
condition: service_started
93+
condition: service_healthy
94+
llm_engine:
95+
condition: service_healthy
8996

9097
volumes:
9198
postgres_data:

llm_engine/Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ RUN apt-get update && \
3535
# Copy the binary from the builder stage
3636
COPY --from=builder /app/target/release/llm_engine /app/llm_engine
3737

38-
# Set environment variables
39-
ENV LLM_ENGINE_PORT=8001
40-
4138
# Expose the port
4239
EXPOSE 8001
4340

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
[package]
2-
name = "query_runner"
2+
name = "query_router"
33
version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
77
tokio = { version = "1.29", features = ["full"] }
8-
axum = "0.6.20"
8+
axum = "0.6"
99
serde = { version = "1.0", features = ["derive"] }
1010
serde_json = "1.0"
1111
tracing = "0.1"
1212
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
13+
tower = "0.4"
1314
tower-http = { version = "0.4", features = ["cors"] }
1415
reqwest = { version = "0.11", features = ["json"] }
1516
dotenvy = "0.15"
@@ -18,3 +19,4 @@ thiserror = "1.0"
1819
tokio-postgres = { version = "0.7", features = ["with-serde_json-1"] }
1920
futures = "0.3"
2021
chrono = { version = "0.4", features = ["serde"] }
22+
dotenv = "0.15"

query_runner/Dockerfile renamed to query_router/Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ RUN apt-get update && \
3232
rm -rf /var/lib/apt/lists/*
3333

3434
# Copy the binary from the builder stage
35-
COPY --from=builder /app/target/release/query_runner /app/query_runner
35+
COPY --from=builder /app/target/release/query_router /app/query_router
36+
37+
EXPOSE 8002
3638

3739
# Command to run the application
38-
CMD ["/app/query_runner"]
40+
CMD ["/app/query_router"]

0 commit comments

Comments
 (0)