XFEstudio/gpt4free
fix: update timeout, regex, and message logic in OpenaiChat & chat.v1.js
- **g4f/Provider/needs_auth/OpenaiChat.py:** - Increase the default timeout parameter from 180 to 360 seconds. - Modify the regex pattern used in `re.sub` from `(?:cite\nturn[0-9]+search|cite\nturn[0-9]+news|turn[0-9]+news|turn[0-9]+search)(\d+)` to `(?:cite\nturn[0-9]+|turn[0-9]+)(?:search|news|view)(\d+)`. - **g4f/gui/client/static/js/chat.v1.js:** - Change the `filter_message` function to wrap the result of `text.replaceAll(...)` with `filter_message_content`, removing the chained `.replace` calls. - In `add_message_chunk`, update the `update_message` call by passing `null` instead of the rendered reasoning. - In `update_message`, refine the content-building logic by: - Checking that both `reasoning_storage[message_id]` and `message_storage[message_id]` exist before concatenating rendered reasoning with the markdown-rendered message. - Using an alternative branch to render only the reasoning when no message content is available. - Appending an error message (if one exists) to the content and then updating `content_map.inner.innerHTML` unconditionally.
819f4d85
代码差异
@@ -278,7 +278,7 @@ class OpenaiChat(AsyncAuthedProvider, ProviderModelMixin):
messages: Messages,
auth_result: AuthResult,
proxy: str = None,
timeout: int = 180,
timeout: int = 360,
auto_continue: bool = False,
action: str = "next",
conversation: Conversation = None,
@@ -447,7 +447,7 @@ class OpenaiChat(AsyncAuthedProvider, ProviderModelMixin):
link = sources.list[int(match.group(1))]["url"]
return f"[[{int(match.group(1))+1}]]({link})"
return f" [{int(match.group(1))+1}]"
buffer = re.sub(r'(?:cite\nturn[0-9]+search|cite\nturn[0-9]+news|turn[0-9]+news|turn[0-9]+search)(\d+)', replacer, buffer)
buffer = re.sub(r'(?:cite\nturn[0-9]+|turn[0-9]+)(?:search|news|view)(\d+)', replacer, buffer)
else:
continue
yield buffer
@@ -120,9 +120,9 @@ function filter_message(text) {
if (Array.isArray(text)) {
return text;
}
return text.replaceAll(
return filter_message_content(text.replaceAll(
/<!-- generated images start -->[\s\S]+<!-- generated images end -->/gm, ""
).replace(/ \[aborted\]$/g, "").replace(/ \[error\]$/g, "");
))
}
function filter_message_content(text) {
@@ -949,7 +949,7 @@ async function add_message_chunk(message, message_id, provider, scroll, finish_m
} if (message.token) {
reasoning_storage[message_id].text += message.token;
}
update_message(content_map, message_id, render_reasoning(reasoning_storage[message_id]), scroll);
update_message(content_map, message_id, null, scroll);
} else if (message.type == "parameters") {
if (!parameters_storage[provider]) {
parameters_storage[provider] = {};
@@ -2100,8 +2100,10 @@ function count_words_and_tokens(text, model, completion_tokens, prompt_tokens) {
function update_message(content_map, message_id, content = null, scroll = true) {
content_map.update_timeouts.push(setTimeout(() => {
if (!content) {
if (reasoning_storage[message_id]) {
if (reasoning_storage[message_id] && message_storage[message_id]) {
content = render_reasoning(reasoning_storage[message_id], true) + markdown_render(message_storage[message_id]);
} else if (reasoning_storage[message_id]) {
content = render_reasoning(reasoning_storage[message_id]);
} else {
content = markdown_render(message_storage[message_id]);
}
@@ -2118,10 +2120,9 @@ function update_message(content_map, message_id, content = null, scroll = true)
}
}
if (error_storage[message_id]) {
content_map.inner.innerHTML = message + markdown_render(`**An error occured:** ${error_storage[message_id]}`);
} else {
content_map.inner.innerHTML = content;
content += markdown_render(`**An error occured:** ${error_storage[message_id]}`);
}
content_map.inner.innerHTML = content;
if (countTokensEnabled) {
content_map.count.innerText = count_words_and_tokens(
(reasoning_storage[message_id] ? reasoning_storage[message_id].text : "")