Skip to content

Commit a82e18d

Browse files
refactor: refactor repo structure for better expandability (#27)
* refactor: Update import paths for LlamaCppClient and related modules * refactor: Restructure repository for improved modularity and clarity * refactor: Restructure repository for improved modularity and clarity * refactor: Update test coverage paths in CI configuration * refactor: Rename functions and variables for clarity and consistency
1 parent 3d42b70 commit a82e18d

61 files changed

Lines changed: 225 additions & 219 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,4 @@ jobs:
8484
8585
- name: Run tests
8686
run: |
87-
poetry run python -m pytest --durations=5 --log-cli-level=DEBUG --capture=tee-sys -v --cov=chatbot --cov-report=term-missing --cov-fail-under=60
87+
poetry run python -m pytest --durations=5 --log-cli-level=DEBUG --capture=tee-sys -v --cov=backend --cov-report=term-missing --cov-fail-under=60

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ install_pre_commit:
1515
poetry run pre-commit install --hook-type pre-commit
1616

1717
migrate_db:
18-
cd backend && PYTHONPATH=.:../chatbot poetry run python migration.py
18+
cd backend && poetry run python migration.py
1919

2020
start_llama_server_cuda:
2121
docker compose up -d

README.md

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,13 @@ To easily install the dependencies and start the services we created a make file
114114
* Both starts `llama.cpp` server locally via Docker compose.
115115
* Start: ```make start```
116116
* Start both the backend and frontend ensuring that the backend is running and ready before launching the frontend.
117-
* Stop `llama.cpp` Server: ```make stop_llama_server```
118-
* Stop the llama.cpp server if it's running locally.
119-
* Start Server: ```make start_server```
117+
* Start llama.cpp server
118+
* on CUDA: ```make start_llama_server_cuda```
119+
* on Metal: ```make start_llama_server_metal```
120120
* Start the llama.cpp server locally via Docker compose.
121121
* It will be available at http://0.0.0.0:8080 (it will show the llama-ui).
122+
* Stop `llama.cpp` Server: ```make stop_llama_server```
123+
* Stop the llama.cpp server if it's running locally.
122124
* Update: ```make update```
123125
* Update an environment and installs all updated dependencies.
124126
* Tidy up the code: ```make tidy```
@@ -240,25 +242,14 @@ Build the memory index by running:
240242

241243
```shell
242244
make migrate_db
243-
python chatbot/memory_builder.py --model-name jinaai/jina-embeddings-v5-text-small-retrieval --chunk-size 1000 --chunk-overlap 50
245+
cd scripts && PYTHONPATH=.:../backend python memory_builder.py --model-name jinaai/jina-embeddings-v5-text-small-retrieval --chunk-size 1000 --chunk-overlap 50
244246
```
245247

246248
## Run the Chatbot
247249

248250
The Chatbot has a UI built with `Vite`, `React` and `TypeScript`, and a backend built with `FastAPI` that serves the LLMs through `llama.cpp` server.
249251

250-
To start the backend type:
251-
252-
```shell
253-
cd backend && PYTHONPATH=.:../chatbot uvicorn main:app --reload
254-
```
255-
256-
To start the frontend (in a new terminal):
257-
```shell
258-
cd frontend && yarn dev
259-
```
260-
261-
or to start both ensuring that the backend is running and ready before launching the frontend just run:
252+
To start both the backend and frontend ensuring that the backend is running and ready before launching the frontend just run:
262253

263254
```shell
264255
make start

backend/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
To start the backend type:
2+
3+
```shell
4+
cd backend && uvicorn main:app --reload
5+
```

backend/alembic/env.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from logging.config import fileConfig
22

33
from alembic import context
4-
from bot.memory.document_registry import DocumentRecord # noqa: F401 – registers the model
5-
from core.config import settings
4+
from config import settings
65
from helpers.log import get_logger
76
from sqlalchemy import engine_from_config, pool
87
from sqlmodel import SQLModel

backend/api/deps.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
from typing import Annotated, Generator
66

77
import state
8-
from bot.client.llamacpp_client import LlamaCppClient
9-
from bot.conversation.chat_history import ChatHistory
10-
from bot.memory.vector_database.chroma import Chroma
11-
from chat_history import chat_history
8+
from chat_history import ChatHistory, chat_history
129
from fastapi import Depends
10+
from llm_providers.llamacpp_client import LlamaCppClient
11+
from memory.vector_database.chroma import Chroma
1312
from sqlmodel import Session
1413

1514

@@ -31,14 +30,14 @@ def get_index() -> Generator[Chroma, None, None]:
3130
"""
3231
Dependency to get the vector database index instance.
3332
"""
34-
yield state.index
33+
yield state.vector_database
3534

3635

3736
def get_db_session() -> Generator[Session, None, None]:
3837
"""
3938
Create a new database session and close the session after the operation has ended.
4039
"""
41-
with Session(state.engine) as session:
40+
with Session(state.db_engine) as session:
4241
yield session
4342

4443

backend/api/endpoints/chat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from core.config import settings
1+
from config import settings
22
from fastapi import APIRouter
33
from fastapi.responses import JSONResponse
44
from helpers.log import get_logger

backend/api/endpoints/documents.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from pathlib import Path
22
from typing import Annotated
33

4-
from bot.memory.document_registry import DocumentRegistry
5-
from bot.memory.vector_database.id_generator import generate_id
6-
from core.config import settings
7-
from document_loader.loader import DirectoryLoader
4+
from config import settings
85
from fastapi import APIRouter, File, HTTPException, UploadFile
96
from helpers.log import get_logger
10-
from memory_builder import split_chunks
7+
from memory.vector_database.id_generator import generate_id
118
from schemas.documents import DocumentInfo, DocumentListResponse, DocumentUploadResponse
9+
from services.ingest_documents_service.document_loader.loader import DirectoryLoader
10+
from services.ingest_documents_service.document_loader.text_splitter import split_chunks
11+
from services.ingest_documents_service.document_registry import DocumentRegistry
1212

1313
from api.deps import SessionDep, VectorDatabaseDep
1414

backend/api/endpoints/health.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from core.config import settings
1+
from config import settings
22
from fastapi import APIRouter
33
from schemas.health import HealthResponse
44

backend/api/services/chat_stream.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import time
22

3-
from bot.conversation.conversation_handler import (
3+
from config import settings
4+
from fastapi import WebSocket
5+
from helpers.log import get_logger
6+
from helpers.prettier import prettify_source
7+
from schemas.chat import ChatRequest
8+
from services.chat_service.conversation_handler import (
49
answer,
510
answer_with_context,
611
extract_content_after_reasoning,
712
refine_question,
813
)
9-
from bot.conversation.ctx_strategy import get_ctx_synthesis_strategy
10-
from core.config import settings
11-
from fastapi import WebSocket
12-
from helpers.log import get_logger
13-
from helpers.prettier import prettify_source
14-
from schemas.chat import ChatRequest
14+
from services.chat_service.ctx_strategy import get_ctx_synthesis_strategy
1515

1616
from api.deps import ChatHistoryDep, LlamaCppClientDep, VectorDatabaseDep
1717

0 commit comments

Comments
 (0)