Commit graph

4 commits

Author SHA1 Message Date
SamoilenkoVadym
29e6c2e442 Implement repository pattern and chat service orchestration
Repositories (Data Access Layer):
- BaseRepository: Generic CRUD operations with async support
- UserRepository: User management, Azure AD integration
- ConversationRepository: Conversation CRUD, archiving, search
- MessageRepository: Message creation, retrieval, search
- TokenUsageRepository: Usage tracking, cost calculation, analytics

Chat Service (Business Logic):
- Complete conversation lifecycle management
- Message sending with OpenAI integration
- Multi-turn conversation support via previous_response_id
- Automatic token usage tracking
- Cost calculation per message
- Permission checks for user access
- Conversation archiving and deletion
- Token usage analytics and reporting

Key Features:
- Repository pattern for clean data access
- Async/await throughout for performance
- Proper error handling and logging
- Permission verification for user actions
- Citation validation from OpenAI responses
- Automatic cost tracking per message
- File search results stored in message metadata

Integration Points:
- OpenAIService for AI responses
- All SQLAlchemy models
- Token cost calculation from settings
- Multi-turn conversations via last_response_id

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-27 14:28:41 +00:00
SamoilenkoVadym
86da0b2330 Implement OpenAI Responses API service with RAG enforcement
Features:
- OpenAIService class for Responses API integration
- file_search tool integration with Vector Store
- Strict RAG-only enforcement via system instructions
- Citation validation to prevent hallucinations
- Warning logs for responses without proper citations
- Support for multi-turn conversations via previous_response_id
- Async streaming support for real-time responses
- Comprehensive error handling and logging

Test Coverage:
- Service initialization and configuration
- System instructions validation
- Citation detection (valid, missing, no-info responses)
- Search results formatting
- RAG usage validation with hallucination detection
- Response generation with mocked API calls
- Multi-turn conversation support
- Error handling
- Integration test stubs (skipped, require API key)

Key RAG Safety Features:
- Low temperature (0.3) for factual responses
- Citation keyword detection
- Automatic disclaimer for uncited responses
- Separate handling of valid "no info" responses
- Warning logs for potential hallucinations

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-27 14:26:43 +00:00
SamoilenkoVadym
a8151fbe66 Add comprehensive backend test suite and Phase 1 foundation
Backend Tests:
- Add pytest configuration with async support (conftest.py)
- Add model tests: User, Conversation, Message, TokenUsage, Session, UserMemory
- Add configuration tests: Settings validation and environment variables
- Add API tests: Health endpoint and future endpoint stubs
- Add database tests: Connection, transactions, query execution

Phase 1 Foundation:
- FastAPI application structure with main.py
- SQLAlchemy async models for all entities
- Alembic migrations setup
- Configuration management via Pydantic Settings
- Logging system (English only)
- Docker multi-stage builds for backend
- Docker Compose orchestration (PostgreSQL, Redis, backend)
- Frontend React + TypeScript structure
- Dark & Gold theme CSS implementation
- Environment configuration examples

All code and comments in English as per requirements.
Tests cover model relationships, cascade deletes, and constraints.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-27 14:24:59 +00:00
Vadym Samoilenko
6813616035 Initial commit 2026-01-27 13:27:21 +00:00