84 lines
3.5 KiB
Python
84 lines
3.5 KiB
Python
import os, sys
|
|
import config
|
|
|
|
from services.xmpp_client import XMPPClient
|
|
|
|
from scripts.llm_client import LLMClient
|
|
from tools import coder, rag, carrack
|
|
from scripts import gadget
|
|
from scripts.persona import build_system_prompt, PERSONALITY, MODE
|
|
|
|
tools_definition = [
|
|
|
|
gadget.tools_mapping( schema = coder.schema_read_file, handler = coder.read_file ),
|
|
gadget.tools_mapping( schema = coder.schema_write_file, handler = coder.write_file ),
|
|
gadget.tools_mapping( schema = coder.schema_edit_file, handler = coder.edit_file ),
|
|
gadget.tools_mapping( schema = coder.schema_run_bash, handler = coder.run_bash ),
|
|
gadget.tools_mapping( schema = coder.schema_search_code, handler = coder.search_code ),
|
|
gadget.tools_mapping( schema = coder.schema_git_operation, handler = coder.git_operation ),
|
|
|
|
gadget.tools_mapping( schema = rag.schema_ingest_files, handler = rag.ingest_files ),
|
|
gadget.tools_mapping( schema = rag.schema_store_knowledge, handler = rag.store_knowledge ),
|
|
gadget.tools_mapping( schema = rag.schema_search_knowledge, handler = rag.search_knowledge ),
|
|
gadget.tools_mapping( schema = rag.schema_create_collection, handler = rag.create_collection ),
|
|
gadget.tools_mapping( schema = rag.schema_delete_collection, handler = rag.delete_collection ),
|
|
gadget.tools_mapping( schema = rag.schema_list_collections, handler = rag.list_collections ),
|
|
gadget.tools_mapping( schema = rag.schema_inspect_collection, handler = rag.inspect_collection ),
|
|
|
|
gadget.tools_mapping( schema = carrack.schema_sendhttprequest, handler = carrack.sendhttprequest ),
|
|
|
|
]
|
|
|
|
TOOLS = gadget.tool_schemas (tools_definition)
|
|
TOOL_HANDLERS = gadget.tool_handlers (tools_definition)
|
|
|
|
def main():
|
|
llm_client = LLMClient(config.llm_baseurl, config.llm_model, config.llm_api_key, config.llm_timeout)
|
|
|
|
workspace = None
|
|
i = 1
|
|
while i < len(sys.argv):
|
|
if sys.argv[i] in ('-w', '--workspace') and i + 1 < len(sys.argv):
|
|
workspace = sys.argv[i + 1]
|
|
i += 2
|
|
else:
|
|
i += 1
|
|
|
|
if workspace:
|
|
resolved = os.path.abspath(workspace)
|
|
if not os.path.isdir(resolved):
|
|
print(f"Error: '{resolved}' is not a valid directory")
|
|
sys.exit(1)
|
|
os.chdir(resolved)
|
|
|
|
if config.XMPP_ENABLED:
|
|
muc_rooms = []
|
|
if config.XMPP_MUC_ROOMS.strip():
|
|
muc_rooms = [r.strip() for r in config.XMPP_MUC_ROOMS.split(',') if r.strip()]
|
|
client = XMPPClient(
|
|
jid = config.XMPP_USERNAME,
|
|
password = config.XMPP_PASSWORD,
|
|
llm_client = llm_client,
|
|
tools_definition = tools_definition,
|
|
TOOLS = TOOLS,
|
|
TOOL_HANDLERS = TOOL_HANDLERS,
|
|
build_system_prompt = build_system_prompt,
|
|
agent_max_iterations = config.AGENT_MAX_ITERATIONS,
|
|
muc_rooms = muc_rooms,
|
|
)
|
|
client.start()
|
|
else:
|
|
from tui import HendrikTUI
|
|
HendrikTUI(
|
|
llm_client = llm_client,
|
|
tools_definition = tools_definition,
|
|
TOOLS = TOOLS,
|
|
TOOL_HANDLERS = TOOL_HANDLERS,
|
|
build_system_prompt = build_system_prompt,
|
|
agent_max_iterations = config.AGENT_MAX_ITERATIONS,
|
|
).run()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|