diff --git a/pyproject.toml b/pyproject.toml index 5ce44bd66..7ba66d18c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,8 +55,8 @@ talkytrend = "1.15.9" iamlistening = "4.2.35" findmyorder = "1.9.10" dxsp = "7.0.7" -cefi = "3.2.45" -myllm = "4.0.2" +cefi = "3.3.0" +myllm = "4.0.4" ib_insync = "0.9.86" [tool.poetry.group.dev.dependencies] diff --git a/tests/test_llm_plugin.py b/tests/test_llm_plugin.py index 74f842629..c22f71cf3 100644 --- a/tests/test_llm_plugin.py +++ b/tests/test_llm_plugin.py @@ -16,17 +16,14 @@ def set_test_settings(): def test_fixture_plugin(): return LlmPlugin() + @pytest.mark.asyncio async def test_plugin(plugin): """Test message handling""" await plugin.handle_message(f"{settings.bot_prefix}{settings.bot_command_question}") assert plugin.should_handle("any message") is True assert plugin.llm is not None - assert plugin.llm.provider is not None assert callable(plugin.llm.chat) - assert callable(plugin.llm.switch_continous_mode) - assert callable(plugin.llm.clear_chat_history) - assert callable(plugin.llm.export_chat_history) @pytest.mark.asyncio @@ -57,29 +54,28 @@ async def test_parsing_llm(plugin): @pytest.mark.asyncio async def test_parsing_info(plugin): """Test info""" - plugin.llm.get_myllm_info = AsyncMock() + plugin.llm.get_info = AsyncMock() await plugin.handle_message(f"{settings.bot_prefix}{settings.bot_command_info}") - plugin.llm.get_myllm_info.assert_awaited_once() + plugin.llm.get_info.assert_awaited_once() @pytest.mark.asyncio async def test_info(plugin): """Test info""" - result = await plugin.llm.get_myllm_info() + result = await plugin.llm.get_info() assert result is not None @pytest.mark.asyncio async def test_llm_chat(plugin): """Test llm""" - print(plugin.llm.provider) result = await plugin.llm.chat("tell me a story") sleep(20) print(result) assert result is not None -@pytest.mark.asyncio -async def test_clear_chat_history(plugin): - result = plugin.llm.export_chat_history() - assert result is not None +# @pytest.mark.asyncio +# async def test_clear_chat_history(plugin): +# result = plugin.llm.export_chat_history() +# assert result is not None diff --git a/tt/plugins/default_plugins/broker_IBKR_plugin.py b/tt/plugins/default_plugins/broker_IBKR_plugin.py deleted file mode 100644 index 598f76079..000000000 --- a/tt/plugins/default_plugins/broker_IBKR_plugin.py +++ /dev/null @@ -1,202 +0,0 @@ -# plugin being added to CEFI library instead - -# import os - -# from findmyorder import FindMyOrder -# from ib_insync import IB, Forex, Order - -# from tt.config import logger, settings -# from tt.plugins.plugin_manager import BasePlugin -# from tt.utils import send_notification - - -# class Broker_IBKR_Plugin(BasePlugin): -# """ -# Support IBKR Broker via BrokerExchange object - -# Order are identified and parsed using Findmyorder lib -# More info: https://github.com/mraniki/findmyorder - -# Args: -# None - -# Returns: -# None - -# """ - -# name = os.path.splitext(os.path.basename(__file__))[0] - -# def __init__(self): -# super().__init__() -# self.enabled = settings.broker_enabled -# if self.enabled: -# self.fmo = FindMyOrder() -# self.exchange = BrokerExchange() - -# async def start(self): -# """Starts the broker_plugin plugin""" - -# async def stop(self): -# """Stops the broker_plugin plugin""" - -# async def send_notification(self, message): -# """Sends a notification""" -# if self.enabled: -# await send_notification(message) - -# async def handle_message(self, msg): -# """ -# Handles incoming messages -# to route to the respective function - -# Args: -# msg (str): The incoming message - -# Returns: -# None - -# """ -# if not self.should_handle(msg): -# return -# logger.debug("settings.bot_ignore: {}", settings.bot_ignore) -# if settings.bot_ignore not in msg or settings.bot_prefix not in msg: -# if await self.fmo.search(msg): -# order = await self.fmo.get_order(msg) -# if order and settings.trading_enabled: -# trade = await self.exchange.submit_order(order) -# if trade: -# await send_notification(trade) - -# if msg.startswith(settings.bot_prefix): -# command, *args = msg.split(" ") -# command = command[1:] - -# command_mapping = { -# settings.bot_command_info: self.exchange.get_info, -# settings.bot_command_quote: lambda: self.exchange.get_quote(args[0]), -# settings.bot_command_bal: self.exchange.get_balance, -# settings.bot_command_pos: self.exchange.get_position, -# } - -# if command in command_mapping: -# function = command_mapping[command] -# await self.send_notification(f"{await function()}") - - -# class BrokerExchange: -# """ -# Class BrokerExchange to support IBKR Broker -# built via ib_insync library -# More info: https://github.com/erdewit/ib_insync - -# """ - -# def __init__(self): -# """ -# Initializes the Broker_IBKR_Plugin class. - -# This function creates an instance of the IB class from the ib_insync -# library and sets it as the 'ib' attribute of the class. -# It also sets the 'client' attribute to None as a placeholder -# for actual client details. - -# To connect to the Interactive Brokers (IBKR) platform, -# the 'connect' method of the 'ib' instance is called. -# This method requires the host, port, and clientId as parameters. -# In this case, the function connects to the IBKR platform using -# the IP address "127.0.0.1", port 7497, and clientId 1. - -# After successfully connecting to IBKR, the function logs -# a debug message using the logger module. - -# Parameters: -# - None - -# Return Type: -# - None -# """ -# self.ib = IB() -# self.ib.connect( -# host=settings.broker_host or "127.0.0.1", -# port=settings.broker_port or 7497, -# clientId=settings.broker_clientId or 1, -# readonly=settings.broker_read_only or False, -# account=settings.broker_account_number or "", -# ) - -# logger.debug("Connected to IBKR {}", self.ib.isConnected()) -# self.account = self.ib.managedAccounts()[0] -# logger.debug("Broker_IBKR_Plugin initialized with account: {}", self.account) - -# def get_info(self): -# """ -# Retrieves information from the accountValues method of the `ib` object. - -# Returns: -# The result of calling the accountValues method of the `ib` object. -# """ -# return self.ib.accountValues() - -# def get_quote(self, symbol): -# """ -# Retrieves a quote for a given symbol from the Interactive Brokers API. - -# Args: -# symbol (str): The symbol of the forex contract. - -# Returns: -# ticker: The ticker representing the quote for the given symbol. -# """ -# contract = Forex(symbol, "SMART", "USD") -# self.ib.reqMktData(contract) -# return self.ib.ticker(contract) - -# def get_balance(self): -# """ -# Get the balance of the account. - -# Returns: -# The balance of the account. -# """ -# return self.ib.accountSummary(self.account) - -# def get_position(self): -# """ -# Get the position of the current object. -# :return: A list of positions. -# """ -# return self.ib.positions() - -# def submit_order(self, order_details): -# """ -# Submit an order to the trading platform. - -# Parameters: -# order_details (dict): A dictionary containing the details of the order. -# - instrument (str): The instrument to trade. -# - action (str): The action to perform, either 'BUY' or 'SELL'. -# - order_type (str, optional): The type of order. Defaults to 'MKT'. -# - quantity (int): The quantity of the order. - -# Returns: -# trade: The result of the order placement. - -# Raises: -# RuntimeError: If the order submission fails. - -# """ -# try: -# # todo: add support for limit price -# # todo: add support for multiple contract type -# contract = Forex(order_details["instrument"], "SMART", "USD") -# # Create an Order object -# order = Order() -# order.action = order_details["action"] # 'BUY' or 'SELL' -# order.orderType = order_details["order_type"] or "MKT" -# order.totalQuantity = order_details["quantity"] - -# return self.ib.placeOrder(contract, order) -# except Exception as e: -# logger.error(f"Order submission failed: {e}") -# return None diff --git a/tt/plugins/default_plugins/llm_plugin.py b/tt/plugins/default_plugins/llm_plugin.py index cf85aa9cf..cea6c4985 100644 --- a/tt/plugins/default_plugins/llm_plugin.py +++ b/tt/plugins/default_plugins/llm_plugin.py @@ -3,7 +3,7 @@ """ import os -import threading + from myllm import MyLLM from tt.config import settings @@ -33,27 +33,25 @@ async def send_notification(self, message): if self.enabled: await send_notification(message) - async def handle_message(self, msg): """Handles incoming messages""" if not self.should_handle(msg): return - if ( - self.llm.llm_ai_mode - and (settings.bot_ignore not in msg) - and (not msg.startswith(settings.bot_prefix)) - ): - threading.Thread(target=self.process_chat, args=(msg,)).start() - + # if ( + # self.llm.llm_ai_mode + # and (settings.bot_ignore not in msg) + # and (not msg.startswith(settings.bot_prefix)) + # ): + # threading.Thread(target=self.process_chat, args=(msg,)).start() if msg.startswith(settings.bot_prefix): command, *args = msg.split(" ") command = command[1:] command_mapping = { - settings.bot_command_info: self.llm.get_myllm_info, - settings.bot_command_aimode: self.llm.switch_continous_mode, - settings.bot_command_aiclear: self.llm.clear_chat_history, + settings.bot_command_info: self.llm.get_info, + # settings.bot_command_aimode: self.llm.switch_continous_mode, + # settings.bot_command_aiclear: self.llm.clear_chat_history, settings.bot_command_aiexport: self.llm.export_chat_history, settings.bot_command_aichat: lambda: self.llm.chat(str(args)), } @@ -62,5 +60,5 @@ async def handle_message(self, msg): await self.send_notification(f"{await function()}") def process_chat(self, msg): - chat = self.llm.chat(str(msg)) - self.send_notification(chat) \ No newline at end of file + chat = self.llm.chat(str(msg)) + self.send_notification(chat) diff --git a/tt/talky_settings.toml b/tt/talky_settings.toml index 65072a20c..5b3f1a818 100644 --- a/tt/talky_settings.toml +++ b/tt/talky_settings.toml @@ -336,8 +336,9 @@ token_personal_list = "https://raw.githubusercontent.com/mraniki/tokenlist/main/ ################################### ### AI MYLLM SETTINGS ### ################################### - -[default.myllm.template] +myllm_enabled = true +llm_ai_mode = false +[default.myllm.g4f] enabled = true llm_model= "gpt_4" llm_provider = "g4f.Provider.Bing" # Refer to https://github.com/xtekky/gpt4free