From 02b84fb519c853cee0a7765b475371d9eb59cf60 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Mon, 26 Feb 2024 10:59:18 +0100 Subject: Improve filter_messages in gui Add rdns suport for proxies --- g4f/gui/client/html/index.html | 1 - g4f/gui/client/js/chat.v1.js | 19 +++++++++++++++---- g4f/providers/helper.py | 6 +++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/g4f/gui/client/html/index.html b/g4f/gui/client/html/index.html index 102a762e..9ef8a820 100644 --- a/g4f/gui/client/html/index.html +++ b/g4f/gui/client/html/index.html @@ -173,7 +173,6 @@ - diff --git a/g4f/gui/client/js/chat.v1.js b/g4f/gui/client/js/chat.v1.js index c727dbf9..edd27689 100644 --- a/g4f/gui/client/js/chat.v1.js +++ b/g4f/gui/client/js/chat.v1.js @@ -121,6 +121,20 @@ const remove_cancel_button = async () => { }; const filter_messages = (messages) => { + // Removes none user messages at end + let last_message; + while (last_message = new_messages.pop()) { + if (last_message["role"] == "user") { + new_messages.push(last_message); + break; + } + } + + // Remove history, if it is selected + if (document.getElementById('history')?.checked) { + messages = [messages[messages.length-1]]; + } + let new_messages = []; for (i in messages) { new_message = messages[i]; @@ -135,6 +149,7 @@ const filter_messages = (messages) => { new_messages.push(new_message) } } + return new_messages; } @@ -143,10 +158,6 @@ const ask_gpt = async () => { messages = await get_messages(window.conversation_id); total_messages = messages.length; - // Remove history, if it is selected - if (document.getElementById('history')?.checked) { - messages = [messages[messages.length-1]]; - } messages = filter_messages(messages); window.scrollTo(0, 0); diff --git a/g4f/providers/helper.py b/g4f/providers/helper.py index 49d033d1..6981f984 100644 --- a/g4f/providers/helper.py +++ b/g4f/providers/helper.py @@ -55,7 +55,11 @@ def get_connector(connector: BaseConnector = None, proxy: str = None) -> Optiona if proxy and not connector: try: from aiohttp_socks import ProxyConnector - connector = ProxyConnector.from_url(proxy) + rdns = False + if proxy.startswith("socks5h://"): + proxy = proxy.replace("socks5h://", "socks5://") + rdns = True + connector = ProxyConnector.from_url(proxy, rdns=rdns) except ImportError: raise MissingRequirementsError('Install "aiohttp_socks" package for proxy support') return connector \ No newline at end of file -- cgit v1.2.3