返回提交历史
Modified
g4f/Provider/Bing.py
+1
-1
Modified
g4f/Provider/BingCreateImages.py
+8
-6
Modified
g4f/Provider/HuggingChat.py
+3
-0
Modified
g4f/Provider/openai/har_file.py
+2
-1
Modified
g4f/gui/client/static/css/style.css
+15
-2
Modified
g4f/gui/client/static/js/chat.v1.js
+44
-11
XFEstudio/gpt4free
Add conversation title change in gui Fix bug with multiple requests a .har in OpenaiChat
74c399d6
代码差异
6 个文件
+73
-21
@@ -484,7 +484,7 @@ async def stream_generate(
484
484
elif message.get('contentType') == "IMAGE":
485
485
prompt = message.get('text')
486
486
try:
487
image_client = BingCreateImages(cookies, proxy)
487
image_client = BingCreateImages(cookies, proxy, api_key)
488
488
image_response = await image_client.create_async(prompt)
489
489
except Exception as e:
490
490
if debug.logging:
@@ -19,9 +19,13 @@ class BingCreateImages(AsyncGeneratorProvider, ProviderModelMixin):
19
19
needs_auth = True
20
20
image_models = ["dall-e"]
21
21
22
def __init__(self, cookies: Cookies = None, proxy: str = None) -> None:
23
self.cookies: Cookies = cookies
24
self.proxy: str = proxy
22
def __init__(self, cookies: Cookies = None, proxy: str = None, api_key: str = None) -> None:
23
if api_key is not None:
24
if cookies is None:
25
cookies = {}
26
cookies["_U"] = api_key
27
self.cookies = cookies
28
self.proxy = proxy
25
29
26
30
@classmethod
27
31
async def create_async_generator(
@@ -33,9 +37,7 @@ class BingCreateImages(AsyncGeneratorProvider, ProviderModelMixin):
33
37
proxy: str = None,
34
38
**kwargs
35
39
) -> AsyncResult:
36
if api_key is not None:
37
cookies = {"_U": api_key}
38
session = BingCreateImages(cookies, proxy)
40
session = BingCreateImages(cookies, proxy, api_key)
39
41
yield await session.create_async(messages[-1]["content"])
40
42
41
43
def create(self, prompt: str) -> Iterator[Union[ImageResponse, str]]:
@@ -24,6 +24,9 @@ class HuggingChat(AsyncGeneratorProvider, ProviderModelMixin):
24
24
'mistralai/Mistral-7B-Instruct-v0.2',
25
25
'meta-llama/Meta-Llama-3-70B-Instruct'
26
26
]
27
model_aliases = {
28
"mistralai/Mistral-7B-Instruct-v0.1": "mistralai/Mistral-7B-Instruct-v0.2"
29
}
27
30
28
31
@classmethod
29
32
def get_models(cls):
@@ -30,6 +30,7 @@ sessionUrl = "https://chat.openai.com/api/auth/session"
30
30
chatArk: arkReq = None
31
31
accessToken: str = None
32
32
cookies: dict = None
33
headers: dict = None
33
34
34
35
def readHAR():
35
36
dirPath = "./"
@@ -130,7 +131,7 @@ def getN() -> str:
130
131
return base64.b64encode(timestamp.encode()).decode()
131
132
132
133
async def getArkoseAndAccessToken(proxy: str) -> tuple[str, str, dict, dict]:
133
global chatArk, accessToken, cookies
134
global chatArk, accessToken, cookies, headers
134
135
if chatArk is None or accessToken is None:
135
136
chatArk, accessToken, cookies, headers = readHAR()
136
137
if chatArk is None:
@@ -210,7 +210,9 @@ body {
210
210
211
211
.conversations .convo .fa-ellipsis-vertical {
212
212
position: absolute;
213
right: 14px;
213
right: 8px;
214
width: 14px;
215
text-align: center;
214
216
}
215
217
216
218
.conversations .convo .choise {
@@ -222,6 +224,9 @@ body {
222
224
.conversations i, .bottom_buttons i {
223
225
color: var(--conversations);
224
226
cursor: pointer;
227
}
228
229
.bottom_buttons i {
225
230
width: 14px;
226
231
}
227
232
@@ -233,9 +238,17 @@ body {
233
238
overflow: hidden;
234
239
white-space: nowrap;
235
240
margin-right: 10px;
241
background-color: transparent;
242
border: 0;
243
width: 100%;
236
244
}
237
245
238
.convo-title .datetime {
246
.convo-title:focus {
247
outline: 1px solid var(--colour-3) !important;
248
}
249
250
.convo .datetime {
251
white-space: nowrap;
239
252
font-size: 10px;
240
253
}
241
254
@@ -482,12 +482,35 @@ const clear_conversation = async () => {
482
482
}
483
483
};
484
484
485
async function set_conversation_title(conversation_id, title) {
486
conversation = await get_conversation(conversation_id)
487
conversation.new_title = title;
488
appStorage.setItem(
489
`conversation:${conversation.id}`,
490
JSON.stringify(conversation)
491
);
492
}
493
485
494
const show_option = async (conversation_id) => {
486
495
const conv = document.getElementById(`conv-${conversation_id}`);
487
496
const choi = document.getElementById(`cho-${conversation_id}`);
488
497
489
498
conv.style.display = "none";
490
499
choi.style.display = "block";
500
501
const el = document.getElementById(`convo-${conversation_id}`);
502
const trash_el = el.querySelector(".fa-trash");
503
const title_el = el.querySelector("span.convo-title");
504
if (title_el) {
505
const left_el = el.querySelector(".left");
506
const input_el = document.createElement("input");
507
input_el.value = title_el.innerText;
508
input_el.classList.add("convo-title");
509
input_el.onfocus = () => trash_el.style.display = "none";
510
input_el.onchange = () => set_conversation_title(conversation_id, input_el.value);
511
left_el.removeChild(title_el);
512
left_el.appendChild(input_el);
513
}
491
514
};
492
515
493
516
const hide_option = async (conversation_id) => {
@@ -496,6 +519,18 @@ const hide_option = async (conversation_id) => {
496
519
497
520
conv.style.display = "block";
498
521
choi.style.display = "none";
522
523
const el = document.getElementById(`convo-${conversation_id}`);
524
el.querySelector(".fa-trash").style.display = "";
525
const input_el = el.querySelector("input.convo-title");
526
if (input_el) {
527
const left_el = el.querySelector(".left");
528
const span_el = document.createElement("span");
529
span_el.innerText = input_el.value;
530
span_el.classList.add("convo-title");
531
left_el.removeChild(input_el);
532
left_el.appendChild(span_el);
533
}
499
534
};
500
535
501
536
const delete_conversation = async (conversation_id) => {
@@ -709,18 +744,15 @@ const load_conversations = async () => {
709
744
710
745
let html = "";
711
746
conversations.forEach((conversation) => {
712
if (conversation?.items.length > 0) {
713
let old_value = conversation.title;
747
if (conversation?.items.length > 0 && !conversation.new_title) {
714
748
let new_value = (conversation.items[0]["content"]).trim();
715
749
let new_lenght = new_value.indexOf("\n");
716
750
new_lenght = new_lenght > 200 || new_lenght < 0 ? 200 : new_lenght;
717
conversation.title = new_value.substring(0, new_lenght);
718
if (conversation.title != old_value) {
719
appStorage.setItem(
720
`conversation:${conversation.id}`,
721
JSON.stringify(conversation)
722
);
723
}
751
conversation.new_title = new_value.substring(0, new_lenght);
752
appStorage.setItem(
753
`conversation:${conversation.id}`,
754
JSON.stringify(conversation)
755
);
724
756
}
725
757
let updated = "";
726
758
if (conversation.updated) {
@@ -730,9 +762,10 @@ const load_conversations = async () => {
730
762
}
731
763
html += `
732
764
<div class="convo" id="convo-${conversation.id}">
733
<div class="left" onclick="set_conversation('${conversation.id}')">
765
<div class="left">
734
766
<i class="fa-regular fa-comments"></i>
735
<span class="convo-title"><span class="datetime">${updated}</span> ${conversation.title}</span>
767
<span class="datetime" onclick="set_conversation('${conversation.id}')">${updated}</span>
768
<span class="convo-title" onclick="set_conversation('${conversation.id}')">${conversation.new_title}</span>
736
769
</div>
737
770
<i onclick="show_option('${conversation.id}')" class="fa-solid fa-ellipsis-vertical" id="conv-${conversation.id}"></i>
738
771
<div id="cho-${conversation.id}" class="choise" style="display:none;">