Cleanup refactor
This commit is contained in:
parent
28bd27f79c
commit
059445de5e
16
hendrik.py
16
hendrik.py
@ -2,16 +2,15 @@ import os, sys, threading, time, signal
|
|||||||
|
|
||||||
import config
|
import config
|
||||||
|
|
||||||
from tools import coder, rag, carrack
|
from tools import coder, rag, carrack
|
||||||
|
|
||||||
from services.xmpp_client import XMPPClient
|
from services.xmpp_client import XMPPClient
|
||||||
from services.telegram_client import TelegramClient
|
from services.telegram_client import TelegramClient
|
||||||
|
|
||||||
from services.llm_client import LLMClient
|
from services.llm_client import LLMClient
|
||||||
from scripts.personality import build_system_prompt
|
|
||||||
from scripts import gadget
|
|
||||||
|
|
||||||
from tui import HendrikTUI
|
from lib import gadget, personality
|
||||||
|
|
||||||
|
from interfaces.tui import HendrikTUI
|
||||||
|
|
||||||
tools_definition = [
|
tools_definition = [
|
||||||
|
|
||||||
@ -37,7 +36,6 @@ tools_definition = [
|
|||||||
TOOLS = gadget.tool_schemas (tools_definition)
|
TOOLS = gadget.tool_schemas (tools_definition)
|
||||||
TOOL_HANDLERS = gadget.tool_handlers (tools_definition)
|
TOOL_HANDLERS = gadget.tool_handlers (tools_definition)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
llm_client = LLMClient(config.llm_baseurl, config.llm_model, config.llm_api_key, config.llm_timeout)
|
llm_client = LLMClient(config.llm_baseurl, config.llm_model, config.llm_api_key, config.llm_timeout)
|
||||||
|
|
||||||
@ -69,7 +67,7 @@ def main():
|
|||||||
tools_definition = tools_definition,
|
tools_definition = tools_definition,
|
||||||
TOOLS = TOOLS,
|
TOOLS = TOOLS,
|
||||||
TOOL_HANDLERS = TOOL_HANDLERS,
|
TOOL_HANDLERS = TOOL_HANDLERS,
|
||||||
build_system_prompt = build_system_prompt,
|
build_system_prompt = personality.build_system_prompt,
|
||||||
agent_max_iterations = config.AGENT_MAX_ITERATIONS,
|
agent_max_iterations = config.AGENT_MAX_ITERATIONS,
|
||||||
muc_rooms = muc_rooms,
|
muc_rooms = muc_rooms,
|
||||||
)
|
)
|
||||||
@ -86,7 +84,7 @@ def main():
|
|||||||
tools_definition = tools_definition,
|
tools_definition = tools_definition,
|
||||||
TOOLS = TOOLS,
|
TOOLS = TOOLS,
|
||||||
TOOL_HANDLERS = TOOL_HANDLERS,
|
TOOL_HANDLERS = TOOL_HANDLERS,
|
||||||
build_system_prompt = build_system_prompt,
|
build_system_prompt = personality.build_system_prompt,
|
||||||
agent_max_iterations = config.AGENT_MAX_ITERATIONS,
|
agent_max_iterations = config.AGENT_MAX_ITERATIONS,
|
||||||
allowed_group_ids = allowed_ids,
|
allowed_group_ids = allowed_ids,
|
||||||
)
|
)
|
||||||
@ -124,7 +122,7 @@ def main():
|
|||||||
tools_definition = tools_definition,
|
tools_definition = tools_definition,
|
||||||
TOOLS = TOOLS,
|
TOOLS = TOOLS,
|
||||||
TOOL_HANDLERS = TOOL_HANDLERS,
|
TOOL_HANDLERS = TOOL_HANDLERS,
|
||||||
build_system_prompt = build_system_prompt,
|
build_system_prompt = personality.build_system_prompt,
|
||||||
agent_max_iterations = config.AGENT_MAX_ITERATIONS,
|
agent_max_iterations = config.AGENT_MAX_ITERATIONS,
|
||||||
).run()
|
).run()
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import json
|
|||||||
import threading
|
import threading
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import config
|
import config
|
||||||
from scripts import ntro, agent_loop
|
from lib import ntro, agent_loop
|
||||||
|
|
||||||
|
|
||||||
def _add_msg(app, role, content, **kwargs):
|
def _add_msg(app, role, content, **kwargs):
|
||||||
@ -1,5 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
from scripts import gadget
|
from lib import gadget
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import urllib.error
|
import urllib.error
|
||||||
|
|
||||||
|
|||||||
@ -7,8 +7,8 @@ from datetime import datetime
|
|||||||
|
|
||||||
import config
|
import config
|
||||||
from services.session_manager import SessionManager
|
from services.session_manager import SessionManager
|
||||||
from scripts.agent_loop import run_agent_loop
|
from lib.agent_loop import run_agent_loop
|
||||||
from scripts.personality import PERSONALITY
|
from lib import personality
|
||||||
from tools.roleplayer import _name_mentioned
|
from tools.roleplayer import _name_mentioned
|
||||||
|
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ class TelegramClient:
|
|||||||
has_mention = True
|
has_mention = True
|
||||||
break
|
break
|
||||||
|
|
||||||
name_mentioned = _name_mentioned(PERSONALITY.name, text)
|
name_mentioned = _name_mentioned(personality.PERSONALITY.name, text)
|
||||||
|
|
||||||
if not replied_to_bot and not has_mention and not name_mentioned:
|
if not replied_to_bot and not has_mention and not name_mentioned:
|
||||||
print(f'[{_ts()}] Telegram Group [{chat_id}] NO-REPLY: {text[:60]}', flush=True)
|
print(f'[{_ts()}] Telegram Group [{chat_id}] NO-REPLY: {text[:60]}', flush=True)
|
||||||
|
|||||||
@ -6,11 +6,11 @@ from datetime import datetime
|
|||||||
|
|
||||||
from slixmpp import ClientXMPP
|
from slixmpp import ClientXMPP
|
||||||
from services.session_manager import SessionManager
|
from services.session_manager import SessionManager
|
||||||
from scripts.agent_loop import run_agent_loop
|
from lib.agent_loop import run_agent_loop
|
||||||
|
|
||||||
import config
|
import config
|
||||||
from tools.roleplayer import should_respond
|
from tools.roleplayer import should_respond
|
||||||
from scripts.personality import PERSONALITY
|
from lib import personality
|
||||||
|
|
||||||
# Anti-ban: delay constants for MUC rejoin behavior
|
# Anti-ban: delay constants for MUC rejoin behavior
|
||||||
MUC_REJOIN_INITIAL_DELAY = 5.0 # detik, delay awal sebelum rejoin
|
MUC_REJOIN_INITIAL_DELAY = 5.0 # detik, delay awal sebelum rejoin
|
||||||
@ -306,7 +306,7 @@ class XMPPClient(ClientXMPP):
|
|||||||
if self._loop and not self._loop.is_closed():
|
if self._loop and not self._loop.is_closed():
|
||||||
asyncio.run_coroutine_threadsafe(_read_delay(), self._loop)
|
asyncio.run_coroutine_threadsafe(_read_delay(), self._loop)
|
||||||
|
|
||||||
my_name = PERSONALITY.name
|
my_name = personality.PERSONALITY.name
|
||||||
quote = body
|
quote = body
|
||||||
|
|
||||||
def on_tool_calls(tnames):
|
def on_tool_calls(tnames):
|
||||||
@ -384,7 +384,7 @@ class XMPPClient(ClientXMPP):
|
|||||||
if self._loop and not self._loop.is_closed():
|
if self._loop and not self._loop.is_closed():
|
||||||
asyncio.run_coroutine_threadsafe(_read_delay(), self._loop)
|
asyncio.run_coroutine_threadsafe(_read_delay(), self._loop)
|
||||||
|
|
||||||
my_name = PERSONALITY.name
|
my_name = personality.PERSONALITY.name
|
||||||
quote = f'[{nick}] {body}'
|
quote = f'[{nick}] {body}'
|
||||||
|
|
||||||
def on_tool_calls(tnames):
|
def on_tool_calls(tnames):
|
||||||
@ -436,7 +436,7 @@ class XMPPClient(ClientXMPP):
|
|||||||
session.start_timer(300, self._timeout_session, room, 'groupchat')
|
session.start_timer(300, self._timeout_session, room, 'groupchat')
|
||||||
|
|
||||||
def _execute_tool(self, tool_call):
|
def _execute_tool(self, tool_call):
|
||||||
from scripts.agent_loop import execute_tool
|
from lib.agent_loop import execute_tool
|
||||||
return execute_tool(tool_call, self._TOOL_HANDLERS)
|
return execute_tool(tool_call, self._TOOL_HANDLERS)
|
||||||
|
|
||||||
def _schedule_send(self, to, body, mtype='chat'):
|
def _schedule_send(self, to, body, mtype='chat'):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user