A comprehensive AI-powered assistant system that combines legal expertise with Cardano blockchain integration. This system provides intelligent assistance for legal queries across multiple domains (Civil Law, Corporate Law, Property Law) and real-time Cardano blockchain data analysis.
- FastAPI Backend - RESTful API with security middleware and rate limiting
- Multi-Agent System - Specialized AI agents for different domains
- Cardano Blockchain Integration - Real-time data from Cardano network via BlockFrost API
- Vector Database - ChromaDB for semantic search and knowledge retrieval
- Legal Knowledge Base - Specialized legal document processing and search
- Cardano Agent: Handles blockchain queries, transaction analysis, and address information
- Legal Assistant Agent: Provides expertise in civil, corporate, and property law
- Transaction Analysis: Retrieve and analyze transaction details using transaction hashes
- Address Information: Get comprehensive address data including balance and transaction history
- Transaction Flow Analysis: Analyze asset flow between addresses with detailed input/output tracking
- Real-time Data: Live connection to Cardano Preview Testnet via BlockFrost API
- CBOR Decoding: Support for Cardano-specific data formats
- Multi-Domain Expertise: Civil Law, Corporate Law, Property Law
- Document Search: Semantic search across legal documents and precedents
- Context-Aware Responses: Intelligent responses based on legal domain context
- Markdown Formatting: Web-ready formatted responses
- Authentication: Custom security token middleware
- Rate Limiting: Configurable request rate limiting
- CORS Support: Cross-origin resource sharing for web applications
- Health Monitoring: Health check endpoints for system monitoring
AI-system/
βββ app/
β βββ api/endpoints/ # API route definitions
β β βββ query.py # Cardano blockchain queries
β β βββ legal_query.py # Legal assistance queries
β β βββ training.py # Vector database setup
β βββ core/
β β βββ config.py # Environment configuration
β βββ crud/ # Business logic layer
β βββ schemas/ # Pydantic data models
β βββ utils/ # Utility functions
βββ workflow/
β βββ agents/ # AI agent implementations
β β βββ cardano_agent.py # Cardano blockchain agent
β β βββ legal_assistant.py # Legal domain agent
β βββ tools/ # Agent tools and integrations
β βββ blockfrost_tool.py # Cardano blockchain tools
β βββ knowledge_base_tool.py # Knowledge search tools
β βββ legal_data_tool.py # Legal document tools
βββ data/ # Raw document storage
β βββ cardano/ # Cardano documentation
β βββ civil_law/ # Civil law documents
β βββ corporate_law/ # Corporate law documents
β βββ property_law/ # Property law documents
βββ db/ # Vector database storage
βββ test/ # Testing and development scripts
- Python 3.10+
- OpenAI API Key
- BlockFrost API Key (Cardano)
- Clone the repository
git clone <repository-url>
cd Cardano-AI-system- Install dependencies
pip install -r requirements.txt- Environment Configuration
Create a
.envfile in the root directory:
OPENAI_API_KEY=your_openai_api_key
BLOCKFROST_PROJECT_ID=your_blockfrost_project_id
BLOCKFROST_BASE_URL=https://cardano-preview.blockfrost.io/api/v0
CHROMA_DB_PATH=./chroma_data- Setup Vector Databases
# Start the FastAPI server
uvicorn app.main:app --reload
# Setup all knowledge bases (one-time setup)
curl -X GET "http://localhost:8000/training/setup_all_vector_dbs" \
-H "Secret-token: unihack25"# Build the Docker image
docker build -t ai-legal-cardano-system .
# Run the container
docker run -p 8000:8000 --env-file .env ai-legal-cardano-systemAll API endpoints require a security token header:
Secret-token: unihack25
POST /query/
Content-Type: application/json
{
"thread_id": 1,
"user_input": "What is the balance of addr_test1wryf65umuw5nuh8m4sjh9dka0mx7pwsmle0uyex8pf7f4ycj7y6tp?",
"lang": "en"
}POST /legalquery/
Content-Type: application/json
{
"thread_id": 1,
"domain": "corporate_law",
"user_input": "What are the requirements for company registration?",
"lang": "en"
}GET /training/setup_cardano_vector_db
GET /training/setup_civil_law_vector_db
GET /training/setup_corporate_law_vector_db
GET /training/setup_property_law_vector_db
GET /training/setup_all_vector_dbsget_address_details(address)- Get comprehensive address informationget_transactions_for_address(address)- Retrieve transaction historyget_single_transaction_details(tx_hash)- Detailed transaction analysissearch_cardano_knowledge(query)- Search Cardano documentation
search_civil_law_knowledge(query)- Civil law document searchsearch_corporate_law_knowledge(query)- Corporate law expertisesearch_legal_property_law_knowledge(query)- Property law assistance
Transaction Analysis:
"Analyze transaction 4bcba01d2c775b545c783bbd49a9443bb0ac071c743c86eeddd6a814852288e5"
Address Information:
"What is the current balance and transaction history for addr_test1wryf65umuw5nuh8m4sjh9dka0mx7pwsmle0uyex8pf7f4ycj7y6tp?"
General Cardano Questions:
"How does Cardano's proof-of-stake consensus work?"
Corporate Law:
Domain: "corporate_law"
Query: "What are the legal requirements for forming a corporation?"
Property Law:
Domain: "property_law"
Query: "What are the steps involved in property transfer?"
Civil Law:
Domain: "civil_law"
Query: "What constitutes a valid contract under civil law?"
# Run the test script for Cardano integration
python test/blockFrostApi.py
# Run the agent test
python test/agent.py# Start with auto-reload
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000- Place PDF documents in the appropriate
data/subdirectory - Run the corresponding vector database setup endpoint
- The system will automatically process and index the documents
- Token-based Authentication: Custom middleware for API security
- Rate Limiting: Configurable request throttling
- CORS Configuration: Secure cross-origin request handling
- Input Validation: Pydantic schema validation for all requests
- BlockFrost API: Production-ready Cardano data access
- Preview Testnet: Safe testing environment
- Real-time Data: Live blockchain information
- CBOR Support: Native Cardano data format handling
- LangChain: Advanced agent orchestration
- OpenAI GPT-4: High-quality language understanding
- ChromaDB: Efficient vector similarity search
- Embeddings: Semantic document understanding
GET /healthReturns system health status and availability.
- Fork the repository
- Create a feature branch
- Implement your changes
- Add appropriate tests
- Submit a pull request
This project is licensed under the terms specified in the LICENSE file.
- Testnet Usage: Currently configured for Cardano Preview Testnet
- API Keys: Ensure proper security for API keys in production
- Rate Limits: Respect BlockFrost API rate limitations
- Legal Disclaimer: This system provides informational assistance only, not legal advice
For technical support or questions:
- Check the API documentation at
/docswhen the server is running - Review the logs for debugging information
- Ensure all environment variables are properly configured
- Verify vector databases are properly initialized
Built for UniHack 2025 Organized by CoinCeylon - An intelligent assistant system combining legal expertise with blockchain technology.