Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
242 lines (192 loc) · 7.05 KB
/
Copy pathmain.py
File metadata and controls
242 lines (192 loc) · 7.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/usr/bin/env python3
"""
main.py — Entry point para AXIOM.
Uso:
python main.py → Servidor web (FastAPI + WebSocket)
python main.py cli → Terminal interactivo
python main.py telegram → Bot de Telegram
python main.py all → Web + Telegram en paralelo
python main.py --help → Ayuda
"""
import sys
import os
import asyncio
from pathlib import Path
os.chdir(Path(__file__).parent)
def print_help():
print("""
AXIOM — Agente con Propósito Autónomo
======================================
Uso:
python main.py Servidor web en http://localhost:8000
python main.py cli Terminal interactivo (requiere rich)
python main.py telegram Bot de Telegram (configura token en config.yaml)
python main.py all Web + Telegram en paralelo
python main.py --help Esta ayuda
Configuración : config.yaml
SOUL : soul/SOUL.md
Memoria : data/memory.db
Workspace : workspace/
Notas : data/notes/
Primeros pasos:
1. ollama serve && ollama pull llama3.2
2. pip install -r requirements.txt
3. python main.py
""")
def _load_config():
from core.agent import load_config
return load_config("config.yaml")
def run_server():
import uvicorn
config = _load_config()
host = config["api"]["host"]
port = config["api"]["port"]
print(f"""
✦ AXIOM — Servidor Web
────────────────────────────────────
Web UI → http://localhost:{port}
REST → http://localhost:{port}/chat
SOUL → http://localhost:{port}/soul
Tools → http://localhost:{port}/tools
Health → http://localhost:{port}/health
────────────────────────────────────
Modelo : {config['model']['name']} @ {config['model']['base_url']}
Reflexión: cada {config['agent']['reflection_every_n_turns']} turnos
────────────────────────────────────
""")
uvicorn.run(
"api.server:app",
host=host,
port=port,
reload=False,
log_level="warning"
)
def run_cli():
from cli.chat import run_cli as _run_cli
asyncio.run(_run_cli())
async def run_telegram_async(agent=None):
config = _load_config()
tg_cfg = config.get("telegram", {})
token = tg_cfg.get("token", "").strip()
if not token:
print("""
✦ Bot de Telegram — Configuración requerida
────────────────────────────────────────────
1. Crea un bot con @BotFather en Telegram → obtendrás un TOKEN
2. Habla con @userinfobot para obtener tu CHAT_ID
3. Edita config.yaml:
telegram:
token: "123456789:ABC..."
owner_chat_id: 987654321 ← tu chat_id (recibe notificaciones)
allowed_users: [987654321] ← quién puede chatear (vacío = todos)
4. Vuelve a correr: python main.py telegram
""")
return
from core.agent import Agent
from tgbot.bot import AxiomTelegramBot
if agent is None:
agent = Agent()
owner = tg_cfg.get("owner_chat_id") or None
allowed = tg_cfg.get("allowed_users") or []
interval = float(tg_cfg.get("stream_update_interval", 0.8))
if owner == 0:
owner = None
bot = AxiomTelegramBot(
token=token,
agent=agent,
allowed_users=allowed,
owner_chat_id=owner,
stream_update_interval=interval
)
# Attach voice pipeline if enabled
voice_cfg = config.get("voice", {})
if voice_cfg.get("stt", {}).get("enabled", False):
try:
from voice.stt import get_stt
from voice.tts import get_tts
from voice.pipeline import VoicePipeline
stt_cfg = voice_cfg.get("stt", {})
tts_cfg = voice_cfg.get("tts", {})
stt = get_stt(
model_size=stt_cfg.get("model", "base"),
language=stt_cfg.get("language")
)
tts_enabled_cfg = tts_cfg.get("enabled", True)
tts = get_tts(
backend=tts_cfg.get("backend", "auto") if tts_enabled_cfg else "silent",
edge_voice=tts_cfg.get("edge_voice", "es-VE-SebastianNeural"),
macos_voice=tts_cfg.get("macos_voice", "Paulina")
)
pipeline = VoicePipeline(agent=agent, stt_engine=stt, tts_engine=tts)
bot.set_voice_pipeline(pipeline)
print(f" 🎙 Voice pipeline activo | STT: {stt_cfg.get('model','base')} | TTS: {tts.backend_name}")
except Exception as e:
print(f" ⚠ Voice pipeline no disponible: {e}")
print(f"""
✦ AXIOM — Bot de Telegram
────────────────────────────────────
Agente : {agent.name}
Modelo : {agent.model_name}
Owner ID : {owner or 'no configurado'}
Whitelist: {allowed or 'abierto (todos)'}
────────────────────────────────────
Iniciando polling...
""")
await bot.run()
def run_telegram():
asyncio.run(run_telegram_async())
async def run_all_async():
"""Run web server + Telegram bot concurrently."""
import uvicorn
from core.agent import Agent
config = _load_config()
host = config["api"]["host"]
port = config["api"]["port"]
# Shared agent instance
agent = Agent()
# Inject shared agent into FastAPI server
import api.server as srv
srv.agent = agent
print(f"""
✦ AXIOM — Modo completo (Web + Telegram)
────────────────────────────────────────
Web UI → http://localhost:{port}
Telegram → polling activo
Agente : {agent.name} (instancia compartida)
────────────────────────────────────────
""")
tg_cfg = config.get("telegram", {})
token = tg_cfg.get("token", "").strip()
tasks = []
# Web server task
uvi_config = uvicorn.Config(
"api.server:app",
host=host, port=port,
reload=False, log_level="warning"
)
server = uvicorn.Server(uvi_config)
tasks.append(asyncio.create_task(server.serve()))
# Telegram task (only if token configured)
if token:
tasks.append(asyncio.create_task(run_telegram_async(agent=agent)))
else:
print(" ⚠ Telegram no configurado — solo modo web activo.")
await asyncio.gather(*tasks)
def run_all():
asyncio.run(run_all_async())
def main():
args = sys.argv[1:]
if "--help" in args or "-h" in args:
print_help()
return
mode = args[0] if args else "server"
if mode == "cli":
run_cli()
elif mode == "telegram":
run_telegram()
elif mode == "all":
run_all()
else:
run_server()
if __name__ == "__main__":
main()