Skip to content

Commit 03cdf48

Browse files
committed
REST API and refactoring
1 parent 1ef2db3 commit 03cdf48

17 files changed

+1062
-1082
lines changed

.env.template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ POSTGRES_PASSWORD=postgres
55
POSTGRES_DB=postgres
66
REDIS_URL=redis://redis:6379
77
OLLAMA_URL=http://host.docker.internal:11434
8-
OLLAMA_MODEL=llama3
8+
OLLAMA_MODEL=llama3
9+
API_PORT=3000

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
node-version: 20
2121

2222
- name: Install dependencies
23-
run: npm ci
23+
run: npm ci --legacy-peer-deps
2424

2525
- name: Compile TypeScript
2626
run: npx tsc --noEmit

Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
FROM node:20
1+
FROM node:24
22

33
WORKDIR /app
44

55
COPY package*.json ./
66

7-
RUN npm install
7+
RUN npm install --legacy-peer-deps
88

99
COPY . .
1010

1111
RUN npm run build
1212

13-
ENTRYPOINT ["npm", "run", "start"]
13+
EXPOSE 3000
14+
15+
CMD ["npm", "run", "start:api"]

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Test](https://github.com/Kaltsoon/rag-my-docs/actions/workflows/test.yml/badge.svg)](https://github.com/Kaltsoon/rag-my-docs/actions/workflows/test.yml)
44

5-
A CLI application for building a [RAG](https://blogs.nvidia.com/blog/what-is-retrieval-augmented-generation/) for GitHub repository's markdown files and using it as a context for an LLM to ask questions related to the repository's documentation.
5+
A REST API and CLI application for building a [RAG](https://blogs.nvidia.com/blog/what-is-retrieval-augmented-generation/) for GitHub repository's markdown files and using it as a context for an LLM to ask questions related to the repository's documentation.
66

77
The client code is implemented using TypeScript. PostgreSQL with [pgvector](https://github.com/pgvector/pgvector) is used as a vector database. Redis is used for caching purposes.
88

@@ -14,5 +14,29 @@ Docker and [Ollama](https://ollama.com/).
1414

1515
1. Setup [Ollama](https://ollama.com/) and pull the `llama3:8b` model by running `ollama pull llama3:8b`. You can use other Ollama models as well, see next step for configuration instructions.
1616
2. Create a `.env` and with the contents of the `.env.template` file. Feel free to change the environment variables, e.g. `OLLAMA_MODEL` variable to change the model.
17-
2. Run the containers by running `docker compose up -d pg redis`.
18-
3. Once the containers are ready, run the CLI application by running `docker compose run -it --rm cli` and follow the instructions provided by the application.
17+
3. Run the containers by running `docker compose up -d`
18+
4. Once the containers are ready, there's two ways to access the LLM: `http://localhost:3000/api/repos/{owner}/{repo}/prompt` REST API endpoint and the CLI application. Details for both are below.
19+
20+
> [!WARNING]
21+
> GitHub's API [limits the requests for unauthenticated users](https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28). Provide a GitHub authentication token as instructed below to increate your rate limit.
22+
23+
### REST API
24+
25+
REST API endpoint `http://localhost:3000/api/repos/{owner}/{repo}/prompt` (e.g. <http://localhost:3000/api/repos/Kaltsoon/rag-my-docs>) accepts a request body in the following format:
26+
27+
```json
28+
{
29+
"question": "What is the purpose of the repository?",
30+
"ref": "dev",
31+
"auth": "supersecret"
32+
}
33+
```
34+
35+
The `ref` and `auth` attributes are optional. The `ref` attribute determines name of the commit/branch/tag. Defaults to repository's default branch. The `auth` attribute determines the GitHub authentication token used for requests to GitHub's API. It is only required while accessing non-public resources or to increase the rate limit.
36+
37+
> [!WARNING]
38+
> The first request for the repository will take some time, but the subsequent request to the same repository are much faster due to caching.
39+
40+
### CLI
41+
42+
You can run the CLI application by running `docker compose exec -it app npm run start:cli`. The CLI application will provide instructions on the usage.

compose.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
services:
2-
cli:
2+
app:
33
build:
44
context: ./
55
env_file: .env
6-
container_name: rag-my-docs-cli
6+
container_name: rag-my-docs-app
7+
ports:
8+
- 3000:3000
79
redis:
810
image: redis/redis-stack-server
911
volumes:
@@ -20,5 +22,4 @@ services:
2022
container_name: rag-my-docs-postgres
2123
volumes:
2224
redis_data:
23-
ollama_data:
2425
pg_data:

0 commit comments

Comments
 (0)