Skip to content

Commit 8e5ca64

Browse files
authored
Merge pull request #35 from ks6088ts-labs/copilot/fix-34
Enhance documentation, testing, and logging functionality
2 parents bfb3d66 + c78cf9f commit 8e5ca64

File tree

15 files changed

+1515
-224
lines changed

15 files changed

+1515
-224
lines changed

.env.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ MICROSOFT_GRAPH_TENANT_ID="<YOUR_TENANT_ID>"
3131
MICROSOFT_GRAPH_CLIENT_ID="<YOUR_CLIENT_ID>"
3232
MICROSOFT_GRAPH_CLIENT_SECRET="<YOUR_CLIENT_SECRET>"
3333
MICROSOFT_GRAPH_USER_SCOPES="User.Read Sites.Read.All" # scopes for Microsoft Graph API
34+
35+
# Logging Configuration
36+
LOG_LEVEL="INFO" # Valid levels: DEBUG, INFO, WARNING, ERROR, CRITICAL

README.md

Lines changed: 155 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,182 @@
66

77
# template-fastapi
88

9-
This is a template repository for Python
9+
A comprehensive FastAPI template with Azure cloud services integration, Agent-based workflows, and multi-service API architecture.
1010

11-
## Prerequisites
11+
## Features
12+
13+
- **Multiple API Services**: Items management, file operations, restaurant discovery, speech transcription, and agent-based chat
14+
- **Azure Cloud Integration**: CosmosDB, Blob Storage, OpenAI, AI Speech, and Application Insights
15+
- **Agent Workflows**: LangGraph and Azure AI Foundry integration for conversational AI
16+
- **Real-time Communication**: WebSocket-based chat functionality
17+
- **Comprehensive Logging**: Configurable log levels with structured error handling
18+
- **Testing & Quality**: 37+ automated tests with logging and monitoring
19+
- **Container Ready**: Docker support with multi-stage builds
20+
21+
## Quick Start
22+
23+
### Prerequisites
1224

