Skip to content

Commit

Permalink
Add quick access search button
Browse files Browse the repository at this point in the history
  • Loading branch information
hlohaus committed Dec 17, 2024
1 parent b8d7e3e commit 03c6939
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 15 deletions.
25 changes: 18 additions & 7 deletions g4f/Provider/needs_auth/GithubCopilot.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import annotations

import json
from aiohttp import ClientSession

from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin, BaseConversation
from ...typing import AsyncResult, Messages, Cookies
from ...requests.raise_for_status import raise_for_status
from ...requests import StreamSession
from ...requests.aiohttp import get_connector
from ...providers.helper import format_prompt
from ...cookies import get_cookies

Expand All @@ -16,6 +17,7 @@ def __init__(self, conversation_id: str):
self.conversation_id = conversation_id

class GithubCopilot(AsyncGeneratorProvider, ProviderModelMixin):
label = "GitHub Copilot"
url = "https://github.com/copilot"

working = True
Expand All @@ -42,13 +44,22 @@ async def create_async_generator(
if not model:
model = cls.default_model
if cookies is None:
cookies = get_cookies(".github.com")
async with StreamSession(
proxy=proxy,
impersonate="chrome",
cookies = get_cookies("github.com")
async with ClientSession(
connector=get_connector(proxy=proxy),
cookies=cookies,
headers={
"GitHub-Verified-Fetch": "true",
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0',
'Accept-Language': 'en-US,en;q=0.5',
'Referer': 'https://github.com/copilot',
'Content-Type': 'application/json',
'GitHub-Verified-Fetch': 'true',
'X-Requested-With': 'XMLHttpRequest',
'Origin': 'https://github.com',
'Connection': 'keep-alive',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
}
) as session:
headers = {}
Expand Down Expand Up @@ -87,7 +98,7 @@ async def create_async_generator(
json=json_data,
headers=headers
) as response:
async for line in response.iter_lines():
async for line in response.content:
if line.startswith(b"data: "):
data = json.loads(line[6:])
if data.get("type") == "content":
Expand Down
1 change: 1 addition & 0 deletions g4f/cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class CookiesConfig():
"chat.reka.ai",
"chatgpt.com",
".cerebras.ai",
"github.com",
]

if has_browser_cookie3 and os.environ.get('DBUS_SESSION_BUS_ADDRESS') == "/dev/null":
Expand Down
7 changes: 7 additions & 0 deletions g4f/gui/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ <h3>Settings</h3>
</div>
</div>
<div class="buttons">
<div class="field">
<button id="search">
<a href="" onclick="return false;" title="Enable Web Access">
<i class="fa-solid fa-search"></i>
</a>
</button>
</div>
<div class="field">
<select name="model" id="model">
<option value="">Model: Default</option>
Expand Down
13 changes: 6 additions & 7 deletions g4f/gui/client/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
--scrollbar-thumb: var(--blur-bg);
--button-hover: var(--colour-5);
--top: 50%;
--right: 0;
--size: 70vw;
--blur: 35vw; /* Half of 70vw */
--opacity: 0.3;
Expand Down Expand Up @@ -73,13 +72,12 @@ body:not(.white) a:visited{
.gradient {
position: absolute;
z-index: -1;
left: 50%;
left: 70vw;
border-radius: 50%;
background: radial-gradient(circle at center, var(--accent), var(--gradient));
width: var(--size);
height: var(--size);
top: var(--top);
right: var(--right);
transform: translate(-50%, -50%);
filter: blur(var(--blur)) opacity(var(--opacity));
animation: zoom_gradient 6s infinite alternate;
Expand Down Expand Up @@ -600,7 +598,8 @@ body.white .gradient{

.file-label:has(> input:valid),
.file-label.selected,
.micro-label.recognition {
.micro-label.recognition,
#search.active a i {
color: var(--accent);
}

Expand Down Expand Up @@ -716,7 +715,7 @@ select {
outline: none;
padding: 8px 16px;
appearance: none;
width: 160px;
width: 132px;
}

.buttons button {
Expand Down Expand Up @@ -816,7 +815,7 @@ select:hover,
width: 200px;
}
.field {
padding-right: 15px
padding-right: 8px
}
.message {
flex-direction: row;
Expand Down Expand Up @@ -1003,7 +1002,7 @@ ul {
.buttons {
align-items: flex-start;
flex-wrap: wrap;
gap: 10px;
gap: 8px;
}

.mobile-sidebar {
Expand Down
16 changes: 15 additions & 1 deletion g4f/gui/client/static/js/chat.v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const settings = document.querySelector(".settings");
const chat = document.querySelector(".conversation");
const album = document.querySelector(".images");
const log_storage = document.querySelector(".log");
const switchInput = document.getElementById("switch");
const searchButton = document.getElementById("search");

const optionElementsSelector = ".settings input, .settings textarea, #model, #model2, #provider";

Expand Down Expand Up @@ -591,7 +593,7 @@ const ask_gpt = async (message_id, message_index = -1, regenerate = false, provi
id: message_id,
conversation_id: window.conversation_id,
model: model,
web_search: document.getElementById("switch").checked,
web_search: switchInput.checked,
provider: provider,
messages: messages,
auto_continue: auto_continue,
Expand Down Expand Up @@ -1434,6 +1436,9 @@ async function on_api() {
}
});
}

const method = switchInput.checked ? "add" : "remove";
searchButton.classList[method]("active");
}

async function load_version() {
Expand Down Expand Up @@ -1640,6 +1645,7 @@ async function load_provider_models(providerIndex=null) {
}
};
providerSelect.addEventListener("change", () => load_provider_models());

document.getElementById("pin").addEventListener("click", async () => {
const pin_container = document.getElementById("pin_container");
let selected_provider = providerSelect.options[providerSelect.selectedIndex];
Expand Down Expand Up @@ -1667,6 +1673,14 @@ document.getElementById("pin").addEventListener("click", async () => {
}
});

switchInput.addEventListener("change", () => {
const method = switchInput.checked ? "add" : "remove";
searchButton.classList[method]("active");
});
searchButton.addEventListener("click", async () => {
switchInput.click();
});

function save_storage() {
let filename = `chat ${new Date().toLocaleString()}.json`.replaceAll(":", "-");
let data = {"options": {"g4f": ""}};
Expand Down

0 comments on commit 03c6939

Please sign in to comment.