pycoze 0.1.422__py3-none-any.whl → 0.1.423__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pycoze/bot/chat_base.py CHANGED
@@ -164,38 +164,40 @@ async def stream_openai_response(conversation_history, start_new_stream):
164
164
  print(f"Error: {e}", style="bold red")
165
165
  break
166
166
 
167
- if not in_json_block:
168
- # 查找 JSON 代码块的起始标记
169
- json_start_match = re.search(r"```json", buffer, re.IGNORECASE)
170
- if json_start_match:
171
- # 提取 JSON 代码块之前的文本
172
- text_content += buffer[:json_start_match.start()]
173
- # 如果 text_content 不为空,先 yield 文本
174
- if text_content.strip():
175
- yield ("text", text_content.strip())
176
- text_content = ""
177
- # 进入 JSON 代码块模式
178
- in_json_block = True
179
- buffer = buffer[json_start_match.end():]
167
+ if buffer:
168
+ if not in_json_block:
169
+ # 查找 JSON 代码块的起始标记
170
+ json_start_match = re.search(r"```json", buffer, re.IGNORECASE)
171
+ if json_start_match:
172
+ # 提取 JSON 代码块之前的文本
173
+ text_content += buffer[:json_start_match.start()]
174
+ # 如果 text_content 不为空,先 yield 文本
175
+ if text_content.strip():
176
+ yield ("text", text_content.strip())
177
+ text_content = ""
178
+ # 进入 JSON 代码块模式
179
+ in_json_block = True
180
+ buffer = buffer[json_start_match.end():]
181
+ else:
182
+ # 如果没有找到 JSON 代码块,继续累积到 text_content
183
+ text_content += buffer
184
+ buffer = ""
180
185
  else:
181
- # 如果没有找到 JSON 代码块,继续累积到 text_content
182
- text_content += buffer
183
- buffer = ""
184
- else:
185
- # 查找 JSON 代码块的结束标记
186
- json_end_match = re.search(r"```", buffer)
187
- if json_end_match:
188
- # 提取 JSON 代码块内容
189
- json_block_content += buffer[:json_end_match.start()]
190
- # yield JSON 代码块
191
- yield ("json", json_block_content.strip())
192
- json_block_content = ""
193
- in_json_block = False
194
- buffer = buffer[json_end_match.end():]
195
- else:
196
- # 如果没有找到结束标记,继续累积 JSON 内容
197
- json_block_content += buffer
198
- buffer = ""
186
+ # 查找 JSON 代码块的结束标记
187
+ json_end_match = re.search(r"```", buffer)
188
+ if json_end_match:
189
+ # 提取 JSON 代码块内容
190
+ json_block_content += buffer[:json_end_match.start()]
191
+ # yield JSON 代码块
192
+ yield ("json", json_block_content.strip())
193
+ json_block_content = ""
194
+ in_json_block = False
195
+ buffer = buffer[json_end_match.end():]
196
+ else:
197
+ # 如果没有找到结束标记,继续累积 JSON 内容
198
+ json_block_content += buffer
199
+ buffer = ""
200
+
199
201
  # 处理流结束后的剩余内容
200
202
  if in_json_block:
201
203
  # 如果仍在 JSON 代码块模式,处理剩余的 JSON 内容
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pycoze
3
- Version: 0.1.422
3
+ Version: 0.1.423
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -11,7 +11,7 @@ pycoze/api/lib/web.py,sha256=GWgtiTJOolKOX2drXcwuyqTcbo5FQVxa1NuBGcNyjyc,223
11
11
  pycoze/api/lib/window.py,sha256=dkzWfLwn5pE_L0DfQ38K8nx9tQyT5KO-GYyXi0rytFc,2073
12
12
  pycoze/bot/__init__.py,sha256=rL3Q-ycczRpSFfKn84fg3QBl5k22WpyeIU5qOEjEby8,79
13
13
  pycoze/bot/chat.py,sha256=qEuMxH0cVFU9QSU36FrOsjhRAxtsvOv7CQtuXvM3F6Y,6446
14
- pycoze/bot/chat_base.py,sha256=A68wiakJxlCjVSZxAPLpk0xdQg62_0T8Xf7gbT-R490,12845
14
+ pycoze/bot/chat_base.py,sha256=ezA8zTnA5lDhymA3mm2Hu3gRWj7Lg-wks_TsmjRgBb4,12993
15
15
  pycoze/bot/lib.py,sha256=_bQ52mKsWgFGAogFHnmRBJbvK_tPOwsAJ8NqJNMR5K4,7210
16
16
  pycoze/bot/message.py,sha256=udnIi-h4QgGzkbr_5VcAsVGjoLp9wXJSfBCeuOz7_Bk,802
17
17
  pycoze/bot/prompt.md,sha256=t7NQdiiNe-jCDVfeVbvTPfq5WK5nF8CxFUQUFMyXJlo,13880
@@ -31,8 +31,8 @@ pycoze/utils/arg.py,sha256=jop1tBfe5hYkHW1NSpCeaZBEznkgguBscj_7M2dWfrs,503
31
31
  pycoze/utils/env.py,sha256=5pWlXfM1F5ZU9hhv1rHlDEanjEW5wf0nbyez9bNRqqA,559
32
32
  pycoze/utils/socket.py,sha256=bZbFFRH4mfThzRqt55BAAGQ6eICx_ja4x8UGGrUdAm8,2428
33
33
  pycoze/utils/text_or_file.py,sha256=gpxZVWt2DW6YiEg_MnMuwg36VNf3TX383QD_1oZNB0Y,551
34
- pycoze-0.1.422.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
35
- pycoze-0.1.422.dist-info/METADATA,sha256=nc-lEVVpD_stwUoyiE6DDyOoSaBueNJP4DcdG7Q233g,854
36
- pycoze-0.1.422.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
37
- pycoze-0.1.422.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
38
- pycoze-0.1.422.dist-info/RECORD,,
34
+ pycoze-0.1.423.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
35
+ pycoze-0.1.423.dist-info/METADATA,sha256=oE3uAJ3Xa-psi-4qdE88527WUbAHt5KjbJ5WUWZ929I,854
36
+ pycoze-0.1.423.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
37
+ pycoze-0.1.423.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
38
+ pycoze-0.1.423.dist-info/RECORD,,