summaryrefslogtreecommitdiffstats
path: root/g4f/gui
diff options
context:
space:
mode:
authorCommenter123321 <36051603+Commenter123321@users.noreply.github.com>2023-10-10 14:15:12 +0200
committerCommenter123321 <36051603+Commenter123321@users.noreply.github.com>2023-10-10 14:15:12 +0200
commit0e4297494dd46533738f786e4ac675541586177a (patch)
tree6c2999e14ed831f7f37cc60991571cd040772918 /g4f/gui
parentadd cool testing for gpt-3.5 and and gpt-4 (diff)
parentUpdate Aivvm.py (diff)
downloadgpt4free-0e4297494dd46533738f786e4ac675541586177a.tar
gpt4free-0e4297494dd46533738f786e4ac675541586177a.tar.gz
gpt4free-0e4297494dd46533738f786e4ac675541586177a.tar.bz2
gpt4free-0e4297494dd46533738f786e4ac675541586177a.tar.lz
gpt4free-0e4297494dd46533738f786e4ac675541586177a.tar.xz
gpt4free-0e4297494dd46533738f786e4ac675541586177a.tar.zst
gpt4free-0e4297494dd46533738f786e4ac675541586177a.zip
Diffstat (limited to 'g4f/gui')
-rw-r--r--g4f/gui/__init__.py2
-rw-r--r--g4f/gui/client/html/index.html291
-rw-r--r--g4f/gui/client/js/chat.v2.js14
-rw-r--r--g4f/gui/run.py16
-rw-r--r--g4f/gui/server/backend.py19
-rw-r--r--g4f/gui/server/provider.py17
6 files changed, 208 insertions, 151 deletions
diff --git a/g4f/gui/__init__.py b/g4f/gui/__init__.py
index 90a6c7a6..48b78881 100644
--- a/g4f/gui/__init__.py
+++ b/g4f/gui/__init__.py
@@ -16,7 +16,7 @@ def run_gui(host: str = '0.0.0.0', port: int = 80, debug: bool = False) -> None:
view_func = site.routes[route]['function'],
methods = site.routes[route]['methods'],
)
-
+
backend_api = Backend_Api(app)
for route in backend_api.routes:
app.add_url_rule(
diff --git a/g4f/gui/client/html/index.html b/g4f/gui/client/html/index.html
index 3acde2df..bb472706 100644
--- a/g4f/gui/client/html/index.html
+++ b/g4f/gui/client/html/index.html
@@ -1,161 +1,178 @@
<!DOCTYPE html>
<html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0 maximum-scale=1.0">
- <meta name="description" content="A conversational AI system that listens, learns, and challenges">
- <meta property="og:title" content="ChatGPT">
- <meta property="og:image" content="https://openai.com/content/images/2022/11/ChatGPT.jpg">
- <meta property="og:description" content="A conversational AI system that listens, learns, and challenges">
- <meta property="og:url" content="https://g4f.ai">
- <link rel="stylesheet" href="/assets/css/style.css">
- <link rel="apple-touch-icon" sizes="180x180" href="/assets/img/apple-touch-icon.png">
- <link rel="icon" type="image/png" sizes="32x32" href="/assets/img/favicon-32x32.png">
- <link rel="icon" type="image/png" sizes="16x16" href="/assets/img/favicon-16x16.png">
- <link rel="manifest" href="/assets/img/site.webmanifest">
- <script src="/assets/js/icons.js"></script>
- <script src="/assets/js/highlightjs-copy.min.js"></script>
- <script src="/assets/js/chat.v2.js" defer></script>
- <script src="https://cdn.jsdelivr.net/npm/markdown-it@13.0.1/dist/markdown-it.min.js"></script>
- <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.7.0/build/styles/base16/dracula.min.css">
- <script>
- const user_image = `<img src="/assets/img/user.png" alt="your avatar">`;
- const gpt_image = `<img src="/assets/img/gpt.png" alt="your avatar">`;
- </script>
- <style>
- .hljs {
- color: #e9e9f4;
- background: #28293629;
- border-radius: var(--border-radius-1);
- border: 1px solid var(--blur-border);
- font-size: 15px;
- }
- #message-input {
- margin-right: 30px;
- height: 80px;
- }
+<head>
+ <meta charset="UTF-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0 maximum-scale=1.0">
+ <meta name="description" content="A conversational AI system that listens, learns, and challenges">
+ <meta property="og:title" content="ChatGPT">
+ <meta property="og:image" content="https://openai.com/content/images/2022/11/ChatGPT.jpg">
+ <meta property="og:description" content="A conversational AI system that listens, learns, and challenges">
+ <meta property="og:url" content="https://g4f.ai">
+ <link rel="stylesheet" href="/assets/css/style.css">
+ <link rel="apple-touch-icon" sizes="180x180" href="/assets/img/apple-touch-icon.png">
+ <link rel="icon" type="image/png" sizes="32x32" href="/assets/img/favicon-32x32.png">
+ <link rel="icon" type="image/png" sizes="16x16" href="/assets/img/favicon-16x16.png">
+ <link rel="manifest" href="/assets/img/site.webmanifest">
+ <script src="/assets/js/icons.js"></script>
+ <script src="/assets/js/highlightjs-copy.min.js"></script>
+ <script src="/assets/js/chat.v2.js" defer></script>
+ <script src="https://cdn.jsdelivr.net/npm/markdown-it@13.0.1/dist/markdown-it.min.js"></script>
+ <link rel="stylesheet"
+ href="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.7.0/build/styles/base16/dracula.min.css">
+ <script>
+ const user_image = `<img src="/assets/img/user.png" alt="your avatar">`;
+ const gpt_image = `<img src="/assets/img/gpt.png" alt="your avatar">`;
+ </script>
+ <style>
+ .hljs {
+ color: #e9e9f4;
+ background: #28293629;
+ border-radius: var(--border-radius-1);
+ border: 1px solid var(--blur-border);
+ font-size: 15px;
+ }
+
+ #message-input {
+ margin-right: 30px;
+ height: 80px;
+ }
- #message-input::-webkit-scrollbar {
- width: 5px;
- }
+ #message-input::-webkit-scrollbar {
+ width: 5px;
+ }
- /* Track */
- #message-input::-webkit-scrollbar-track {
- background: #f1f1f1;
- }
-
- /* Handle */
- #message-input::-webkit-scrollbar-thumb {
- background: #c7a2ff;
- }
+ /* Track */
+ #message-input::-webkit-scrollbar-track {
+ background: #f1f1f1;
+ }
- /* Handle on hover */
- #message-input::-webkit-scrollbar-thumb:hover {
- background: #8b3dff;
- }
- </style>
- <script src="/assets/js/highlight.min.js"></script>
- <script>window.conversation_id = `{{chat_id}}`</script>
- <title>g4f - gui</title>
- </head>
- <body>
- <div class="gradient"></div>
- <div class="row">
- <div class="box conversations">
- <div class="top">
- <button class="new_convo" onclick="new_conversation()">
- <i class="fa-regular fa-plus"></i>
- <span>New Conversation</span>
- </button>
+ /* Handle */
+ #message-input::-webkit-scrollbar-thumb {
+ background: #c7a2ff;
+ }
+
+ /* Handle on hover */
+ #message-input::-webkit-scrollbar-thumb:hover {
+ background: #8b3dff;
+ }
+ </style>
+ <script src="/assets/js/highlight.min.js"></script>
+ <script>window.conversation_id = `{{chat_id}}`</script>
+ <title>g4f - gui</title>
+</head>
+
+<body>
+ <div class="gradient"></div>
+ <div class="row">
+ <div class="box conversations">
+ <div class="top">
+ <button class="new_convo" onclick="new_conversation()">
+ <i class="fa-regular fa-plus"></i>
+ <span>New Conversation</span>
+ </button>
+ </div>
+ <div class="bottom_buttons">
+ <button onclick="delete_conversations()">
+ <i class="fa-regular fa-trash"></i>
+ <span>Clear Conversations</span>
+ </button>
+ <div class="info">
+ <i class="fa-brands fa-discord"></i>
+ <span class="convo-title">telegram: <a href="https://t.me/g4f_official">@g4f_official</a><br>
+ </span>
</div>
- <div class="bottom_buttons">
- <button onclick="delete_conversations()">
- <i class="fa-regular fa-trash"></i>
- <span>Clear Conversations</span>
- </button>
- <div class="info">
- <i class="fa-brands fa-discord"></i>
- <span class="convo-title">telegram: <a href="https://t.me/g4f_official">@g4f_official</a><br>
- </span>
- </div>
- <div class="info">
- <i class="fa-brands fa-github"></i>
- <span class="convo-title">github: <a href="https://github.com/xtekky/gpt4free">@gpt4free</a><br>
- leave a star ; )
- </span>
- </div>
+ <div class="info">
+ <i class="fa-brands fa-github"></i>
+ <span class="convo-title">github: <a href="https://github.com/xtekky/gpt4free">@gpt4free</a><br>
+ leave a star ; )
+ </span>
</div>
</div>
- <div class="conversation">
- <div class="stop_generating stop_generating-hidden">
- <button id="cancelButton">
- <span>Stop Generating</span>
- <i class="fa-regular fa-stop"></i>
- </button>
+ </div>
+ <div class="conversation">
+ <div class="stop_generating stop_generating-hidden">
+ <button id="cancelButton">
+ <span>Stop Generating</span>
+ <i class="fa-regular fa-stop"></i>
+ </button>
+ </div>
+ <div class="box" id="messages">
+ </div>
+ <div class="user-input">
+ <div class="box input-box">
+ <textarea id="message-input" placeholder="Ask a question" cols="30" rows="10"
+ style="white-space: pre-wrap;resize: none;"></textarea>
+ <div id="send-button">
+ <i class="fa-solid fa-paper-plane-top"></i>
+ </div>
</div>
- <div class="box" id="messages">
+ </div>
+ <div class="buttons">
+ <div class="field">
+ <input type="checkbox" id="switch" />
+ <label for="switch"></label>
+ <span class="about">Web Access</span>
</div>
- <div class="user-input">
- <div class="box input-box">
- <textarea id="message-input" placeholder="Ask a question" cols="30" rows="10" style="white-space: pre-wrap;resize: none;"></textarea>
- <div id="send-button">
- <i class="fa-solid fa-paper-plane-top"></i>
- </div>
- </div>
+ <div class="field">
+ <select name="model" id="model">
+ <option value="gpt-3.5-turbo" selected>gpt-3.5</option>
+ <option value="gpt-4">gpt-4</option>
+ <option value="gpt-3.5-turbo-0613">gpt-3.5 fast</option>
+ <option value="gpt-3.5-turbo-16k">gpt-3.5 16k</option>
+ </select>
</div>
- <div class="buttons">
- <div class="field">
- <input type="checkbox" id="switch"/>
- <label for="switch"></label>
- <span class="about">Web Access</span>
- </div>
+ <div class="field">
+ <select name="jailbreak" id="jailbreak">
+ <option value="default" selected>Set Jailbreak</option>
+ <option value="gpt-math-1.0">math 1.0</option>
+ <option value="gpt-dude-1.0">dude 1.0</option>
+ <option value="gpt-dan-1.0">dan 1.0</option>
+ <option value="gpt-dan-2.0">dan 2.0</option>
+ <option value="gpt-dev-2.0">dev 2.0</option>
+ <option value="gpt-evil-1.0">evil 1.0</option>
+ </select>
<div class="field">
- <select name="model" id="model">
- <option value="gpt-3.5-turbo" selected>gpt-3.5</option>
- <option value="gpt-4">gpt-4</option>
- <option value="gpt-3.5-turbo-0613">gpt-3.5 fast</option>
- <option value="gpt-3.5-turbo-16k">gpt-3.5 16k</option>
+ <select name="provider" id="provider">
+ <option value="g4f.Provider.Auto" selected>Set Provider</option>
+ <option value="g4f.Provider.AItianhuSpace">AItianhuSpace</option>
+ <option value="g4f.Provider.ChatgptLogin">ChatgptLogin</option>
+ <option value="g4f.Provider.ChatgptDemo">ChatgptDemo</option>
+ <option value="g4f.Provider.ChatgptDuo">ChatgptDuo</option>
+ <option value="g4f.Provider.Vitalentum">Vitalentum</option>
+ <option value="g4f.Provider.ChatgptAi">ChatgptAi</option>
+ <option value="g4f.Provider.AItianhu">AItianhu</option>
+ <option value="g4f.Provider.ChatBase">ChatBase</option>
+ <option value="g4f.Provider.Liaobots">Liaobots</option>
+ <option value="g4f.Provider.Yqcloud">Yqcloud</option>
+ <option value="g4f.Provider.Myshell">Myshell</option>
+ <option value="g4f.Provider.FreeGpt">FreeGpt</option>
+ <option value="g4f.Provider.Vercel">Vercel</option>
+ <option value="g4f.Provider.DeepAi">DeepAi</option>
+ <option value="g4f.Provider.Aichat">Aichat</option>
+ <option value="g4f.Provider.GPTalk">GPTalk</option>
+ <option value="g4f.Provider.GptGod">GptGod</option>
+ <option value="g4f.Provider.AiAsk">AiAsk</option>
+ <option value="g4f.Provider.GptGo">GptGo</option>
+ <option value="g4f.Provider.Ylokh">Ylokh</option>
+ <option value="g4f.Provider.Bard">Bard</option>
+ <option value="g4f.Provider.Aibn">Aibn</option>
+ <option value="g4f.Provider.Bing">Bing</option>
+ <option value="g4f.Provider.You">You</option>
+ <option value="g4f.Provider.H2o">H2o</option>
+ <option value="g4f.Provider.Aivvm">Aivvm</option>
</select>
</div>
- <div class="field">
- <select name="jailbreak" id="jailbreak">
- <option value="default" selected>default</option>
- <option value="gpt-math-1.0">math 1.0</option>
- <option value="gpt-dude-1.0">dude 1.0</option>
- <option value="gpt-dan-1.0">dan 1.0</option>
- <option value="gpt-dan-2.0">dan 2.0</option>
- <option value="gpt-dev-2.0">dev 2.0</option>
- <option value="gpt-evil-1.0">evil 1.0</option>
- </select>
- <form class="color-picker" action="">
- <fieldset>
- <legend class="visually-hidden">Pick a color scheme</legend>
- <label for="light" class="visually-hidden">Light</label>
- <input type="radio" name="theme" id="light" checked>
-
- <label for="pink" class="visually-hidden">Pink theme</label>
- <input type="radio" id="pink" name="theme">
-
- <label for="blue" class="visually-hidden">Blue theme</label>
- <input type="radio" id="blue" name="theme">
-
- <label for="green" class="visually-hidden">Green theme</label>
- <input type="radio" id="green" name="theme">
-
- <label for="dark" class="visually-hidden">Dark theme</label>
- <input type="radio" id="dark" name="theme">
- </fieldset>
- </form>
- </div>
</div>
</div>
</div>
+ </div>
<div class="mobile-sidebar">
<i class="fa-solid fa-bars"></i>
</div>
<script>
</script>
- </body>
+</body>
+
</html> \ No newline at end of file
diff --git a/g4f/gui/client/js/chat.v2.js b/g4f/gui/client/js/chat.v2.js
index df827030..e1faa6bb 100644
--- a/g4f/gui/client/js/chat.v2.js
+++ b/g4f/gui/client/js/chat.v2.js
@@ -52,7 +52,7 @@ const remove_cancel_button = async () => {
const ask_gpt = async (message) => {
try {
- message_input.value = ``;
+ message_input.value = ``;
message_input.innerHTML = ``;
message_input.innerText = ``;
@@ -60,10 +60,11 @@ const ask_gpt = async (message) => {
window.scrollTo(0, 0);
window.controller = new AbortController();
- jailbreak = document.getElementById("jailbreak");
- model = document.getElementById("model");
- prompt_lock = true;
- window.text = ``;
+ jailbreak = document.getElementById("jailbreak");
+ provider = document.getElementById("provider");
+ model = document.getElementById("model");
+ prompt_lock = true;
+ window.text = ``;
window.token = message_id();
stop_generating.classList.remove(`stop_generating-hidden`);
@@ -109,12 +110,15 @@ const ask_gpt = async (message) => {
headers: {
"content-type": `application/json`,
accept: `text/event-stream`,
+ // v: `1.0.0`,
+ // ts: Date.now().toString(),
},
body: JSON.stringify({
conversation_id: window.conversation_id,
action: `_ask`,
model: model.options[model.selectedIndex].value,
jailbreak: jailbreak.options[jailbreak.selectedIndex].value,
+ provider: provider.options[provider.selectedIndex].value,
meta: {
id: window.token,
content: {
diff --git a/g4f/gui/run.py b/g4f/gui/run.py
index da672d59..731c7cbf 100644
--- a/g4f/gui/run.py
+++ b/g4f/gui/run.py
@@ -1,4 +1,18 @@
from g4f.gui import run_gui
+from argparse import ArgumentParser
+
if __name__ == '__main__':
- run_gui() \ No newline at end of file
+
+ parser = ArgumentParser(description='Run the GUI')
+
+ parser.add_argument('-host', type=str, default='0.0.0.0', help='hostname')
+ parser.add_argument('-port', type=int, default=80, help='port')
+ parser.add_argument('-debug', action='store_true', help='debug mode')
+
+ args = parser.parse_args()
+ port = args.port
+ host = args.host
+ debug = args.debug
+
+ run_gui(host, port, debug) \ No newline at end of file
diff --git a/g4f/gui/server/backend.py b/g4f/gui/server/backend.py
index 9a1dbbf8..8f4b529f 100644
--- a/g4f/gui/server/backend.py
+++ b/g4f/gui/server/backend.py
@@ -1,9 +1,11 @@
import g4f
from flask import request
-from threading import Thread
from .internet import search
from .config import special_instructions
+from .provider import get_provider
+
+g4f.logging = True
class Backend_Api:
def __init__(self, app) -> None:
@@ -31,22 +33,25 @@ class Backend_Api:
conversation = request.json['meta']['content']['conversation']
prompt = request.json['meta']['content']['parts'][0]
model = request.json['model']
+ provider = get_provider(request.json.get('provider'))
messages = special_instructions[jailbreak] + conversation + search(internet_access, prompt) + [prompt]
def stream():
- answer = g4f.ChatCompletion.create(model = model,
- messages = messages, stream=True)
+ if provider:
+ answer = g4f.ChatCompletion.create(model=model,
+ provider=provider, messages=messages, stream=True)
+ else:
+ answer = g4f.ChatCompletion.create(model=model,
+ messages=messages, stream=True)
for token in answer:
yield token
-
+
return self.app.response_class(stream(), mimetype='text/event-stream')
- except Exception as e:
- print(e)
+ except Exception as e:
return {
- '_token': 'anerroroccuredmf',
'_action': '_ask',
'success': False,
"error": f"an error occured {str(e)}"}, 400 \ No newline at end of file
diff --git a/g4f/gui/server/provider.py b/g4f/gui/server/provider.py
new file mode 100644
index 00000000..286f881b
--- /dev/null
+++ b/g4f/gui/server/provider.py
@@ -0,0 +1,17 @@
+import g4f
+
+def get_provider(provider: str) -> g4f.Provider.BaseProvider:
+
+ if isinstance(provider, str):
+ print(provider)
+ if provider == 'g4f.Provider.Auto':
+ return None
+
+ if provider in g4f.Provider.ProviderUtils.convert:
+ return g4f.Provider.ProviderUtils.convert[provider]
+
+ else:
+ return None
+
+ else:
+ return None