Skip to content

Commit

Permalink
Merge pull request #2572 from hlohaus/15Jan
Browse files Browse the repository at this point in the history
Readd JsApi for Webview UI
  • Loading branch information
hlohaus authored Jan 15, 2025
2 parents f105451 + df7f9e4 commit 55d6709
Show file tree
Hide file tree
Showing 20 changed files with 269 additions and 105 deletions.
11 changes: 4 additions & 7 deletions g4f/Provider/needs_auth/OpenaiChat.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ async def create_authed(
# if auth_result.arkose_token is None:
# raise MissingAuthError("No arkose token found in .har file")
if "proofofwork" in chat_requirements:
if getattr(auth_result, "proof_token") is None:
if getattr(auth_result, "proof_token", None) is None:
auth_result.proof_token = get_config(auth_result.headers.get("user-agent"))
proofofwork = generate_proof_token(
**chat_requirements["proofofwork"],
Expand Down Expand Up @@ -444,12 +444,9 @@ async def create_authed(
headers=headers
) as response:
cls._update_request_args(auth_result, session)
if response.status in (403, 404) and max_retries > 0:
max_retries -= 1
debug.log(f"Retry: Error {response.status}: {await response.text()}")
conversation.conversation_id = None
await asyncio.sleep(5)
continue
if response.status == 403:
auth_result.proof_token = None
RequestConfig.proof_token = None
await raise_for_status(response)
buffer = u""
async for line in response.iter_lines():
Expand Down
14 changes: 13 additions & 1 deletion g4f/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from typing import Union, Optional, List

import g4f
import g4f.Provider
import g4f.debug
from g4f.client import AsyncClient, ChatCompletion, ImagesResponse, convert_to_provider
from g4f.providers.response import BaseConversation, JsonConversation
Expand Down Expand Up @@ -223,7 +224,18 @@ async def models():
"created": 0,
"owned_by": model.base_provider,
"image": isinstance(model, g4f.models.ImageModel),
} for model_id, model in g4f.models.ModelUtils.convert.items()]
"provider": False,
} for model_id, model in g4f.models.ModelUtils.convert.items()] +
[{
"id": provider_name,
"object": "model",
"created": 0,
"owned_by": getattr(provider, "label", None),
"image": bool(getattr(provider, "image_models", False)),
"provider": True,
} for provider_name, provider in g4f.Provider.ProviderUtils.convert.items()
if provider.working and provider_name != "Custom"
]
}

@self.app.get("/v1/models/{model_name}", responses={
Expand Down
7 changes: 2 additions & 5 deletions g4f/gui/client/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@
font-size: 1.2rem;
margin-bottom: 30px;
color: var(--colour-2);
} return app

}

.input-field {
width: 80%;
Expand Down Expand Up @@ -211,9 +210,7 @@

<!-- Input and Button -->
<form action="/chat/">
<!--
<input type="text" name="prompt" class="input-field" placeholder="Enter your query...">
-->
<input type="text" name="prompt" class="input-field" placeholder="Enter your query...">
<button class="button">Open Chat</button>
</form>

Expand Down
6 changes: 3 additions & 3 deletions g4f/gui/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
<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="/static/css/style.css">
<link rel="stylesheet" href="/static/css/all.min.css">
<link rel="apple-touch-icon" sizes="180x180" href="/static/img/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/static/img/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/static/img/favicon-16x16.png">
<link rel="manifest" href="/static/img/site.webmanifest">
<script src="/static/js/icons.js"></script>
<script src="/static/js/highlightjs-copy.min.js"></script>
<script src="/static/js/chat.v1.js" defer></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/markdown-it.min.js"></script>
Expand Down Expand Up @@ -172,7 +172,7 @@ <h3>Settings</h3>
</div>
<div class="bottom_buttons">
<button onclick="delete_conversations()">
<i class="fa-regular fa-trash"></i>
<i class="fa-solid fa-trash"></i>
<span>Clear Conversations</span>
</button>
<button onclick="save_storage()">
Expand Down Expand Up @@ -243,7 +243,7 @@ <h3>Settings</h3>
<i class="fa-solid fa-microphone-slash"></i>
</label>
<div id="send-button">
<i class="fa-solid fa-paper-plane-top"></i>
<i class="fa-regular fa-paper-plane"></i>
</div>
</div>
</div>
Expand Down
9 changes: 9 additions & 0 deletions g4f/gui/client/static/css/all.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion g4f/gui/client/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ ul {
border: 1px dashed #e4d4ffa6;
border-radius: 4px;
cursor: pointer;
padding-left: 8px;
padding-left: 4px;
padding-right: 5px;
padding-top: 2px;
padding-bottom: 2px;
Expand Down
10 changes: 9 additions & 1 deletion g4f/gui/client/static/img/site.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,13 @@
],
"theme_color": "#ffffff",
"background_color": "#ffffff",
"display": "standalone"
"display": "standalone",
"share_target": {
"action": "/chat/",
"method": "GET",
"enctype": "application/x-www-form-urlencoded",
"params": {
"title": "prompt"
}
}
}
Loading

0 comments on commit 55d6709

Please sign in to comment.