monra commited on
Commit
2436a6f
1 Parent(s): 7f0cf80

The return of web access 🥳

Browse files
Files changed (2) hide show
  1. client/html/index.html +22 -18
  2. server/backend.py +13 -10
client/html/index.html CHANGED
@@ -66,24 +66,28 @@
66
  </div>
67
  </div>
68
  </div>
69
- <div class="buttons">
70
- <div class="field" style="display: none">
71
- <input type="checkbox" disabled id="switch" />
72
- <label for="switch"></label>
73
- <span class="about">Web Access</span>
74
- </div>
75
- <div class="field">
76
- <select class="dropdown" name="model" id="model">
77
- <option value="gpt-3.5-turbo">GPT-3.5</option>
78
- <option value="gpt-4" selected>GPT-4</option>
79
- </select>
80
- </div>
81
- <div class="field">
82
- <select class="dropdown" name="jailbreak" id="jailbreak">
83
- <option value="default" selected>Default</option>
84
- <option value="gpt-dan-11.0">DAN</option>
85
- <option value="gpt-evil">Evil</option>
86
- </select>
 
 
 
 
87
  </div>
88
  </div>
89
  </div>
 
66
  </div>
67
  </div>
68
  </div>
69
+ <div>
70
+ <div class="options-container">
71
+ <div class="buttons">
72
+ <div class="field">
73
+ <select class="dropdown" name="model" id="model">
74
+ <option value="gpt-3.5-turbo">GPT-3.5</option>
75
+ <option value="gpt-4" selected>GPT-4</option>
76
+ </select>
77
+ </div>
78
+ <div class="field">
79
+ <select class="dropdown" name="jailbreak" id="jailbreak">
80
+ <option value="default" selected>Default</option>
81
+ <option value="gpt-dan-11.0">DAN</option>
82
+ <option value="gpt-evil">Evil</option>
83
+ </select>
84
+ </div>
85
+ </div>
86
+ <div class="field checkbox">
87
+ <input type="checkbox" id="switch" />
88
+ <label for="switch"></label>
89
+ <span>Web Access</span>
90
+ </div>
91
  </div>
92
  </div>
93
  </div>
server/backend.py CHANGED
@@ -1,4 +1,3 @@
1
- import threading
2
  import re
3
  import g4f
4
  from g4f import ChatCompletion
@@ -82,17 +81,19 @@ def build_messages(jailbreak):
82
  # Initialize the conversation with the system message
83
  conversation = [{'role': 'system', 'content': system_message}]
84
 
 
 
 
85
  # Add web results if enabled
86
  conversation += fetch_search_results(
87
  prompt["content"]) if internet_access else []
88
 
89
- # Add the existing conversation and the prompt
90
- conversation += _conversation + [prompt]
91
-
92
  # Add jailbreak instructions if enabled
93
  if jailbreak_instructions := isJailbreak(jailbreak):
94
- index_last_object = len(conversation) - 1
95
- conversation[index_last_object:index_last_object] = jailbreak_instructions
 
 
96
 
97
  # Reduce conversation size to avoid API Token quantity error
98
  conversation = conversation[-4:] if len(conversation) > 3 else conversation
@@ -110,14 +111,16 @@ def fetch_search_results(query):
110
  search = get('https://ddg-api.herokuapp.com/search',
111
  params={
112
  'query': query,
113
- 'limit': 3,
114
  })
115
 
116
  results = []
 
117
  for index, result in enumerate(search.json()):
118
- snippet = f'[{index}] "{result["snippet"]}"\nURL:{result["link"]}\n\n'
119
- results.append({'role': 'user', 'content': snippet})
120
-
 
121
  return results
122
 
123
 
 
 
1
  import re
2
  import g4f
3
  from g4f import ChatCompletion
 
81
  # Initialize the conversation with the system message
82
  conversation = [{'role': 'system', 'content': system_message}]
83
 
84
+ # Add the existing conversation
85
+ conversation += _conversation
86
+
87
  # Add web results if enabled
88
  conversation += fetch_search_results(
89
  prompt["content"]) if internet_access else []
90
 
 
 
 
91
  # Add jailbreak instructions if enabled
92
  if jailbreak_instructions := isJailbreak(jailbreak):
93
+ conversation += jailbreak_instructions
94
+
95
+ # Add the prompt
96
+ conversation += [prompt]
97
 
98
  # Reduce conversation size to avoid API Token quantity error
99
  conversation = conversation[-4:] if len(conversation) > 3 else conversation
 
111
  search = get('https://ddg-api.herokuapp.com/search',
112
  params={
113
  'query': query,
114
+ 'limit': 5,
115
  })
116
 
117
  results = []
118
+ snippets = ""
119
  for index, result in enumerate(search.json()):
120
+ snippet = f'[{index + 1}] "{result["snippet"]}" URL:{result["link"]}.'
121
+ snippets += snippet
122
+ results.append({'role': 'system', 'content': snippets})
123
+
124
  return results
125
 
126