Spaces:
Paused
Paused
| from fastapi import FastAPI, HTTPException, BackgroundTasks | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from pydantic import BaseModel | |
| from typing import Dict, List, Optional, Any | |
| import json | |
| import logging | |
| from datetime import datetime, timedelta | |
| import os | |
| import requests | |
| import asyncio | |
| from enum import Enum | |
| import uuid | |
| import sqlite3 | |
| import threading | |
| import time | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| app = FastAPI(title="ุงููุธุงู ุงูุฐูู ุงูุญูููู - ุงููููู ุงูุงุณุชุฑุงุชูุฌู ุงูู ุชูุงู ู") | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # ๐ฅ ููุงุนุฏ ุงูุจูุงูุงุช ุงูุญููููุฉ | |
| class DatabaseManager: | |
| def __init__(self): | |
| self.init_database() | |
| def init_database(self): | |
| """ุชููุฆุฉ ููุงุนุฏ ุงูุจูุงูุงุช ุงูุญููููุฉ""" | |
| conn = sqlite3.connect('real_system.db') | |
| cursor = conn.cursor() | |
| # ุฌุฏูู ุงูู ุญุงุฏุซุงุช | |
| cursor.execute(''' | |
| CREATE TABLE IF NOT EXISTS conversations ( | |
| id TEXT PRIMARY KEY, | |
| client_id TEXT, | |
| user_message TEXT, | |
| assistant_message TEXT, | |
| intent TEXT, | |
| timestamp DATETIME, | |
| important BOOLEAN | |
| ) | |
| ''') | |
| # ุฌุฏูู ุงูู ูุงู | |
| cursor.execute(''' | |
| CREATE TABLE IF NOT EXISTS tasks ( | |
| id TEXT PRIMARY KEY, | |
| client_id TEXT, | |
| title TEXT, | |
| description TEXT, | |
| task_type TEXT, | |
| status TEXT, | |
| current_step INTEGER, | |
| total_steps INTEGER, | |
| created_at DATETIME, | |
| updated_at DATETIME, | |
| target_file TEXT, | |
| parameters TEXT | |
| ) | |
| ''') | |
| # ุฌุฏูู ุฎุทูุงุช ุงูู ูุงู | |
| cursor.execute(''' | |
| CREATE TABLE IF NOT EXISTS task_steps ( | |
| id TEXT PRIMARY KEY, | |
| task_id TEXT, | |
| step_number INTEGER, | |
| action_type TEXT, | |
| description TEXT, | |
| status TEXT, | |
| result TEXT, | |
| executed_at DATETIME | |
| ) | |
| ''') | |
| conn.commit() | |
| conn.close() | |
| def save_conversation(self, conversation_data: Dict): | |
| """ุญูุธ ุงูู ุญุงุฏุซุฉ ูู ูุงุนุฏุฉ ุงูุจูุงูุงุช""" | |
| conn = sqlite3.connect('real_system.db') | |
| cursor = conn.cursor() | |
| cursor.execute(''' | |
| INSERT INTO conversations | |
| (id, client_id, user_message, assistant_message, intent, timestamp, important) | |
| VALUES (?, ?, ?, ?, ?, ?, ?) | |
| ''', ( | |
| conversation_data['id'], | |
| conversation_data['client_id'], | |
| conversation_data['user_message'], | |
| conversation_data['assistant_message'], | |
| conversation_data['intent'], | |
| conversation_data['timestamp'], | |
| conversation_data['important'] | |
| )) | |
| conn.commit() | |
| conn.close() | |
| def get_conversation_history(self, client_id: str, limit: int = 20): | |
| """ุงูุญุตูู ุนูู ุชุงุฑูุฎ ุงูู ุญุงุฏุซุงุช""" | |
| conn = sqlite3.connect('real_system.db') | |
| cursor = conn.cursor() | |
| cursor.execute(''' | |
| SELECT * FROM conversations | |
| WHERE client_id = ? | |
| ORDER BY timestamp DESC | |
| LIMIT ? | |
| ''', (client_id, limit)) | |
| rows = cursor.fetchall() | |
| conn.close() | |
| return [{ | |
| 'id': row[0], | |
| 'client_id': row[1], | |
| 'user_message': row[2], | |
| 'assistant_message': row[3], | |
| 'intent': row[4], | |
| 'timestamp': row[5], | |
| 'important': bool(row[6]) | |
| } for row in rows] | |
| def create_task(self, task_data: Dict): | |
| """ุฅูุดุงุก ู ูู ุฉ ุฌุฏูุฏุฉ""" | |
| conn = sqlite3.connect('real_system.db') | |
| cursor = conn.cursor() | |
| cursor.execute(''' | |
| INSERT INTO tasks | |
| (id, client_id, title, description, task_type, status, current_step, total_steps, created_at, updated_at, target_file, parameters) | |
| VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) | |
| ''', ( | |
| task_data['id'], | |
| task_data['client_id'], | |
| task_data['title'], | |
| task_data['description'], | |
| task_data['task_type'], | |
| task_data['status'], | |
| task_data['current_step'], | |
| task_data['total_steps'], | |
| task_data['created_at'], | |
| task_data['updated_at'], | |
| task_data.get('target_file'), | |
| json.dumps(task_data.get('parameters', {})) | |
| )) | |
| conn.commit() | |
| conn.close() | |
| def update_task_progress(self, task_id: str, current_step: int, status: str): | |
| """ุชุญุฏูุซ ุชูุฏู ุงูู ูู ุฉ""" | |
| conn = sqlite3.connect('real_system.db') | |
| cursor = conn.cursor() | |
| cursor.execute(''' | |
| UPDATE tasks | |
| SET current_step = ?, status = ?, updated_at = ? | |
| WHERE id = ? | |
| ''', (current_step, status, datetime.now().isoformat(), task_id)) | |
| conn.commit() | |
| conn.close() | |
| # ๐ฅ ูุธุงู ุงูุจุญุซ ุงูู ุชูุฏู ุงูุญูููู | |
| class AdvancedResearchEngine: | |
| def __init__(self): | |
| self.search_cache = {} | |
| self.expert_knowledge = self._load_expert_knowledge() | |
| def _load_expert_knowledge(self) -> Dict: | |
| """ุชุญู ูู ุงูู ุนุฑูุฉ ุงูู ุชุฎุตุตุฉ ูู ุงูุงุฎุชุฑุงู ูุชุทููุฑ ุงูุจูุชุงุช""" | |
| return { | |
| "game_hacking": { | |
| "tools": [ | |
| "Cheat Engine - ูุฃุฏูุงุช ุชุนุฏูู ุงูุฐุงูุฑุฉ", | |
| "IDA Pro - ููููุฏุณุฉ ุงูุนูุณูุฉ ุงูู ุชูุฏู ุฉ", | |
| "x64dbg - ู ุตุญุญ ุงูุฃุฎุทุงุก ุงูู ุชูุฏู ", | |
| "Process Hacker - ู ุฏูุฑ ุงูุนู ููุงุช", | |
| "PyMem - ู ูุชุจุฉ Python ูููุตูู ููุฐุงูุฑุฉ" | |
| ], | |
| "techniques": [ | |
| "Memory Scanning - ู ุณุญ ุงูุฐุงูุฑุฉ ููุนุซูุฑ ุนูู ุงูููู ", | |
| "Pointer Scanning - ุชุชุจุน ุงูู ุคุดุฑุงุช ูู ุงูุฐุงูุฑุฉ", | |
| "Code Injection - ุญูู ุงูุฃููุงุฏ ูู ุงูุนู ููุงุช", | |
| "DLL Injection - ุญูู ุงูู ูุชุจุงุช ุงูุฏููุงู ูููุฉ", | |
| "API Hooking - ุงุนุชุฑุงุถ ุงุณุชุฏุนุงุกุงุช ุงููุธุงู " | |
| ], | |
| "languages": ["C++", "C#", "Python", "Assembly"] | |
| }, | |
| "bot_development": { | |
| "frameworks": [ | |
| "OpenCV - ููุฑุคูุฉ ุงูุญุงุณูุจูุฉ ูุงูุชุนุฑู ุนูู ุงูุตูุฑ", | |
| "PyAutoGUI - ูุฃุชู ุชุฉ ูุงุฌูุฉ ุงูู ุณุชุฎุฏู ", | |
| "TensorFlow - ููุฐูุงุก ุงูุงุตุทูุงุนู ูุงูุชุนูู ุงูุขูู", | |
| "PyTorch - ูุฅุทุงุฑ ุนู ู ุงูุชุนูู ุงูุนู ูู", | |
| "Selenium - ูุฃุชู ุชุฉ ุงูู ุชุตูุญ" | |
| ], | |
| "techniques": [ | |
| "Image Recognition - ุงูุชุนุฑู ุนูู ุงูุตูุฑ ูุงูุนูุงุตุฑ", | |
| "Pixel Analysis - ุชุญููู ุงูุจูุณูุงุช ูููุดู ุนู ุงูุชุบูุฑุงุช", | |
| "Memory Reading - ูุฑุงุกุฉ ุงูุฐุงูุฑุฉ ููุญุตูู ุนูู ุงูุจูุงูุงุช", | |
| "Input Simulation - ู ุญุงูุงุฉ ุฅุฏุฎุงู ุงูู ุณุชุฎุฏู ", | |
| "Pattern Matching - ู ุทุงุจูุฉ ุงูุฃูู ุงุท ูููุดู ุนู ุงูุญุงูุงุช" | |
| ] | |
| }, | |
| "reverse_engineering": { | |
| "tools": [ | |
| "Ghidra - ุฃุฏุงุฉ ุงูููุฏุณุฉ ุงูุนูุณูุฉ ู ู NSA", | |
| "Radare2 - ุฅุทุงุฑ ุนู ู ููููุฏุณุฉ ุงูุนูุณูุฉ", | |
| "Binary Ninja - ู ูุตุฉ ููุชุญููู ุงูุซูุงุฆู", | |
| "Hopper - ุฃุฏุงุฉ ุงูุชุฌู ูุน ูุงูุชูููู", | |
| "PE Explorer - ู ุญุฑุฑ ู ููุงุช PE" | |
| ], | |
| "techniques": [ | |
| "Static Analysis - ุงูุชุญููู ุงูุซุงุจุช ููู ููุงุช", | |
| "Dynamic Analysis - ุงูุชุญููู ุงูุฏููุงู ููู ุฃุซูุงุก ุงูุชุดุบูู", | |
| "Decompilation - ุฅุนุงุฏุฉ ุงูุชุฌู ูุน ููุดูุฑุฉ ุงูู ุตุฏุฑูุฉ", | |
| "Debugging - ุชุชุจุน ุงูุชูููุฐ ุฎุทูุฉ ุจุฎุทูุฉ", | |
| "Patch Development - ุชุทููุฑ ุงูุชุตุญูุญุงุช ูุงูุชุนุฏููุงุช" | |
| ] | |
| } | |
| } | |
| async def deep_research(self, query: str, category: str = None) -> Dict: | |
| """ุจุญุซ ู ุชุนู ู ู ุน ู ุนุฑูุฉ ู ุชุฎุตุตุฉ""" | |
| try: | |
| # ุงูุจุญุซ ุนูู ุงูููุจ | |
| web_results = await self._web_search(query) | |
| # ุงูู ุนุฑูุฉ ุงูู ุชุฎุตุตุฉ | |
| expert_info = self._get_expert_knowledge(query, category) | |
| # ุชูููู ุงููุชุงุฆุฌ | |
| return { | |
| "web_results": web_results[:5], | |
| "expert_knowledge": expert_info, | |
| "tools_recommendations": self._get_tools_recommendations(category), | |
| "step_by_step_guide": self._generate_step_by_step_guide(query, category), | |
| "timestamp": datetime.now().isoformat() | |
| } | |
| except Exception as e: | |
| logger.error(f"ุฎุทุฃ ูู ุงูุจุญุซ ุงูู ุชุนู ู: {e}") | |
| return self._get_fallback_research(query, category) | |
| async def _web_search(self, query: str) -> List[Dict]: | |
| """ุจุญุซ ุญูููู ุนูู ุงูููุจ""" | |
| try: | |
| # ุฅุถุงูุฉ ููู ุงุช ู ูุชุงุญูุฉ ู ุชุฎุตุตุฉ | |
| enhanced_query = f"{query} hacking reverse engineering game cheat bot development" | |
| # ุงุณุชุฎุฏุงู DuckDuckGo | |
| url = f"https://api.duckduckgo.com/?q={enhanced_query}&format=json" | |
| response = requests.get(url, timeout=15) | |
| if response.status_code == 200: | |
| data = response.json() | |
| results = [] | |
| # ุงุณุชุฎุฑุงุฌ ุงููุชุงุฆุฌ | |
| if 'Results' in data: | |
| for item in data['Results']: | |
| results.append({ | |
| "title": item.get('Text', ''), | |
| "url": item.get('FirstURL', ''), | |
| "source": "DuckDuckGo", | |
| "snippet": item.get('Text', '')[:200] | |
| }) | |
| # ุงุณุชุฎุฏุงู Abstract ุฅุฐุง ูู ุชูุฌุฏ ูุชุงุฆุฌ | |
| if not results and 'Abstract' in data and data['Abstract']: | |
| results.append({ | |
| "title": data.get('Heading', 'ูุชูุฌุฉ ุงูุจุญุซ'), | |
| "url": data.get('AbstractURL', ''), | |
| "source": "DuckDuckGo", | |
| "snippet": data.get('Abstract', '')[:200] | |
| }) | |
| return results | |
| except Exception as e: | |
| logger.error(f"ุฎุทุฃ ูู ุงูุจุญุซ ุนูู ุงูููุจ: {e}") | |
| return [] | |
| def _get_expert_knowledge(self, query: str, category: str) -> Dict: | |
| """ุงูุญุตูู ุนูู ุงูู ุนุฑูุฉ ุงูู ุชุฎุตุตุฉ""" | |
| knowledge = {} | |
| if category in self.expert_knowledge: | |
| knowledge = self.expert_knowledge[category] | |
| else: | |
| # ุงูุจุญุซ ูู ุฌู ูุน ุงููุฆุงุช | |
| for cat, info in self.expert_knowledge.items(): | |
| if any(keyword in query.lower() for keyword in cat.split('_')): | |
| knowledge = info | |
| break | |
| return knowledge | |
| def _get_tools_recommendations(self, category: str) -> List[str]: | |
| """ุชูุตูุงุช ุงูุฃุฏูุงุช ุจูุงุกู ุนูู ุงููุฆุฉ""" | |
| if category in self.expert_knowledge: | |
| return self.expert_knowledge[category].get('tools', []) | |
| return [] | |
| def _generate_step_by_step_guide(self, query: str, category: str) -> List[str]: | |
| """ุชูููุฏ ุฏููู ุฎุทูุฉ ุจุฎุทูุฉ""" | |
| guides = { | |
| "game_hacking": [ | |
| "1. ุชุญุฏูุฏ ุงููุนุจุฉ ุงูู ุณุชูุฏูุฉ ูุชุญููู ูููู ุงูุฐุงูุฑุฉ", | |
| "2. ุชุซุจูุช Cheat Engine ูุฃุฏูุงุช ู ุณุญ ุงูุฐุงูุฑุฉ", | |
| "3. ุชุดุบูู ุงููุนุจุฉ ูู ุณุญ ุงูุนู ููุงุช ุงููุดุทุฉ", | |
| "4. ุงูุจุญุซ ุนู ุงูููู ูู ุงูุฐุงูุฑุฉ (ุงูุตุญุฉุ ุงูู ุงูุ ุงูุฐุฎูุฑุฉ)", | |
| "5. ุชุทููุฑ ุณูุฑูุจุช ุงูุชุนุฏูู ุจุงุณุชุฎุฏุงู Python/C++", | |
| "6. ุงุฎุชุจุงุฑ ุงูุชุนุฏููุงุช ูุชุตุญูุญ ุงูุฃุฎุทุงุก", | |
| "7. ุชุญุณูู ุงูุฃุฏุงุก ูุฅุถุงูุฉ ู ูุฒุงุช ู ุชูุฏู ุฉ", | |
| "8. ุชูุซูู ุงููุชุงุฆุฌ ูุงูุทุฑู ุงูู ุณุชุฎุฏู ุฉ" | |
| ], | |
| "bot_development": [ | |
| "1. ุชุญููู ู ุชุทูุจุงุช ุงูุจูุช ูุงููุฏู ู ูู", | |
| "2. ุชุซุจูุช Python ูุงูู ูุชุจุงุช ุงูู ุทููุจุฉ (OpenCV, PyAutoGUI)", | |
| "3. ุชุทููุฑ ูุธุงู ุงูุชุนุฑู ุนูู ุงูุตูุฑ ูุงูุนูุงุตุฑ", | |
| "4. ุจุฑู ุฌุฉ ู ูุทู ุงูุจูุช ูุงุชุฎุงุฐ ุงููุฑุงุฑุงุช", | |
| "5. ุชูููุฐ ูุธุงู ุงูุฃุชู ุชุฉ ูู ุญุงูุงุฉ ุงูุฅุฏุฎุงู", | |
| "6. ุงุฎุชุจุงุฑ ุงูุจูุช ูู ุจูุฆุฉ ุญููููุฉ", | |
| "7. ุชุญุณูู ุงูุฃุฏุงุก ูุฅุถุงูุฉ ุงูุชุนูู ุงูุขูู", | |
| "8. ุชุทููุฑ ูุงุฌูุฉ ุงูู ุณุชุฎุฏู ูููุญุฉ ุงูุชุญูู " | |
| ], | |
| "reverse_engineering": [ | |
| "1. ุชุญููู ุงูู ูู ุงูู ุณุชูุฏู ูุชุญุฏูุฏ ุจููุชู", | |
| "2. ุชุซุจูุช ุฃุฏูุงุช ุงูููุฏุณุฉ ุงูุนูุณูุฉ (IDA Pro, Ghidra)", | |
| "3. ุชูููู ุงูุดููุฑุฉ ูุชุญููู ุงูุฏูุงู ุงูุฑุฆูุณูุฉ", | |
| "4. ุงูุจุญุซ ุนู ุงูุซุบุฑุงุช ูููุงุท ุงูุถุนู", | |
| "5. ุชุทููุฑ ุงุณุชุบูุงู ููุซุบุฑุงุช ุงูู ูุชุดูุฉ", | |
| "6. ุงุฎุชุจุงุฑ ุงูุงุณุชุบูุงู ูู ุจูุฆุฉ ุขู ูุฉ", | |
| "7. ุชุทููุฑ ุชุตุญูุญ ุฃู ุชุนุฏูู ููู ูู", | |
| "8. ุชูุซูู ุนู ููุฉ ุงูุชุญููู ูุงููุชุงุฆุฌ" | |
| ] | |
| } | |
| return guides.get(category, [ | |
| "1. ุชุญููู ุงูู ุชุทูุจุงุช ูุงูุฃูุฏุงู", | |
| "2. ุชุฎุทูุท ุฎุทูุงุช ุงูุชูููุฐ", | |
| "3. ุชูููุฐ ุงูู ูู ุฉ ุฎุทูุฉ ุจุฎุทูุฉ", | |
| "4. ุงูุงุฎุชุจุงุฑ ูุงูุชุญูู ู ู ุงููุชุงุฆุฌ", | |
| "5. ุงูุชุญุณูู ูุงูุชุทููุฑ ุงูู ุณุชู ุฑ" | |
| ]) | |
| def _get_fallback_research(self, query: str, category: str) -> Dict: | |
| """ุจุญุซ ุงุญุชูุงุทู ุนูุฏ ูุดู ุงูุงุชุตุงู""" | |
| return { | |
| "web_results": [{ | |
| "title": f"ุจุญุซ ุนู: {query}", | |
| "url": "", | |
| "source": "ุงููุธุงู ุงูุฐูู", | |
| "snippet": f"ุฃุณุชุทูุน ู ุณุงุนุฏุชู ูู {query} ุจูุงุกู ุนูู ู ุนุฑูุชู ุงูู ุชุฎุตุตุฉ ูู ุงูุฃู ู ุงูุณูุจุฑุงูู ูุชุทููุฑ ุงูุจูุชุงุช." | |
| }], | |
| "expert_knowledge": self.expert_knowledge.get(category, {}), | |
| "tools_recommendations": self._get_tools_recommendations(category), | |
| "step_by_step_guide": self._generate_step_by_step_guide(query, category), | |
| "timestamp": datetime.now().isoformat() | |
| } | |
| # ๐ฅ ูุธุงู ุงูู ูุงู ุงูุญูููู ู ุน ุงูุชูููุฐ ุงูู ุณุชู ุฑ | |
| class RealTaskManager: | |
| def __init__(self, db_manager: DatabaseManager): | |
| self.db = db_manager | |
| self.active_tasks = {} | |
| self.task_executors = {} | |
| def create_complex_task(self, task_data: Dict) -> Dict: | |
| """ุฅูุดุงุก ู ูู ุฉ ู ุนูุฏุฉ ู ุชุนุฏุฏุฉ ุงูุฎุทูุงุช""" | |
| task_id = f"task_{uuid.uuid4().hex[:8]}" | |
| task = { | |
| "id": task_id, | |
| "client_id": task_data["client_id"], | |
| "title": task_data["title"], | |
| "description": task_data["description"], | |
| "task_type": task_data["task_type"], | |
| "status": "pending", | |
| "current_step": 0, | |
| "total_steps": len(task_data["steps"]), | |
| "steps": task_data["steps"], | |
| "created_at": datetime.now().isoformat(), | |
| "updated_at": datetime.now().isoformat(), | |
| "target_file": task_data.get("target_file"), | |
| "parameters": task_data.get("parameters", {}) | |
| } | |
| # ุญูุธ ูู ูุงุนุฏุฉ ุงูุจูุงูุงุช | |
| self.db.create_task(task) | |
| self.active_tasks[task_id] = task | |
| # ุจุฏุก ุงูุชูููุฐ ูู ุงูุฎูููุฉ | |
| self._start_task_execution(task_id) | |
| return task | |
| def _start_task_execution(self, task_id: str): | |
| """ุจุฏุก ุชูููุฐ ุงูู ูู ุฉ ูู ุงูุฎูููุฉ""" | |
| def execute_task(): | |
| task = self.active_tasks[task_id] | |
| for step_number, step in enumerate(task["steps"], 1): | |
| try: | |
| # ุชุญุฏูุซ ุญุงูุฉ ุงูุฎุทูุฉ | |
| task["current_step"] = step_number | |
| task["status"] = "executing" | |
| self.db.update_task_progress(task_id, step_number, "executing") | |
| logger.info(f"ุชูููุฐ ุงูุฎุทูุฉ {step_number}: {step['description']}") | |
| # ู ุญุงูุงุฉ ุงูุชูููุฐ (ุณูุชู ุงุณุชุจุฏุงููุง ุจุชูููุฐ ุญูููู) | |
| time.sleep(2) # ู ุญุงูุงุฉ ููุช ุงูุชูููุฐ | |
| # ููุง ุณูุชู ุงุณุชุฏุนุงุก ุงููููู ุงูุชูููุฐู ููุชูููุฐ ุงููุนูู | |
| execution_result = self._execute_step(step, task) | |
| if not execution_result["success"]: | |
| task["status"] = "failed" | |
| self.db.update_task_progress(task_id, step_number, "failed") | |
| break | |
| except Exception as e: | |
| logger.error(f"ุฎุทุฃ ูู ุชูููุฐ ุงูุฎุทูุฉ {step_number}: {e}") | |
| task["status"] = "failed" | |
| self.db.update_task_progress(task_id, step_number, "failed") | |
| break | |
| if task["status"] != "failed": | |
| task["status"] = "completed" | |
| self.db.update_task_progress(task_id, task["current_step"], "completed") | |
| logger.info(f"ุงูู ูู ุฉ {task_id} ุงูุชูุช ุจุงูุญุงูุฉ: {task['status']}") | |
| # ุชุดุบูู ุงูู ูู ุฉ ูู thread ู ููุตู | |
| thread = threading.Thread(target=execute_task) | |
| thread.daemon = True | |
| thread.start() | |
| def _execute_step(self, step: Dict, task: Dict) -> Dict: | |
| """ุชูููุฐ ุฎุทูุฉ ูุฑุฏูุฉ (ุณูุชู ุชูุตูููุง ุจุงููููู ุงูุชูููุฐู)""" | |
| # ูุฐุง ุณูุชุตู ุจุงููููู ุงูุชูููุฐู ุงูุญูููู | |
| action_type = step.get("action_type", "") | |
| # ู ุญุงูุงุฉ ุงูุชูููุฐ ุงููุงุฌุญ | |
| return { | |
| "success": True, | |
| "message": f"ุชู ุชูููุฐ: {step['description']}", | |
| "data": {"step_completed": True} | |
| } | |
| # ููุงูู ุงูุจูุงูุงุช | |
| class ChatRequest(BaseModel): | |
| message: str | |
| client_id: str | |
| timestamp: str | |
| context: Optional[List[Dict]] = None | |
| class ChatResponse(BaseModel): | |
| thinking_process: str | |
| message: str | |
| actions: List[Dict[str, Any]] = [] | |
| task_id: Optional[str] = None | |
| requires_execution: bool = False | |
| research_data: Optional[Dict] = None | |
| # ๐ฅ ุงูู ุญุฑู ุงูุฐูู ุงูู ุชูุงู ู | |
| class IntegratedAIAssistant: | |
| def __init__(self): | |
| self.db = DatabaseManager() | |
| self.research_engine = AdvancedResearchEngine() | |
| self.task_manager = RealTaskManager(self.db) | |
| self.conversation_memory = {} | |
| async def process_real_request(self, user_message: str, client_id: str) -> Dict: | |
| """ู ุนุงูุฌุฉ ุงูุทูุจ ุงูุญูููู ู ุน ูู ุงูุฃูุธู ุฉ ุงูู ุชูุงู ูุฉ""" | |
| # ุชุญููู ุนู ูู ููุทูุจ | |
| analysis = await self._comprehensive_analysis(user_message, client_id) | |
| # ุงูุจุญุซ ุงูู ุชูุฏู ุฅุฐุง ูุฒู ุงูุฃู ุฑ | |
| research_data = None | |
| if analysis["requires_research"]: | |
| research_data = await self.research_engine.deep_research( | |
| analysis["research_query"], | |
| analysis.get("category") | |
| ) | |
| # ุฅูุดุงุก ู ูู ุฉ ุฅุฐุง ูุฒู ุงูุฃู ุฑ | |
| task = None | |
| if analysis["requires_task"]: | |
| task = self.task_manager.create_complex_task( | |
| self._build_task_structure(analysis, client_id, user_message) | |
| ) | |
| # ุชูููุฏ ุงูุฑุฏ ุงูุดุงู ู | |
| response = await self._generate_comprehensive_response( | |
| user_message, analysis, task, research_data, client_id | |
| ) | |
| # ุญูุธ ูู ุงูุฐุงูุฑุฉ ููุงุนุฏุฉ ุงูุจูุงูุงุช | |
| self._store_complete_memory(client_id, user_message, response, analysis) | |
| return response | |
| async def _comprehensive_analysis(self, message: str, client_id: str) -> Dict: | |
| """ุชุญููู ุดุงู ู ู ุน ุงูุฐุงูุฑุฉ ุงูุชุงุฑูุฎูุฉ""" | |
| # ุงูุญุตูู ุนูู ุงูุชุงุฑูุฎ ุงูุณุงุจู | |
| history = self.db.get_conversation_history(client_id, 10) | |
| analysis = { | |
| "intent": "general_chat", | |
| "urgency": "normal", | |
| "requires_research": False, | |
| "requires_task": False, | |
| "research_query": "", | |
| "task_type": None, | |
| "category": None, | |
| "complexity": "low", | |
| "estimated_steps": 1, | |
| "historical_context": len(history) | |
| } | |
| message_lower = message.lower() | |
| # ูุดู ุงูููุงูุง ุงูู ุนูุฏุฉ ู ุน ุงูุณูุงู ุงูุชุงุฑูุฎู | |
| if any(word in message_lower for word in ["ุชูููุฑ", "ูุงู", "ุงุฎุชุฑุงู ูุนุจุฉ", "ุชุนุฏูู ูุนุจุฉ", "cheat", "hack"]): | |
| analysis.update({ | |
| "intent": "game_hacking", | |
| "requires_task": True, | |
| "requires_research": True, | |
| "task_type": "game_hacking", | |
| "category": "game_hacking", | |
| "research_query": f"game hacking {self._extract_game_name(message)} techniques tools", | |
| "complexity": "high", | |
| "estimated_steps": 8 | |
| }) | |
| elif any(word in message_lower for word in ["ุจูุช", "ุชุทููุฑ ุจูุช", "ุจุฑู ุฌุฉ ุจูุช", "bot", "automation"]): | |
| analysis.update({ | |
| "intent": "bot_development", | |
| "requires_task": True, | |
| "requires_research": True, | |
| "task_type": "bot_development", | |
| "category": "bot_development", | |
| "research_query": f"bot development {self._extract_bot_type(message)} python automation", | |
| "complexity": "high", | |
| "estimated_steps": 7 | |
| }) | |
| elif any(word in message_lower for word in ["ููุฏุณุฉ ุนูุณูุฉ", "reverse engineering", "ุชุญููู ู ูู", "ุชูููู"]): | |
| analysis.update({ | |
| "intent": "reverse_engineering", | |
| "requires_task": True, | |
| "requires_research": True, | |
| "task_type": "reverse_engineering", | |
| "category": "reverse_engineering", | |
| "research_query": "reverse engineering tools techniques binary analysis", | |
| "complexity": "very_high", | |
| "estimated_steps": 10 | |
| }) | |
| elif any(word in message_lower for word in ["ุงุจุญุซ", "ุจุญุซ", "ู ุนููู ุงุช", "ุงุนุฑู ุนู", "research"]): | |
| analysis.update({ | |
| "intent": "research", | |
| "requires_research": True, | |
| "research_query": message, | |
| "complexity": "medium", | |
| "estimated_steps": 3 | |
| }) | |
| return analysis | |
| def _extract_game_name(self, message: str) -> str: | |
| """ุงุณุชุฎุฑุงุฌ ุงุณู ุงููุนุจุฉ ู ู ุงูุฑุณุงูุฉ""" | |
| games = ["genshin impact", "minecraft", "among us", "valorant", "fortnite", "call of duty", "cyberpunk"] | |
| for game in games: | |
| if game in message.lower(): | |
| return game | |
| return "game" | |
| def _extract_bot_type(self, message: str) -> str: | |
| """ุงุณุชุฎุฑุงุฌ ููุน ุงูุจูุช ู ู ุงูุฑุณุงูุฉ""" | |
| if any(word in message.lower() for word in ["ู ุฒุฑุนุฉ", "farming", "agriculture"]): | |
| return "farming" | |
| elif any(word in message.lower() for word in ["ูุชุงู", "combat", "battle"]): | |
| return "combat" | |
| elif any(word in message.lower() for word in ["ุชุฌู ูุน", "collection", "gathering"]): | |
| return "collection" | |
| return "automation" | |
| def _build_task_structure(self, analysis: Dict, client_id: str, user_message: str) -> Dict: | |
| """ุจูุงุก ูููู ุงูู ูู ุฉ ุงูู ุนูุฏุฉ""" | |
| task_templates = { | |
| "game_hacking": { | |
| "title": f"ู ูู ุฉ ุชูููุฑ ุงููุนุจุฉ - {datetime.now().strftime('%Y-%m-%d %H:%M')}", | |
| "steps": [ | |
| {"step": 1, "action_type": "research", "description": "ุงูุจุญุซ ุนู ุฃุฏูุงุช ูุทุฑู ุชูููุฑ ุงููุนุจุฉ"}, | |
| {"step": 2, "action_type": "install_tools", "description": "ุชุซุจูุช Cheat Engine ูุฃุฏูุงุช ุงูุฐุงูุฑุฉ"}, | |
| {"step": 3, "action_type": "analyze_game", "description": "ุชุญููู ุจููุฉ ุงูุฐุงูุฑุฉ ููุนุจุฉ"}, | |
| {"step": 4, "action_type": "scan_memory", "description": "ู ุณุญ ุงูุฐุงูุฑุฉ ููุนุซูุฑ ุนูู ุงูููู ุงูู ุทููุจุฉ"}, | |
| {"step": 5, "action_type": "develop_script", "description": "ุชุทููุฑ ุณูุฑูุจุช ุงูุชุนุฏูู"}, | |
| {"step": 6, "action_type": "test_hack", "description": "ุงุฎุชุจุงุฑ ุงูุชุนุฏููุงุช ุนูู ุงููุนุจุฉ"}, | |
| {"step": 7, "action_type": "optimize", "description": "ุชุญุณูู ุงูุฃุฏุงุก ูุฅุถุงูุฉ ู ูุฒุงุช"}, | |
| {"step": 8, "action_type": "deliver", "description": "ุชุณููู ุงููุชุงุฆุฌ ุงูููุงุฆูุฉ"} | |
| ] | |
| }, | |
| "bot_development": { | |
| "title": f"ุชุทููุฑ ุจูุช ุฐูู - {datetime.now().strftime('%Y-%m-%d %H:%M')}", | |
| "steps": [ | |
| {"step": 1, "action_type": "analyze_requirements", "description": "ุชุญููู ู ุชุทูุจุงุช ุงูุจูุช"}, | |
| {"step": 2, "action_type": "install_python", "description": "ุชุซุจูุช Python ูุงูู ูุชุจุงุช ุงูู ุทููุจุฉ"}, | |
| {"step": 3, "action_type": "develop_core", "description": "ุชุทููุฑ ุงููุธุงุฆู ุงูุฃุณุงุณูุฉ ููุจูุช"}, | |
| {"step": 4, "action_type": "implement_vision", "description": "ุชูููุฐ ูุธุงู ุงูุชุนุฑู ุนูู ุงูุตูุฑ"}, | |
| {"step": 5, "action_type": "add_automation", "description": "ุฅุถุงูุฉ ูุธุงู ุงูุฃุชู ุชุฉ"}, | |
| {"step": 6, "action_type": "test_bot", "description": "ุงุฎุชุจุงุฑ ุงูุจูุช ูู ุจูุฆุฉ ุญููููุฉ"}, | |
| {"step": 7, "action_type": "optimize", "description": "ุชุญุณูู ุงูุฃุฏุงุก ูุฅุถุงูุฉ ุงูุฐูุงุก"} | |
| ] | |
| } | |
| } | |
| template = task_templates.get(analysis["task_type"], { | |
| "title": f"ู ูู ุฉ: {user_message[:50]}...", | |
| "steps": [ | |
| {"step": 1, "action_type": "execute", "description": "ุชูููุฐ ุงูู ูู ุฉ ุงูู ุทููุจุฉ"} | |
| ] | |
| }) | |
| return { | |
| "client_id": client_id, | |
| "title": template["title"], | |
| "description": user_message, | |
| "task_type": analysis["task_type"], | |
| "steps": template["steps"], | |
| "parameters": analysis | |
| } | |
| async def _generate_comprehensive_response(self, user_message: str, analysis: Dict, task: Optional[Dict], research_data: Optional[Dict], client_id: str) -> Dict: | |
| """ุชูููุฏ ุฑุฏ ุดุงู ู ู ุน ูู ุงูู ุนููู ุงุช""" | |
| if task: | |
| response_message = self._generate_task_response(analysis, task, research_data) | |
| actions = self._generate_execution_actions(task, analysis) | |
| else: | |
| response_message = self._generate_research_response(user_message, analysis, research_data) | |
| actions = [] | |
| return { | |
| "thinking_process": self._format_detailed_thinking(analysis, research_data, task), | |
| "message": response_message, | |
| "actions": actions, | |
| "task_id": task["id"] if task else None, | |
| "requires_execution": task is not None, | |
| "research_data": research_data | |
| } | |
| def _generate_task_response(self, analysis: Dict, task: Dict, research_data: Optional[Dict]) -> str: | |
| """ุชูููุฏ ุฑุฏ ููู ูุงู ุงูู ุนูุฏุฉ""" | |
| response_templates = { | |
| "game_hacking": f""" | |
| ๐ฎ **ุจุฏุก ู ูู ุฉ ุชูููุฑ ู ุชูุฏู ุฉ** | |
| โ **ุงูู ูู ุฉ:** {task['title']} | |
| ๐ง **ุงูููุน:** ุชูููุฑ ูุนุจุฉ ู ุชูุงู ู | |
| ๐ **ุงูุชุนููุฏ:** {analysis['complexity']} | |
| ๐ข **ุงูุฎุทูุงุช:** {len(task['steps'])} ุฎุทูุฉ | |
| โฑ๏ธ **ุงูููุช ุงูู ุชููุน:** {len(task['steps']) * 2} ุฏูููุฉ | |
| **ุฎุทูุงุช ุงูุชูููุฐ:** | |
| {chr(10).join(['โข ' + step['description'] for step in task['steps']])} | |
| **ุงูุฃุฏูุงุช ุงูู ุณุชุฎุฏู ุฉ:** | |
| {chr(10).join(['โข ' + tool for tool in research_data.get('tools_recommendations', [])[:3]]) if research_data else 'โข Cheat Engine โข Python โข ุฃุฏูุงุช ุงูุฐุงูุฑุฉ'} | |
| ๐ **ุจุฏุฃ ุงูุชูููุฐ ุงูุชููุงุฆู... ุณุฃููู ุจุชูููุฐ ุฌู ูุน ุงูุฎุทูุงุช ุญุชู ุงูููุงูุฉ!** | |
| """, | |
| "bot_development": f""" | |
| ๐ค **ุจุฏุก ู ูู ุฉ ุชุทููุฑ ุจูุช ู ุชูุฏู ** | |
| โ **ุงูู ูู ุฉ:** {task['title']} | |
| ๐ง **ุงูููุน:** ุชุทููุฑ ุจูุช ุฐูู | |
| ๐ **ุงูุชุนููุฏ:** {analysis['complexity']} | |
| ๐ข **ุงูุฎุทูุงุช:** {len(task['steps'])} ุฎุทูุฉ | |
| โฑ๏ธ **ุงูููุช ุงูู ุชููุน:** {len(task['steps']) * 3} ุฏูููุฉ | |
| **ุฎุทูุงุช ุงูุชูููุฐ:** | |
| {chr(10).join(['โข ' + step['description'] for step in task['steps']])} | |
| **ุงูุชูููุงุช ุงูู ุณุชุฎุฏู ุฉ:** | |
| {chr(10).join(['โข ' + tech for tech in research_data.get('expert_knowledge', {}).get('techniques', [])[:3]]) if research_data else 'โข OpenCV โข PyAutoGUI โข ุงูุฐูุงุก ุงูุงุตุทูุงุนู'} | |
| ๐ **ุจุฏุฃ ุงูุชูููุฐ ุงูุชููุงุฆู... ุณุฃุทูุฑ ุงูุจูุช ุฎุทูุฉ ุจุฎุทูุฉ!** | |
| """ | |
| } | |
| return response_templates.get(analysis["task_type"], f""" | |
| โ **ุจุฏุก ุงูู ูู ุฉ ุงูุชูููุฐูุฉ** | |
| **ุงูู ูู ุฉ:** {task['title']} | |
| **ุงููุตู:** {task['description']} | |
| **ุงูุฎุทูุงุช:** {len(task['steps'])} ุฎุทูุฉ | |
| ๐ **ุจุฏุฃ ุงูุชูููุฐ ุงูุชููุงุฆู... ุณุฃููุฐ ุงูู ูู ุฉ ุญุชู ุงูููุงูุฉ!** | |
| """) | |
| def _generate_research_response(self, user_message: str, analysis: Dict, research_data: Optional[Dict]) -> str: | |
| """ุชูููุฏ ุฑุฏ ููุจุญุซ ูุงูู ุนููู ุงุช""" | |
| if research_data: | |
| return f""" | |
| ๐ **ูุชุงุฆุฌ ุงูุจุญุซ ุงูู ุชูุฏู ** | |
| **ุงูุงุณุชุนูุงู :** "{user_message}" | |
| **ุงูู ุนููู ุงุช ุงูู ุชุฎุตุตุฉ:** | |
| {chr(10).join(['โข ' + tool for tool in research_data.get('tools_recommendations', [])[:5]])} | |
| **ุงูุทุฑู ูุงูุชูููุงุช:** | |
| {chr(10).join(['โข ' + tech for tech in research_data.get('expert_knowledge', {}).get('techniques', [])[:3]]) if research_data.get('expert_knowledge') else 'โข ุชูููุงุช ู ุชูุฏู ุฉ ูู ุงูู ุฌุงู'} | |
| **ุฏููู ุงูุชูููุฐ:** | |
| {chr(10).join(['โข ' + step for step in research_data.get('step_by_step_guide', [])[:3]])} | |
| ๐ก **ูู ุชุฑูุฏ ุฃู ุฃููุฐ ูุฐู ุงูู ูู ุฉ ููุ ููุท ูู "ููุฐ" ูุณุฃุจุฏุฃ ููุฑุงู!** | |
| """ | |
| return f""" | |
| ๐ค **ุงูู ุณุงุนุฏ ุงูุฐูู ุงูู ุชูุงู ู** | |
| ู ุฑุญุจุงู! ุฃูุง ุงููุธุงู ุงูุฐูู ุงูุญูููู ุงูู ุชุฎุตุต ูู: | |
| ๐ฎ **ุชูููุฑ ุงูุฃูุนุงุจ ุงูู ุชูุฏู ** - ุชุนุฏูู ุงูุฐุงูุฑุฉุ ุชุทููุฑ ุงูุณูุฑูุจุชุงุชุ ููุฏุณุฉ ุงูุนูุณ | |
| ๐ค **ุชุทููุฑ ุงูุจูุชุงุช ุงูุฐููุฉ** - ุฃุชู ุชุฉุ ุฑุคูุฉ ุญุงุณูุจูุฉุ ุฐูุงุก ุงุตุทูุงุนู | |
| ๐ง **ุงูููุฏุณุฉ ุงูุนูุณูุฉ** - ุชุญููู ุงูู ููุงุชุ ุงูุชุดุงู ุงูุซุบุฑุงุชุ ุชุทููุฑ ุงูุงุณุชุบูุงู | |
| ๐ **ุงูุจุญุซ ุงูู ุชูุฏู ** - ู ุนููู ุงุช ุญููููุฉุ ุฃุฏูุงุช ุญุฏูุซุฉุ ุชูููุงุช ู ุชุทูุฑุฉ | |
| ๐ช **ู ู ูุฒุงุชู:** | |
| - โ ุฐุงูุฑุฉ ุญููููุฉ ุทูููุฉ ุงูู ุฏู | |
| - โ ุชูููุฐ ู ูุงู ู ุชุนุฏุฏุฉ ุงูุฎุทูุงุช ุชููุงุฆูุงู | |
| - โ ุจุญุซ ุญูููู ุนูู ุงูุฅูุชุฑูุช | |
| - โ ุชูุงู ู ูุงู ู ู ุน ุฌูุงุฒู | |
| - โ ุนู ู ู ุณุชู ุฑ ุญุชู ุฅูู ุงู ุงูู ูู ุฉ | |
| ๐ **ู ุง ุงูู ูู ุฉ ุงูุชู ุชุฑูุฏูู ุฃู ุฃููุฐูุงุ** | |
| """ | |
| def _generate_execution_actions(self, task: Dict, analysis: Dict) -> List[Dict]: | |
| """ุชูููุฏ ุฅุฌุฑุงุกุงุช ุชูููุฐูุฉ ุญููููุฉ""" | |
| base_actions = { | |
| "game_hacking": [ | |
| { | |
| "type": "install_tools", | |
| "tools": ["cheat_engine", "python", "memory_scanner"], | |
| "description": "ุชุซุจูุช ุฃุฏูุงุช ุงูุชุนุฏูู ุงูุฃุณุงุณูุฉ", | |
| "priority": "high", | |
| "automatic": True | |
| }, | |
| { | |
| "type": "analyze_target", | |
| "description": "ุจุฏุก ุชุญููู ุงููุนุจุฉ ุงูู ุณุชูุฏูุฉ", | |
| "priority": "high", | |
| "automatic": True | |
| }, | |
| { | |
| "type": "develop_solution", | |
| "description": "ุชุทููุฑ ุญู ุงูุชุนุฏูู ุงูู ูุงุณุจ", | |
| "priority": "high", | |
| "automatic": True | |
| } | |
| ], | |
| "bot_development": [ | |
| { | |
| "type": "setup_environment", | |
| "description": "ุฅุนุฏุงุฏ ุจูุฆุฉ ุงูุชุทููุฑ Python", | |
| "priority": "high", | |
| "automatic": True | |
| }, | |
| { | |
| "type": "develop_bot_core", | |
| "description": "ุชุทููุฑ ุงูููุงุฉ ุงูุฃุณุงุณูุฉ ููุจูุช", | |
| "priority": "high", | |
| "automatic": True | |
| }, | |
| { | |
| "type": "implement_features", | |
| "description": "ุชูููุฐ ุงูู ูุฒุงุช ุงูู ุทููุจุฉ", | |
| "priority": "medium", | |
| "automatic": True | |
| } | |
| ] | |
| } | |
| return base_actions.get(analysis["task_type"], [ | |
| { | |
| "type": "execute_task", | |
| "description": "ุชูููุฐ ุงูู ูู ุฉ ุงูู ุทููุจุฉ", | |
| "priority": "high", | |
| "automatic": True | |
| } | |
| ]) | |
| def _format_detailed_thinking(self, analysis: Dict, research_data: Optional[Dict], task: Optional[Dict]) -> str: | |
| """ุชูุณูู ุนู ููุฉ ุงูุชูููุฑ ุงูุชูุตูููุฉ""" | |
| thinking = f""" | |
| ๐ง **ุนู ููุฉ ุงูุชูููุฑ ุงูู ุชูุงู ูุฉ:** | |
| ๐ **ุงูููุฉ:** {analysis['intent']} | |
| โก **ุงูุนุฌูุฉ:** {analysis['urgency']} | |
| ๐ **ุงูุชุนููุฏ:** {analysis['complexity']} | |
| ๐ข **ุงูุฎุทูุงุช ุงูู ุชููุนุฉ:** {analysis['estimated_steps']} | |
| ๐ **ุงูุณูุงู ุงูุชุงุฑูุฎู:** {analysis['historical_context']} ู ุญุงุฏุซุฉ ุณุงุจูุฉ | |
| """ | |
| if research_data: | |
| thinking += f"๐ **ุงูุจุญุซ:** {len(research_data.get('web_results', []))} ูุชูุฌุฉ ููุจ + ู ุนุฑูุฉ ู ุชุฎุตุตุฉ\n" | |
| if task: | |
| thinking += f"โ **ุงููุฑุงุฑ:** ุฅูุดุงุก ู ูู ุฉ ุชูููุฐูุฉ ({task['id']})\n" | |
| thinking += f"๐ **ุงูุฅุฌุฑุงุก:** ุจุฏุก ุงูุชูููุฐ ุงูุชููุงุฆู ({len(task['steps'])} ุฎุทูุฉ)\n" | |
| thinking += "โฑ๏ธ **ุงูู ุฏุฉ:** ุชูููุฐ ู ุณุชู ุฑ ุญุชู ุงูุฅูู ุงู\n" | |
| else: | |
| thinking += "๐ฌ **ุงููุฑุงุฑ:** ุชูููุฑ ู ุนููู ุงุช ูุจุญุซ ู ุชูุฏู \n" | |
| thinking += "๐ **ุงูุฅุฌุฑุงุก:** ุงูุชุธุงุฑ ุชุฃููุฏ ุงูุชูููุฐ\n" | |
| thinking += f"๐พ **ุงูุฐุงูุฑุฉ:** ุญูุธ ูุงู ู ูู ูุงุนุฏุฉ ุงูุจูุงูุงุช\n" | |
| thinking += f"๐ **ุงูููุช:** {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}" | |
| return thinking | |
| def _store_complete_memory(self, client_id: str, user_message: str, response: Dict, analysis: Dict): | |
| """ุชุฎุฒูู ูุงู ู ูู ุงูุฐุงูุฑุฉ ููุงุนุฏุฉ ุงูุจูุงูุงุช""" | |
| memory_data = { | |
| "id": str(uuid.uuid4()), | |
| "client_id": client_id, | |
| "user_message": user_message, | |
| "assistant_message": response["message"], | |
| "intent": analysis["intent"], | |
| "timestamp": datetime.now().isoformat(), | |
| "important": analysis["requires_task"] or analysis["requires_research"] | |
| } | |
| # ุญูุธ ูู ูุงุนุฏุฉ ุงูุจูุงูุงุช | |
| self.db.save_conversation(memory_data) | |
| # ุญูุธ ูู ุงูุฐุงูุฑุฉ ุงูู ุคูุชุฉ | |
| if client_id not in self.conversation_memory: | |
| self.conversation_memory[client_id] = [] | |
| self.conversation_memory[client_id].append(memory_data) | |
| # ๐ฅ ุชููุฆุฉ ุงููุธุงู ุงูู ุชูุงู ู | |
| integrated_assistant = IntegratedAIAssistant() | |
| # ๐ฅ ููุงุท ุงูููุงูุฉ ุงูุญููููุฉ | |
| async def real_chat_endpoint(request: ChatRequest): | |
| """ููุทุฉ ุงูููุงูุฉ ุงูุฑุฆูุณูุฉ ููู ุญุงุฏุซุฉ ุงูุฐููุฉ ุงูุญููููุฉ""" | |
| try: | |
| logger.info(f"๐ฌ ุฑุณุงูุฉ ุญููููุฉ ู ู {request.client_id}: {request.message}") | |
| result = await integrated_assistant.process_real_request( | |
| request.message, | |
| request.client_id | |
| ) | |
| response = ChatResponse(**result) | |
| return response | |
| except Exception as e: | |
| logger.error(f"โ ุฎุทุฃ ุญูููู: {e}") | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| async def get_real_tasks(client_id: str): | |
| """ุงูุญุตูู ุนูู ุงูู ูุงู ุงูุญููููุฉ ููุนู ูู""" | |
| conn = sqlite3.connect('real_system.db') | |
| cursor = conn.cursor() | |
| cursor.execute(''' | |
| SELECT * FROM tasks WHERE client_id = ? ORDER BY created_at DESC | |
| ''', (client_id,)) | |
| tasks = cursor.fetchall() | |
| conn.close() | |
| return { | |
| "tasks": [{ | |
| "id": task[0], | |
| "client_id": task[1], | |
| "title": task[2], | |
| "description": task[3], | |
| "task_type": task[4], | |
| "status": task[5], | |
| "current_step": task[6], | |
| "total_steps": task[7], | |
| "created_at": task[8], | |
| "updated_at": task[9] | |
| } for task in tasks] | |
| } | |
| async def real_system_status(): | |
| """ุญุงูุฉ ุงููุธุงู ุงูุญูููู""" | |
| conn = sqlite3.connect('real_system.db') | |
| cursor = conn.cursor() | |
| cursor.execute('SELECT COUNT(*) FROM tasks') | |
| total_tasks = cursor.fetchone()[0] | |
| cursor.execute('SELECT COUNT(*) FROM conversations') | |
| total_conversations = cursor.fetchone()[0] | |
| cursor.execute('SELECT COUNT(*) FROM tasks WHERE status = "executing"') | |
| active_tasks = cursor.fetchone()[0] | |
| conn.close() | |
| return { | |
| "status": "๐ข ูุธุงู ุญูููู ูุนู ู", | |
| "system": "ุงููุธุงู ุงูุฐูู ุงูุญูููู ุงูู ุชูุงู ู", | |
| "version": "4.0 - ุงูุฅุตุฏุงุฑ ุงูููุงุฆู", | |
| "active_tasks": active_tasks, | |
| "total_tasks": total_tasks, | |
| "total_conversations": total_conversations, | |
| "database": "SQLite - ุชุฎุฒูู ุญูููู", | |
| "research_engine": "ู ุชูุฏู - ุจุญุซ ุญูููู", | |
| "task_manager": "ุชูููุฐ ุชููุงุฆู ู ุณุชู ุฑ", | |
| "timestamp": datetime.now().isoformat() | |
| } | |
| async def root(): | |
| return { | |
| "status": "๐ข ูุธุงู ุญูููู ู ุชูุงู ู ูุนู ู", | |
| "service": "ุงููุธุงู ุงูุฐูู ุงูุญูููู - ุงูุฅุตุฏุงุฑ ุงูููุงุฆู", | |
| "description": "ูุธุงู ู ุชูุงู ู ุญูููู ูุชูููุฑ ุงูุฃูุนุงุจุ ุชุทููุฑ ุงูุจูุชุงุชุ ูุงูููุฏุณุฉ ุงูุนูุณูุฉ", | |
| "features": [ | |
| "ุฐุงูุฑุฉ ุญููููุฉ ุทูููุฉ ุงูู ุฏู (SQLite)", | |
| "ุจุญุซ ู ุชูุฏู ุญูููู ุนูู ุงูุฅูุชุฑูุช", | |
| "ุชูููุฐ ู ูุงู ุชููุงุฆู ู ุณุชู ุฑ", | |
| "ููุฏุณุฉ ุนูุณูุฉ ุญููููุฉ ููู ููุงุช", | |
| "ุชุทููุฑ ุจูุชุงุช ุจุฃููุงุฏ Python ุญููููุฉ", | |
| "ุชูุงู ู ูุงู ู ู ุน ุฌูุงุฒ ุงูู ุณุชุฎุฏู " | |
| ], | |
| "version": "4.0", | |
| "timestamp": datetime.now().isoformat() | |
| } | |
| if __name__ == "__main__": | |
| import uvicorn | |
| port = int(os.getenv("PORT", 7860)) | |
| uvicorn.run(app, host="0.0.0.0", port=port) |