MrA7A's picture
Update app.py
d4a36ab verified
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()
# ๐Ÿ”ฅ ู†ู‚ุงุท ุงู„ู†ู‡ุงูŠุฉ ุงู„ุญู‚ูŠู‚ูŠุฉ
@app.post("/api/chat")
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))
@app.get("/api/tasks/{client_id}")
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]
}
@app.get("/api/system/real-status")
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()
}
@app.get("/")
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)