Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup FastAPI Intelligence Service #47

Merged
merged 5 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions server/intelligence-service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Intelligence Service

This is a FastAPI service for interfacing with LangChain and other machine learning services.

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [Project Structure](#project-structure)
- [Testing](#testing)

## Installation

To set up the project locally, follow these steps:

1. **Install dependencies:**
The project uses `poetry` for dependency management. Install the dependencies by running:
```bash
poetry install
```

2. **Run the application:**
You can start the FastAPI application with Uvicorn:
```bash
poetry run uvicorn src.main:app --reload
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me might want to improve this in the future so it is just poetry run intelligence-service or so

```

## Usage

After running the application, you can access the FastAPI API documentation at `http://127.0.0.1:8000/docs` or `http://127.0.0.1:8000/redoc`.

## Project Structure

The project is organized as follows:
```
intelligence-service/
├── pyproject.toml
├── README.md
├── poetry.lock
├── .pytest_cache/
├── tests/
│ ├── __init__.py
│ └── test_hello.py
├── src/
│ ├── config.py
│ ├── main.py
│ └── auth/
│ └── router.py
└── ...
```
## Testing

The project includes a set of unit tests to ensure that the core functionalities work as expected. These tests are located in the `tests/` directory.

### Running Tests

To run all tests, use the following command:

```bash
poetry run pytest
397 changes: 397 additions & 0 deletions server/intelligence-service/poetry.lock

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions server/intelligence-service/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[tool.poetry]
name = "intelligence-service"
version = "0.1.0"
description = "A FastAPI service for interfacing with large language models (LLMs) and providing intelligent text-based responses"
authors = ["milenasrb <[email protected]>"]
readme = "README.md"
package-mode = false

[tool.poetry.dependencies]
python = "^3.12"
fastapi = "^0.112.0"
uvicorn = "^0.30.5"


[tool.poetry.group.dev.dependencies]
httpx = "^0.27.0"
pytest = "^8.3.2"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
8 changes: 8 additions & 0 deletions server/intelligence-service/src/auth/router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from fastapi import APIRouter

router = APIRouter()


@router.get("/", response_model=dict, summary="Hello World Endpoint")
async def hello_world():
return {"message": "Hello, World!"}
5 changes: 5 additions & 0 deletions server/intelligence-service/src/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Settings:
APP_NAME: str = "Intelligence Service"


settings = Settings()
8 changes: 8 additions & 0 deletions server/intelligence-service/src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from fastapi import FastAPI

from .auth.router import router
from .config import settings

app = FastAPI(title=settings.APP_NAME)

app.include_router(router)
Empty file.
10 changes: 10 additions & 0 deletions server/intelligence-service/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from fastapi.testclient import TestClient
from src.main import app

client = TestClient(app)


def test_hello_world():
response = client.get("/")
assert response.status_code == 200
assert response.json() == {"message": "Hello, World!"}