WilliamRabuel commited on
Commit
d860bb9
·
verified ·
1 Parent(s): 4ff7b57

Create config.py

Browse files
Files changed (1) hide show
  1. config.py +177 -0
config.py ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Configuration centralisée pour l'UltraAgent
3
+ """
4
+ import os
5
+ from typing import Dict, Any, Optional
6
+
7
+ class AgentConfig:
8
+ """Configuration centralisée pour l'agent"""
9
+
10
+ # Modèles HuggingFace
11
+ ORCHESTRATOR_MODEL = "moonshotai/Kimi-K2-Instruct"
12
+ CODE_AGENT_MODEL = "moonshotai/Kimi-K2-Instruct"
13
+ VISION_MODEL = "Qwen/Qwen2.5-VL-72B-Instruct"
14
+ REASONING_MODEL = "deepseek-ai/DeepSeek-R1-0528"
15
+
16
+ # Configuration des timeouts (en secondes)
17
+ DEFAULT_TIMEOUT = 120
18
+ VISION_TIMEOUT = 180
19
+ REASONING_TIMEOUT = 180
20
+ WEB_REQUEST_TIMEOUT = 30
21
+
22
+ # Paramètres des modèles
23
+ DEFAULT_MAX_TOKENS = 4096
24
+ VISION_MAX_TOKENS = 2048
25
+ REASONING_MAX_TOKENS = 8192
26
+
27
+ # Températures des modèles
28
+ ORCHESTRATOR_TEMPERATURE = 0.1
29
+ CODE_TEMPERATURE = 0.0
30
+ VISION_TEMPERATURE = 0.1
31
+ REASONING_TEMPERATURE = 0.2
32
+
33
+ # Limites de sécurité
34
+ MAX_SEARCH_RESULTS = 15
35
+ MAX_SCRAPED_CONTENT_LENGTH = 10000
36
+ MAX_FILE_SIZE_MB = 50
37
+ MAX_CONVERSATION_HISTORY = 50
38
+
39
+ # Configuration des outils web
40
+ SEARCH_REGION = "fr-fr"
41
+ MAX_LINKS_PER_PAGE = 50
42
+
43
+ # Headers pour les requêtes web
44
+ DEFAULT_HEADERS = {
45
+ 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
46
+ 'Accept-Language': 'fr-FR,fr;q=0.9,en;q=0.8',
47
+ 'Accept-Encoding': 'gzip, deflate',
48
+ 'Connection': 'keep-alive',
49
+ 'Upgrade-Insecure-Requests': '1',
50
+ }
51
+
52
+ # Configuration Selenium
53
+ SELENIUM_OPTIONS = [
54
+ "--headless",
55
+ "--no-sandbox",
56
+ "--disable-dev-shm-usage",
57
+ "--disable-gpu",
58
+ "--window-size=1920,1080",
59
+ "--disable-blink-features=AutomationControlled",
60
+ "--disable-extensions",
61
+ "--disable-plugins",
62
+ ]
63
+
64
+ @classmethod
65
+ def get_hf_token(cls) -> Optional[str]:
66
+ """Récupère le token HuggingFace depuis les variables d'environnement"""
67
+ return os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_TOKEN")
68
+
69
+ @classmethod
70
+ def get_model_config(cls, model_type: str) -> Dict[str, Any]:
71
+ """Retourne la configuration pour un type de modèle donné"""
72
+ configs = {
73
+ "orchestrator": {
74
+ "model": cls.ORCHESTRATOR_MODEL,
75
+ "max_tokens": cls.DEFAULT_MAX_TOKENS,
76
+ "temperature": cls.ORCHESTRATOR_TEMPERATURE,
77
+ "timeout": cls.DEFAULT_TIMEOUT
78
+ },
79
+ "code_agent": {
80
+ "model": cls.CODE_AGENT_MODEL,
81
+ "max_tokens": cls.DEFAULT_MAX_TOKENS,
82
+ "temperature": cls.CODE_TEMPERATURE,
83
+ "timeout": cls.DEFAULT_TIMEOUT
84
+ },
85
+ "vision": {
86
+ "model": cls.VISION_MODEL,
87
+ "max_tokens": cls.VISION_MAX_TOKENS,
88
+ "temperature": cls.VISION_TEMPERATURE,
89
+ "timeout": cls.VISION_TIMEOUT
90
+ },
91
+ "reasoning": {
92
+ "model": cls.REASONING_MODEL,
93
+ "max_tokens": cls.REASONING_MAX_TOKENS,
94
+ "temperature": cls.REASONING_TEMPERATURE,
95
+ "timeout": cls.REASONING_TIMEOUT
96
+ }
97
+ }
98
+
99
+ return configs.get(model_type, configs["orchestrator"])
100
+
101
+ @classmethod
102
+ def validate_environment(cls) -> Dict[str, Any]:
103
+ """Valide l'environnement et retourne un rapport"""
104
+ report = {
105
+ "status": "ok",
106
+ "warnings": [],
107
+ "errors": [],
108
+ "environment": {}
109
+ }
110
+
111
+ # Vérifie le token HF
112
+ hf_token = cls.get_hf_token()
113
+ if not hf_token:
114
+ report["errors"].append("Token HuggingFace manquant (HF_TOKEN ou HUGGINGFACE_TOKEN)")
115
+ report["status"] = "error"
116
+ else:
117
+ report["environment"]["hf_token"] = "✅ Présent"
118
+
119
+ # Vérifie les variables d'environnement optionnelles
120
+ space_id = os.getenv("SPACE_ID")
121
+ space_host = os.getenv("SPACE_HOST")
122
+
123
+ if space_id:
124
+ report["environment"]["space_id"] = space_id
125
+ else:
126
+ report["warnings"].append("SPACE_ID non défini (mode local?)")
127
+
128
+ if space_host:
129
+ report["environment"]["space_host"] = space_host
130
+ else:
131
+ report["warnings"].append("SPACE_HOST non défini (mode local?)")
132
+
133
+ # Vérifie les imports critiques
134
+ try:
135
+ import smolagents
136
+ report["environment"]["smolagents"] = f"✅ v{smolagents.__version__}"
137
+ except ImportError:
138
+ report["errors"].append("smolagents non installé")
139
+ report["status"] = "error"
140
+
141
+ try:
142
+ import requests
143
+ report["environment"]["requests"] = "✅ Disponible"
144
+ except ImportError:
145
+ report["errors"].append("requests non installé")
146
+ report["status"] = "error"
147
+
148
+ # Avertissements si status n'est que warnings
149
+ if report["warnings"] and report["status"] == "ok":
150
+ report["status"] = "warning"
151
+
152
+ return report
153
+
154
+ @classmethod
155
+ def get_debug_info(cls) -> Dict[str, Any]:
156
+ """Retourne les informations de debug"""
157
+ return {
158
+ "models": {
159
+ "orchestrator": cls.ORCHESTRATOR_MODEL,
160
+ "code_agent": cls.CODE_AGENT_MODEL,
161
+ "vision": cls.VISION_MODEL,
162
+ "reasoning": cls.REASONING_MODEL
163
+ },
164
+ "timeouts": {
165
+ "default": cls.DEFAULT_TIMEOUT,
166
+ "vision": cls.VISION_TIMEOUT,
167
+ "reasoning": cls.REASONING_TIMEOUT,
168
+ "web_request": cls.WEB_REQUEST_TIMEOUT
169
+ },
170
+ "limits": {
171
+ "max_search_results": cls.MAX_SEARCH_RESULTS,
172
+ "max_scraped_content": cls.MAX_SCRAPED_CONTENT_LENGTH,
173
+ "max_file_size_mb": cls.MAX_FILE_SIZE_MB,
174
+ "max_conversation_history": cls.MAX_CONVERSATION_HISTORY
175
+ },
176
+ "environment_validation": cls.validate_environment()
177
+ }