monra commited on
Commit
6b32ba0
β€’
1 Parent(s): 69d9c5f

Remove auto-proxy to migrate it to a standalone project

Browse files
Files changed (5) hide show
  1. README.md +2 -19
  2. client/.DS_Store +0 -0
  3. config.json +1 -2
  4. server/auto_proxy.py +0 -103
  5. server/backend.py +12 -20
README.md CHANGED
@@ -7,7 +7,7 @@ This project features a WebUI utilizing the [G4F API](https://github.com/xtekky/
7
  Experience the power of ChatGPT with a user-friendly interface, enhanced jailbreaks, and completely free.
8
 
9
  ## Known bugs 🚧
10
- - Auto Proxy is not working.
11
 
12
  _Coding to solve as quickly as possible_
13
 
@@ -28,8 +28,6 @@ Please note that the choice and integration of additional Providers are the user
28
  - [Cloning the Repository](#cloning-the-repository-inbox_tray)
29
  - [Install Dependencies](#install-dependencies-wrench)
30
  - [Running the Application](#running-the-application-rocket)
31
- - [Auto Proxy](#auto-proxy-)
32
- - [Enable Auto Proxy](#enable-auto-proxy)
33
  - [Docker](#docker-)
34
  - [Prerequisites](#prerequisites)
35
  - [Running the Docker](#running-the-docker)
@@ -49,9 +47,8 @@ Please note that the choice and integration of additional Providers are the user
49
  - [x] Add the GPT-4 model
50
  - [x] Enhance the user interface
51
  - [ ] Check status of API Providers (online/offline)
52
- - [ ] Auto Proxy
53
  - [ ] Enable editing and creating Jailbreaks/Roles in the WebUI
54
- - [ ] Migrate the interface to React.js (?)
55
 
56
  ## Getting Started :white_check_mark:
57
  To get started with this project, you'll need to clone the repository and have [Python](https://www.python.org/downloads/) installed on your system.
@@ -87,20 +84,6 @@ or
87
  ```
88
  http://localhost:1338
89
  ```
90
- ## Auto Proxy πŸ”‘
91
- The application includes an auto proxy feature that allows it to work with multiple free proxy servers.
92
- The freeGPT API refuses some connections, especially when hosted in the cloud (Azure, AWS, Google Cloud).
93
- Auto proxy solves this problem automatically for you.
94
- When enabled, the application will automatically fetch and test proxy servers, updating the list of working proxies every 30 minutes.
95
-
96
- ### Enable Auto Proxy
97
- To enable it, just go to the `config.json` file and change the value of the "use_auto_proxy" to `true`.
98
-
99
- ```
100
- "use_auto_proxy": true
101
- ```
102
- ![use-auto-proxy-gif](https://github.com/ramonvc/gptfree-webui/assets/13617054/f83c6217-411c-404c-9f4c-8ae700a486d1)
103
-
104
 
105
 
106
  ## Docker 🐳
 
7
  Experience the power of ChatGPT with a user-friendly interface, enhanced jailbreaks, and completely free.
8
 
9
  ## Known bugs 🚧
10
+ - GPT-4 model offline.
11
 
12
  _Coding to solve as quickly as possible_
13
 
 
28
  - [Cloning the Repository](#cloning-the-repository-inbox_tray)
29
  - [Install Dependencies](#install-dependencies-wrench)
30
  - [Running the Application](#running-the-application-rocket)
 
 
31
  - [Docker](#docker-)
32
  - [Prerequisites](#prerequisites)
33
  - [Running the Docker](#running-the-docker)
 
47
  - [x] Add the GPT-4 model
48
  - [x] Enhance the user interface
49
  - [ ] Check status of API Providers (online/offline)
 
50
  - [ ] Enable editing and creating Jailbreaks/Roles in the WebUI
51
+ - [ ] Refactor web client
52
 
53
  ## Getting Started :white_check_mark:
54
  To get started with this project, you'll need to clone the repository and have [Python](https://www.python.org/downloads/) installed on your system.
 
84
  ```
85
  http://localhost:1338
86
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
 
89
  ## Docker 🐳
client/.DS_Store DELETED
Binary file (6.15 kB)
 
config.json CHANGED
@@ -3,6 +3,5 @@
3
  "host": "0.0.0.0",
4
  "port": 1338,
5
  "debug": false
6
- },
7
- "use_auto_proxy": false
8
  }
 
3
  "host": "0.0.0.0",
4
  "port": 1338,
5
  "debug": false
6
+ }
 
7
  }
server/auto_proxy.py DELETED
@@ -1,103 +0,0 @@
1
- import random
2
- import requests
3
- import time
4
- import threading
5
-
6
-
7
- def fetch_proxies():
8
- """Fetch a list of proxy servers from proxyscrape.com.
9
-
10
- Returns:
11
- list: A list of proxy servers in the format "IP:Port".
12
- """
13
- url = "https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all"
14
- response = requests.get(url)
15
- if response.status_code == 200:
16
- return response.text.split("\r\n")[:-1]
17
- print(f"Error fetching proxies: {response.status_code}")
18
- return []
19
-
20
-
21
- def test_proxy(proxy, prompt, timeout):
22
- """Test the given proxy server with a specified prompt and timeout.
23
-
24
- Args:
25
- proxy (str): The proxy server in the format "IP:Port".
26
- prompt (str): The test prompt to be used for testing.
27
- timeout (int): The maximum time in seconds allowed for the test.
28
- """
29
- try:
30
- start_time = time.time()
31
- # res = gpt3.Completion.create(prompt=prompt, proxy=proxy)
32
- end_time = time.time()
33
- response_time = end_time - start_time
34
-
35
- if response_time < timeout:
36
- response_time = int(response_time*1000)
37
- print(f'proxy: {proxy} [{response_time}ms] βœ…')
38
- add_working_proxy((proxy))
39
- except Exception as e:
40
- pass
41
-
42
-
43
- def add_working_proxy(proxy):
44
- """Add a working proxy server to the global working_proxies list.
45
-
46
- Args:
47
- proxy (str): The proxy server in the format "IP:Port".
48
- """
49
- global working_proxies
50
- working_proxies.append(proxy)
51
-
52
-
53
- def remove_proxy(proxy):
54
- """Remove a proxy server from the global working_proxies list.
55
-
56
- Args:
57
- proxy (str): The proxy server in the format "IP:Port".
58
- """
59
- global working_proxies
60
- if proxy in working_proxies:
61
- working_proxies.remove(proxy)
62
-
63
-
64
- def get_working_proxies(prompt, timeout=5):
65
- """Fetch and test proxy servers, adding working proxies to the global working_proxies list.
66
-
67
- Args:
68
- prompt (str): The test prompt to be used for testing.
69
- timeout (int, optional): The maximum time in seconds allowed for testing. Defaults to 5.
70
- """
71
- proxy_list = fetch_proxies()
72
- threads = []
73
-
74
- for proxy in proxy_list:
75
- thread = threading.Thread(target=test_proxy, args=(
76
- proxy, prompt, timeout))
77
- threads.append(thread)
78
- thread.start()
79
-
80
- for t in threads:
81
- t.join(timeout)
82
-
83
-
84
- def update_working_proxies():
85
- """Continuously update the global working_proxies list with working proxy servers."""
86
- global working_proxies
87
- test_prompt = "What is the capital of France?"
88
-
89
- while True:
90
- working_proxies = [] # Clear the list before updating
91
- get_working_proxies(test_prompt)
92
- print('proxies updated')
93
- time.sleep(1800) # Update proxies list every 30 minutes
94
-
95
-
96
- def get_random_proxy():
97
- """Get a random working proxy server from the global working_proxies list.
98
-
99
- Returns:
100
- str: A random working proxy server in the format "IP:Port".
101
- """
102
- global working_proxies
103
- return random.choice(working_proxies)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
server/backend.py CHANGED
@@ -6,7 +6,6 @@ from googletrans import Translator
6
  from flask import request
7
  from datetime import datetime
8
  from requests import get
9
- from server.auto_proxy import get_random_proxy, update_working_proxies
10
  from server.config import special_instructions
11
 
12
 
@@ -19,7 +18,6 @@ class Backend_Api:
19
  :param config: Configuration dictionary
20
  """
21
  self.app = app
22
- self.use_auto_proxy = config['use_auto_proxy']
23
  self.routes = {
24
  '/backend-api/v2/conversation': {
25
  'function': self._conversation,
@@ -27,11 +25,6 @@ class Backend_Api:
27
  }
28
  }
29
 
30
- # if self.use_auto_proxy:
31
- # update_proxies = threading.Thread(
32
- # target=update_working_proxies, daemon=True)
33
- # update_proxies.start()
34
-
35
  def _conversation(self):
36
  """
37
  Handles the conversation route.
@@ -41,7 +34,7 @@ class Backend_Api:
41
  max_retries = 3
42
  retries = 0
43
  conversation_id = request.json['conversation_id']
44
-
45
  while retries < max_retries:
46
  try:
47
  jailbreak = request.json['jailbreak']
@@ -50,8 +43,8 @@ class Backend_Api:
50
 
51
  # Generate response
52
  response = ChatCompletion.create(
53
- model=model,
54
- stream=True,
55
  chatId=conversation_id,
56
  messages=messages
57
  )
@@ -183,19 +176,18 @@ def response_jailbroken_failed(response):
183
  return False if len(response) < 4 else not (response.startswith("GPT:") or response.startswith("ACT:"))
184
 
185
 
186
- def set_response_language(prompt):
187
  """
188
  Set the response language based on the prompt content.
189
-
190
  :param prompt: Prompt dictionary
191
  :return: String indicating the language to be used for the response
192
- """
193
- translator = Translator()
194
- max_chars = 256
195
- content_sample = prompt['content'][:max_chars]
196
- detected_language = translator.detect(content_sample).lang
197
- return f"You will respond in the language: {detected_language}. "
198
-
199
 
200
 
201
  def getJailbreak(jailbreak):
@@ -213,4 +205,4 @@ def getJailbreak(jailbreak):
213
  else:
214
  return None
215
  else:
216
- return None
 
6
  from flask import request
7
  from datetime import datetime
8
  from requests import get
 
9
  from server.config import special_instructions
10
 
11
 
 
18
  :param config: Configuration dictionary
19
  """
20
  self.app = app
 
21
  self.routes = {
22
  '/backend-api/v2/conversation': {
23
  'function': self._conversation,
 
25
  }
26
  }
27
 
 
 
 
 
 
28
  def _conversation(self):
29
  """
30
  Handles the conversation route.
 
34
  max_retries = 3
35
  retries = 0
36
  conversation_id = request.json['conversation_id']
37
+
38
  while retries < max_retries:
39
  try:
40
  jailbreak = request.json['jailbreak']
 
43
 
44
  # Generate response
45
  response = ChatCompletion.create(
46
+ model=model,
47
+ stream=True,
48
  chatId=conversation_id,
49
  messages=messages
50
  )
 
176
  return False if len(response) < 4 else not (response.startswith("GPT:") or response.startswith("ACT:"))
177
 
178
 
179
+ def set_response_language(prompt):
180
  """
181
  Set the response language based on the prompt content.
182
+
183
  :param prompt: Prompt dictionary
184
  :return: String indicating the language to be used for the response
185
+ """
186
+ translator = Translator()
187
+ max_chars = 256
188
+ content_sample = prompt['content'][:max_chars]
189
+ detected_language = translator.detect(content_sample).lang
190
+ return f"You will respond in the language: {detected_language}. "
 
191
 
192
 
193
  def getJailbreak(jailbreak):
 
205
  else:
206
  return None
207
  else:
208
+ return None