From 80b856cdc3dbcd53442dbd753e61273b6584f52b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 26 Jan 2024 17:36:51 +0000 Subject: [PATCH 01/10] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20=F0=9F=9B=A0?= =?UTF-8?q?=EF=B8=8F(deps):=20update=20dependency=20cefi=20to=20v3.3.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 5ce44bd66..930e1d63e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,7 +55,7 @@ talkytrend = "1.15.9" iamlistening = "4.2.35" findmyorder = "1.9.10" dxsp = "7.0.7" -cefi = "3.2.45" +cefi = "3.3.0" myllm = "4.0.2" ib_insync = "0.9.86" From 150aa6227ab9cc04c5247cf5114725be309f1024 Mon Sep 17 00:00:00 2001 From: mraniki <8766259+mraniki@users.noreply.github.com> Date: Fri, 26 Jan 2024 18:55:07 +0100 Subject: [PATCH 02/10] =?UTF-8?q?=F0=9F=94=A5=20remove=20llm=20export=20ch?= =?UTF-8?q?at?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_llm_plugin.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/test_llm_plugin.py b/tests/test_llm_plugin.py index 74f842629..4050188bc 100644 --- a/tests/test_llm_plugin.py +++ b/tests/test_llm_plugin.py @@ -16,6 +16,7 @@ def set_test_settings(): def test_fixture_plugin(): return LlmPlugin() + @pytest.mark.asyncio async def test_plugin(plugin): """Test message handling""" @@ -24,9 +25,6 @@ async def test_plugin(plugin): 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 @@ -65,7 +63,7 @@ async def test_parsing_info(plugin): @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 @@ -79,7 +77,7 @@ async def test_llm_chat(plugin): 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 From 095933b15da6b8b39a6e86c9e723a63295b44669 Mon Sep 17 00:00:00 2001 From: mraniki <8766259+mraniki@users.noreply.github.com> Date: Fri, 26 Jan 2024 18:57:17 +0100 Subject: [PATCH 03/10] =?UTF-8?q?=F0=9F=94=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default_plugins/broker_IBKR_plugin.py | 202 ------------------ tt/plugins/default_plugins/llm_plugin.py | 7 +- tt/talky_settings.toml | 1 + 3 files changed, 4 insertions(+), 206 deletions(-) delete mode 100644 tt/plugins/default_plugins/broker_IBKR_plugin.py 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..ae625e30b 100644 --- a/tt/plugins/default_plugins/llm_plugin.py +++ b/tt/plugins/default_plugins/llm_plugin.py @@ -4,6 +4,7 @@ """ import os import threading + from myllm import MyLLM from tt.config import settings @@ -33,7 +34,6 @@ 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): @@ -45,7 +45,6 @@ async def handle_message(self, msg): ): threading.Thread(target=self.process_chat, args=(msg,)).start() - if msg.startswith(settings.bot_prefix): command, *args = msg.split(" ") command = command[1:] @@ -62,5 +61,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..1ba737a5c 100644 --- a/tt/talky_settings.toml +++ b/tt/talky_settings.toml @@ -336,6 +336,7 @@ token_personal_list = "https://raw.githubusercontent.com/mraniki/tokenlist/main/ ################################### ### AI MYLLM SETTINGS ### ################################### +myllm_enabled = true [default.myllm.template] enabled = true From 1dd40c5579299a18b27a2d9324ceb042314955cc Mon Sep 17 00:00:00 2001 From: mraniki <8766259+mraniki@users.noreply.github.com> Date: Fri, 26 Jan 2024 19:09:25 +0100 Subject: [PATCH 04/10] =?UTF-8?q?=F0=9F=94=A5=20removeing=20AImode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_llm_plugin.py | 1 - tt/plugins/default_plugins/llm_plugin.py | 13 ++++++------- tt/talky_settings.toml | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/tests/test_llm_plugin.py b/tests/test_llm_plugin.py index 4050188bc..ae65f5d87 100644 --- a/tests/test_llm_plugin.py +++ b/tests/test_llm_plugin.py @@ -70,7 +70,6 @@ async def test_info(plugin): @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) diff --git a/tt/plugins/default_plugins/llm_plugin.py b/tt/plugins/default_plugins/llm_plugin.py index ae625e30b..830dd67e6 100644 --- a/tt/plugins/default_plugins/llm_plugin.py +++ b/tt/plugins/default_plugins/llm_plugin.py @@ -3,7 +3,6 @@ """ import os -import threading from myllm import MyLLM @@ -38,12 +37,12 @@ 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(" ") diff --git a/tt/talky_settings.toml b/tt/talky_settings.toml index 1ba737a5c..2ed42fc42 100644 --- a/tt/talky_settings.toml +++ b/tt/talky_settings.toml @@ -337,7 +337,7 @@ token_personal_list = "https://raw.githubusercontent.com/mraniki/tokenlist/main/ ### AI MYLLM SETTINGS ### ################################### myllm_enabled = true - +llm_ai_mode = false [default.myllm.template] enabled = true llm_model= "gpt_4" From 4f53a99a020d2738ff53d4e759c6ec7f14af489e Mon Sep 17 00:00:00 2001 From: mraniki <8766259+mraniki@users.noreply.github.com> Date: Fri, 26 Jan 2024 19:10:08 +0100 Subject: [PATCH 05/10] =?UTF-8?q?=F0=9F=94=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tt/talky_settings.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tt/talky_settings.toml b/tt/talky_settings.toml index 2ed42fc42..5b3f1a818 100644 --- a/tt/talky_settings.toml +++ b/tt/talky_settings.toml @@ -338,7 +338,7 @@ token_personal_list = "https://raw.githubusercontent.com/mraniki/tokenlist/main/ ################################### myllm_enabled = true llm_ai_mode = false -[default.myllm.template] +[default.myllm.g4f] enabled = true llm_model= "gpt_4" llm_provider = "g4f.Provider.Bing" # Refer to https://github.com/xtekky/gpt4free From 4e88385325a26f796c23ca4e0a98dfed57d8337f Mon Sep 17 00:00:00 2001 From: mraniki <8766259+mraniki@users.noreply.github.com> Date: Fri, 26 Jan 2024 19:29:41 +0100 Subject: [PATCH 06/10] =?UTF-8?q?=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- tt/plugins/default_plugins/llm_plugin.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 930e1d63e..83fe99356 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,7 +56,7 @@ iamlistening = "4.2.35" findmyorder = "1.9.10" dxsp = "7.0.7" cefi = "3.3.0" -myllm = "4.0.2" +myllm = "4.0.3" ib_insync = "0.9.86" [tool.poetry.group.dev.dependencies] diff --git a/tt/plugins/default_plugins/llm_plugin.py b/tt/plugins/default_plugins/llm_plugin.py index 830dd67e6..d8c799ea4 100644 --- a/tt/plugins/default_plugins/llm_plugin.py +++ b/tt/plugins/default_plugins/llm_plugin.py @@ -49,8 +49,8 @@ async def handle_message(self, msg): 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_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)), From fe1a37609454e58d5ab945b7e16585bd134529d8 Mon Sep 17 00:00:00 2001 From: mraniki <8766259+mraniki@users.noreply.github.com> Date: Fri, 26 Jan 2024 19:55:04 +0100 Subject: [PATCH 07/10] =?UTF-8?q?=F0=9F=94=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tt/plugins/default_plugins/llm_plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tt/plugins/default_plugins/llm_plugin.py b/tt/plugins/default_plugins/llm_plugin.py index d8c799ea4..cea6c4985 100644 --- a/tt/plugins/default_plugins/llm_plugin.py +++ b/tt/plugins/default_plugins/llm_plugin.py @@ -51,7 +51,7 @@ async def handle_message(self, msg): command_mapping = { 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_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)), } From 3f2778dd4c5e6318163d7b2d857ff6b91bc45620 Mon Sep 17 00:00:00 2001 From: mraniki <8766259+mraniki@users.noreply.github.com> Date: Fri, 26 Jan 2024 20:11:21 +0100 Subject: [PATCH 08/10] =?UTF-8?q?=F0=9F=90=9B=20=E2=9C=85=20Unit=20Test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_llm_plugin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_llm_plugin.py b/tests/test_llm_plugin.py index ae65f5d87..e2756769d 100644 --- a/tests/test_llm_plugin.py +++ b/tests/test_llm_plugin.py @@ -23,7 +23,6 @@ async def test_plugin(plugin): 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) From 7422f20e0492f65e792fdd8fb02dd28dd7de2cbf Mon Sep 17 00:00:00 2001 From: mraniki Date: Fri, 26 Jan 2024 20:29:35 +0100 Subject: [PATCH 09/10] Refactor test_llm_plugin.py to use get_info instead of get_myllm_info --- tests/test_llm_plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_llm_plugin.py b/tests/test_llm_plugin.py index e2756769d..c22f71cf3 100644 --- a/tests/test_llm_plugin.py +++ b/tests/test_llm_plugin.py @@ -54,9 +54,9 @@ 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 From a1218093bc59a1553d18ec6ba98d3bac81b441e3 Mon Sep 17 00:00:00 2001 From: mraniki Date: Fri, 26 Jan 2024 20:30:52 +0100 Subject: [PATCH 10/10] Update myllm version to 4.0.4 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 83fe99356..7ba66d18c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,7 +56,7 @@ iamlistening = "4.2.35" findmyorder = "1.9.10" dxsp = "7.0.7" cefi = "3.3.0" -myllm = "4.0.3" +myllm = "4.0.4" ib_insync = "0.9.86" [tool.poetry.group.dev.dependencies]