A FastAPI-based backend service for managing Interactive Non-Fungible Tokens (iNFTs) with AI-powered chat capabilities and semantic search functionality.
- iNFT Management: Create, store, and manage iNFTs with metadata and traits
- AI-Powered Chat: Interactive chat functionality with each iNFT using ASI API
- Semantic Search: Vector-based similarity search using sentence transformers and FAISS
- Feedback System: Rating and feedback mechanism for iNFTs with score computation
- Web3 Storage: Mock Web3 storage integration for file management
- SQLite Database: Persistent storage for iNFTs and feedback data
- Framework: FastAPI
- Database: SQLite
- AI/ML:
- ASI API for chat completions
- Sentence Transformers (all-MiniLM-L6-v2) for embeddings
- FAISS for vector similarity search
- Dependencies:
uvicorn- ASGI serverpython-dotenv- Environment variable managementrequests- HTTP clientpydantic- Data validation
Backend/
├── __init__.py # Package initialization
├── main.py # FastAPI application entry point
├── config.py # Configuration and environment variables
├── db.py # Database initialization and schema
├── routes.py # API endpoints and route handlers
├── utils.py # Utility functions (Web3 storage, ASI API calls)
└── embedding.py # Vector embeddings and semantic search
Create a .env file in the root directory with the following variables:
ASI_API_KEY=your_asi_api_key_here
ASI_MODEL=asi1-miniid: Primary key (auto-increment)name: iNFT nameowner: Owner address/identifiertag: Category/tagcid: Content identifier (Web3 storage)traits_json: JSON string of traits/metadatascore: Average rating score (0-10)created_at: Timestamp
id: Primary key (auto-increment)inft_id: Reference to iNFTrating: Rating score (0-10)comment: Optional feedback commentcreated_at: Timestamp
POST /create_inft- Create a new iNFT with metadataGET /list_infts- List all iNFTs with their details
POST /chat/{inft_id}- Chat with a specific iNFT using AI
POST /feedback/{inft_id}- Submit rating and feedback for an iNFT
- Each iNFT has a unique persona based on its name, tag, and traits
- Uses ASI API for generating contextual responses
- Incorporates relevant memory through semantic search
- Converts text data into vector embeddings using sentence transformers
- Stores embeddings in FAISS index for fast similarity search
- Retrieves relevant context for chat interactions
-
iNFT Creation:
- Store metadata in database
- Generate embeddings from traits
- Mock upload to Web3 storage
-
Chat Interaction:
- Retrieve iNFT persona and traits
- Search for relevant memories using embeddings
- Generate AI response with context
-
Feedback Processing:
- Store user feedback
- Recompute average score
- Update iNFT rating
-
Install Dependencies:
pip install -r requirements.txt
-
Set Environment Variables: Create
.envfile with ASI API credentials -
Run the Server:
cd Backend uvicorn main:app --reload -
Access API Documentation: Visit
http://localhost:8000/docsfor interactive API documentation
- CORS middleware configured for cross-origin requests
- Input validation using Pydantic models
- Error handling for API failures
- SQLite connection with thread safety
- In-memory FAISS index for fast vector search
- Connection pooling for database operations
- Efficient embedding generation and storage
- Mock Web3 storage for development/testing
- Uses mock Web3 storage implementation for development
- Fallback mock responses when ASI API is unavailable
- Thread-safe database operations
- Comprehensive error handling and HTTP status codes
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is part of the iNFT Agent ecosystem for creating interactive and intelligent NFTs with AI capabilities.