1325
- [Python 3.10+](https://www.python.org/downloads/)
14-
- [uv](https://docs.astral.sh/uv/getting-started/installation/)
26+
- [uv](https://docs.astral.sh/uv/getting-started/installation/) (recommended) or pip
1527
- [GNU Make](https://www.gnu.org/software/make/)
1628

17-
## Development instructions
29+
### Installation
1830

19-
### Local development
31+
```bash
32+
# Clone the repository
33+
git clone https://github.com/ks6088ts-labs/template-fastapi.git
34+
cd template-fastapi
2035

21-
Use Makefile to run the project locally.
36+
# Install dependencies
37+
make install-deps-dev
2238

23-
```shell
24-
# help
25-
make
39+
# Copy environment template
40+
cp .env.template .env
41+
# Edit .env with your Azure service credentials
42+
```
2643

27-
# install dependencies for development
28-
make install-deps-dev
44+
### Running the Application
2945

30-
# run tests
46+
```bash
47+
# Development server with hot reload
48+
make dev
49+
50+
# Production server
51+
make run
52+
53+
# Run tests
3154
make test
3255

33-
# run CI tests
34-
make ci-test
56+
# View documentation
57+
make docs-serve
58+
```
59+
60+
The API will be available at http://localhost:8000 with interactive documentation at http://localhost:8000/docs.
61+
62+
## API Services
63+
64+
### Core Services
65+
66+
- **Items API** (`/items/`): CRUD operations for item management
67+
- **Files API** (`/files/`): File upload, download, and management with Azure Blob Storage
68+
- **Restaurants API** (`/foodies/`): Restaurant discovery with geospatial search
69+
- **Speech API** (`/speeches/`): Batch transcription jobs using Azure AI Speech
70+
71+
### Agent Services
72+
73+
- **LangGraph Agents** (`/agents/langgraph/`): AI agents with custom tools
74+
- **Azure AI Foundry** (`/agents/azure-ai-foundry/`): Thread-based conversations
75+
- **Chat Interface** (`/chats/`): Real-time WebSocket chat with agent integration
76+
77+
### Demo & Utilities
78+
79+
- **Demo Endpoints** (`/demos/`): Dice rolling, flaky endpoints for testing
80+
- **Health & Monitoring**: Application Insights integration with OpenTelemetry
81+
82+
## Configuration
83+
84+
### Environment Variables
85+
86+
Key configuration options in `.env`:
87+
88+
```bash
89+
# Logging
90+
LOG_LEVEL=INFO # DEBUG, INFO, WARNING, ERROR, CRITICAL
91+
92+
# Azure OpenAI
93+
AZURE_OPENAI_ENDPOINT=https://<name>.openai.azure.com/
94+
AZURE_OPENAI_API_KEY=<key>
95+
AZURE_OPENAI_MODEL_CHAT=gpt-4o
96+
97+
# Azure Storage & Database
98+
AZURE_COSMOSDB_CONNECTION_STRING=<connection-string>
99+
AZURE_BLOB_STORAGE_CONNECTION_STRING=<connection-string>
100+
101+
# Monitoring
102+
APPLICATIONINSIGHTS_CONNECTION_STRING=<connection-string>
35103
```
36104

37-
### Docker development
105+
See `.env.template` for complete configuration options.
106+
107+
## Docker Deployment
38108

39-
```shell
40-
# build docker image
109+
```bash
110+
# Build image
41111
make docker-build
42112

43-
# run docker container
44-
make docker-run
113+
# Run container
114+
docker run -p 8000:8000 --env-file .env ks6088ts/template-fastapi:latest
115+
```
116+
117+
## Development
118+
119+
### Project Structure
120+
121+
```
122+
template_fastapi/
123+
├── routers/ # API route handlers
124+
│ ├── agents/ # Agent-based endpoints
125+
│ ├── chats.py # WebSocket chat
126+
│ ├── demos.py # Demo endpoints
127+
│ ├── files.py # File operations
128+
│ ├── foodies.py # Restaurant API
129+
│ ├── items.py # Items CRUD
130+
│ └── speeches.py # Speech transcription
131+
├── models/ # Pydantic data models
132+
├── repositories/ # Data access layer
133+
├── settings/ # Configuration management
134+
└── templates/ # Jinja2 templates
135+
```
136+
137+
### Testing
138+
139+
```bash
140+
# Run all tests
141+
make test
142+
143+
# Run with coverage
144+
pytest --cov=template_fastapi
45145

46-
# run CI tests in docker container
47-
make ci-test-docker
146+
# Run specific test file
147+
pytest tests/test_api.py -v
48148
```
49149

50-
## Deployment instructions
150+
### Code Quality
51151

52-
### Docker Hub
152+
```bash
153+
# Format code
154+
make format
53155

54-
To publish the docker image to Docker Hub, you need to [create access token](https://app.docker.com/settings/personal-access-tokens/create) and set the following secrets in the repository settings.
156+
# Lint code
157+
make lint
55158

56-
```shell
57-
gh secret set DOCKERHUB_USERNAME --body $DOCKERHUB_USERNAME
58-
gh secret set DOCKERHUB_TOKEN --body $DOCKERHUB_TOKEN
159+
# Apply auto-fixes
160+
make fix
59161
```
162+
163+
## Azure Functions Deployment
164+
165+
The application supports Azure Functions deployment:
166+
167+
```bash
168+
# Export requirements
169+
uv export --format requirements-txt --no-dev --no-hashes --output-file requirements.txt
170+
171+
# Deploy to Azure Functions
172+
func azure functionapp publish <function-app-name>
173+
```
174+
175+
## Contributing
176+
177+
1. Fork the repository
178+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
179+
3. Make your changes with tests
180+
4. Run quality checks (`make ci-test`)
181+
5. Commit your changes (`git commit -m 'Add amazing feature'`)
182+
6. Push to the branch (`git push origin feature/amazing-feature`)
183+
7. Open a Pull Request
184+
185+
## License
186+
187+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

0 commit comments

Comments
 (0)