XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

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
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

2 个文件 +10 -9
Modified g4f/Provider/needs_auth/OpenaiChat.py +2 -2
@@ -278,7 +278,7 @@ class OpenaiChat(AsyncAuthedProvider, ProviderModelMixin):
278 278 messages: Messages,
279 279 auth_result: AuthResult,
280 280 proxy: str = None,
281 timeout: int = 180,
281 timeout: int = 360,
282 282 auto_continue: bool = False,
283 283 action: str = "next",
284 284 conversation: Conversation = None,
@@ -447,7 +447,7 @@ class OpenaiChat(AsyncAuthedProvider, ProviderModelMixin):
447 447 link = sources.list[int(match.group(1))]["url"]
448 448 return f"[[{int(match.group(1))+1}]]({link})"
449 449 return f" [{int(match.group(1))+1}]"
450 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)
450 buffer = re.sub(r'(?:cite\nturn[0-9]+|turn[0-9]+)(?:search|news|view)(\d+)', replacer, buffer)
451 451 else:
452 452 continue
453 453 yield buffer
Modified g4f/gui/client/static/js/chat.v1.js +8 -7
@@ -120,9 +120,9 @@ function filter_message(text) {
120 120 if (Array.isArray(text)) {
121 121 return text;
122 122 }
123 return text.replaceAll(
123 return filter_message_content(text.replaceAll(
124 124 /<!-- generated images start -->[\s\S]+<!-- generated images end -->/gm, ""
125 ).replace(/ \[aborted\]$/g, "").replace(/ \[error\]$/g, "");
125 ))
126 126 }
127 127
128 128 function filter_message_content(text) {
@@ -949,7 +949,7 @@ async function add_message_chunk(message, message_id, provider, scroll, finish_m
949 949 } if (message.token) {
950 950 reasoning_storage[message_id].text += message.token;
951 951 }
952 update_message(content_map, message_id, render_reasoning(reasoning_storage[message_id]), scroll);
952 update_message(content_map, message_id, null, scroll);
953 953 } else if (message.type == "parameters") {
954 954 if (!parameters_storage[provider]) {
955 955 parameters_storage[provider] = {};
@@ -2100,8 +2100,10 @@ function count_words_and_tokens(text, model, completion_tokens, prompt_tokens) {
2100 2100 function update_message(content_map, message_id, content = null, scroll = true) {
2101 2101 content_map.update_timeouts.push(setTimeout(() => {
2102 2102 if (!content) {
2103 if (reasoning_storage[message_id]) {
2103 if (reasoning_storage[message_id] && message_storage[message_id]) {
2104 2104 content = render_reasoning(reasoning_storage[message_id], true) + markdown_render(message_storage[message_id]);
2105 } else if (reasoning_storage[message_id]) {
2106 content = render_reasoning(reasoning_storage[message_id]);
2105 2107 } else {
2106 2108 content = markdown_render(message_storage[message_id]);
2107 2109 }
@@ -2118,10 +2120,9 @@ function update_message(content_map, message_id, content = null, scroll = true)
2118 2120 }
2119 2121 }
2120 2122 if (error_storage[message_id]) {
2121 content_map.inner.innerHTML = message + markdown_render(`**An error occured:** ${error_storage[message_id]}`);
2122 } else {
2123 content_map.inner.innerHTML = content;
2123 content += markdown_render(`**An error occured:** ${error_storage[message_id]}`);
2124 2124 }
2125 content_map.inner.innerHTML = content;
2125 2126 if (countTokensEnabled) {
2126 2127 content_map.count.innerText = count_words_and_tokens(
2127 2128 (reasoning_storage[message_id] ? reasoning_storage[message_id].text : "")