A powerful backend service for CS2 (Counter-Strike 2) skin economy research and analysis, built with FastAPI and LangChain.
graph TD
A[FastAPI Server] --> B[LangChain Agent]
B --> C[Search Tools]
B --> D[Document Tools]
B --> E[CS Skins Tool]
C --> F[Search Utils]
C --> G[Fallback Search]
F --> H[FAISS Index]
F --> I[Sentence Transformers]
D --> J[Document Processing]
D --> K[Pattern Analysis]
E --> L[Price Analysis]
E --> M[Market Data]
- Entry point for the application
- Handles HTTP requests and CORS
- Initializes the search engine and tools
- Manages the LangChain agent
- Primary search implementation using FAISS and Sentence Transformers
- Fallback mechanism for when dependencies are missing
- Features:
- Semantic search using embeddings
- Fuzzy matching for similar items
- Price-based filtering
- Pattern recognition
- Collection of specialized tools for the LangChain agent:
cs_skins_tool: CS2 skin price and market datasearch_tool: Web search capabilitieswiki_tool: Wikipedia informationsave_tool: Data persistencedocument_tool: Document analysis
- Handles document analysis and pattern recognition
- Processes structured data for the search engine
- Manages document caching and updates
- Clone the repository:
git clone https://github.com/yourusername/2m-backend.git
cd 2m-backend- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Set up environment variables:
cp .env.example .env
# Edit .env with your configuration- Start the server:
python main.pyMain endpoint for processing queries about CS2 skins and market data.
Request:
{
"query": "What's the cheapest AK-47 skin?"
}Response:
{
"answer": "Detailed response about AK-47 skins...",
"sources": ["source1", "source2"]
}Health check endpoint.
The backend supports various types of queries:
-
Price-based queries:
- "cheapest AK-47"
- "AWP skins under $50"
- "Glock-18 between $10 and $30"
-
Pattern-based queries:
- "Doppler patterns"
- "Fade patterns"
-
Market analysis:
- "price trends"
- "market statistics"
- Create a new tool function in
tools.py - Register it in the
toolslist inmain.py - Update the agent's prompt if necessary
- Edit
search_utils.pyfor core search functionality - Update
search_utils_simplified.pyfor fallback behavior - Test both implementations
- The system includes fallback mechanisms for missing dependencies
- Errors are logged and handled gracefully
- User-friendly error messages are returned
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
MIT License - see LICENSE file for details