Spaces:
Running
Running
The return of web access 🥳
Browse files- client/html/index.html +22 -18
- server/backend.py +13 -10
client/html/index.html
CHANGED
@@ -66,24 +66,28 @@
|
|
66 |
</div>
|
67 |
</div>
|
68 |
</div>
|
69 |
-
<div
|
70 |
-
<div class="
|
71 |
-
<
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
<
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
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 |
-
|
95 |
-
|
|
|
|
|
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':
|
114 |
})
|
115 |
|
116 |
results = []
|
|
|
117 |
for index, result in enumerate(search.json()):
|
118 |
-
snippet = f'[{index}] "{result["snippet"]}"
|
119 |
-
|
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 |
|