pycoze 0.1.469__py3-none-any.whl → 0.1.470__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 +38 -6
- {pycoze-0.1.469.dist-info → pycoze-0.1.470.dist-info}/METADATA +1 -1
- {pycoze-0.1.469.dist-info → pycoze-0.1.470.dist-info}/RECORD +6 -6
- {pycoze-0.1.469.dist-info → pycoze-0.1.470.dist-info}/LICENSE +0 -0
- {pycoze-0.1.469.dist-info → pycoze-0.1.470.dist-info}/WHEEL +0 -0
- {pycoze-0.1.469.dist-info → pycoze-0.1.470.dist-info}/top_level.txt +0 -0
pycoze/bot/chat_base.py
CHANGED
@@ -169,6 +169,7 @@ class BufferProcessor:
|
|
169
169
|
self.text_content = ""
|
170
170
|
|
171
171
|
|
172
|
+
|
172
173
|
async def stream_openai_response(conversation_history, start_new_stream):
|
173
174
|
"""
|
174
175
|
异步流式传输 OpenAI 聊天完成响应并处理结构化输出
|
@@ -219,6 +220,39 @@ async def stream_openai_response(conversation_history, start_new_stream):
|
|
219
220
|
yield result
|
220
221
|
|
221
222
|
|
223
|
+
def mark_json_error(e, content):
|
224
|
+
"""标记JSON解析错误的位置
|
225
|
+
Args:
|
226
|
+
e: JSONDecodeError异常
|
227
|
+
content: 原始JSON内容
|
228
|
+
Returns:
|
229
|
+
标记错误位置的字符串,并用 **ERROR** 标注错误位置
|
230
|
+
"""
|
231
|
+
# 确保上下文长度至少为前后各50个字符
|
232
|
+
error_start = max(0, e.pos - 50)
|
233
|
+
error_end = min(len(content), e.pos + 50)
|
234
|
+
error_context = content[error_start:error_end]
|
235
|
+
|
236
|
+
# 计算错误在上下文中的位置
|
237
|
+
error_pos_in_context = e.pos - error_start
|
238
|
+
|
239
|
+
# 确保错误位置在上下文中
|
240
|
+
if error_pos_in_context < 0 or error_pos_in_context >= len(error_context):
|
241
|
+
# 如果错误位置超出上下文范围,返回整个上下文并标记错误位置
|
242
|
+
return (
|
243
|
+
f"Error position is at the end of the context:\n"
|
244
|
+
f"{error_context}**ERROR_HERE**"
|
245
|
+
)
|
246
|
+
|
247
|
+
# 标记错误位置
|
248
|
+
marked_error = (
|
249
|
+
error_context[:error_pos_in_context] +
|
250
|
+
'**ERROR_HERE**' + error_context[error_pos_in_context] + '**ERROR_HERE**' +
|
251
|
+
error_context[error_pos_in_context + 1:]
|
252
|
+
)
|
253
|
+
|
254
|
+
return marked_error
|
255
|
+
|
222
256
|
|
223
257
|
async def handle_user_inputs(
|
224
258
|
conversation_history, user_input, cwd, abilities, has_any_tool, bot_setting, bot_setting_file:str
|
@@ -287,15 +321,13 @@ async def handle_user_inputs(
|
|
287
321
|
"content": f"\n```json\n{cleaned_content}\n```\n",
|
288
322
|
}
|
289
323
|
)
|
290
|
-
#
|
291
|
-
|
292
|
-
|
293
|
-
context = cleaned_content[start:end]
|
294
|
-
|
324
|
+
# 使用函数标记错误位置
|
325
|
+
marked_error = mark_json_error(e, cleaned_content)
|
326
|
+
json_err = f"JSON parsing error\n\nError type: {type(e).__name__}\nError message: {e.msg}\nPosition: line {e.lineno}, column {e.colno}\n\nError context:\n{marked_error}\n\nPlease think and check and correct the JSON format, then try again."
|
295
327
|
conversation_history.append(
|
296
328
|
{
|
297
329
|
"role": "user",
|
298
|
-
"content":
|
330
|
+
"content": json_err,
|
299
331
|
}
|
300
332
|
)
|
301
333
|
start_new_stream["value"] = True
|
@@ -11,7 +11,7 @@ pycoze/api/lib/web.py,sha256=4HaOV_zYHq6-SSQQIc_O7REnC1asIlXIELxee-pU6zc,2421
|
|
11
11
|
pycoze/api/lib/window.py,sha256=ZZacqnX0fvZUnLUhNVjbbjhBcKkYdi_6E0LswLp1MqM,2071
|
12
12
|
pycoze/bot/__init__.py,sha256=rL3Q-ycczRpSFfKn84fg3QBl5k22WpyeIU5qOEjEby8,79
|
13
13
|
pycoze/bot/chat.py,sha256=bScsMc0hGh2NlvhQxzWEbnA_WXU9JdAJv-rx27SpEB8,6554
|
14
|
-
pycoze/bot/chat_base.py,sha256=
|
14
|
+
pycoze/bot/chat_base.py,sha256=CKinEQWFgV_QKHAXWNAwAzpIvkDStFQNLHd_5btsczk,14199
|
15
15
|
pycoze/bot/lib.py,sha256=WU4h3B7SG7vh9p9BxhtPlaJ7TkU9VsL3HyCn9hKhWOo,7753
|
16
16
|
pycoze/bot/message.py,sha256=udnIi-h4QgGzkbr_5VcAsVGjoLp9wXJSfBCeuOz7_Bk,802
|
17
17
|
pycoze/bot/prompt.md,sha256=gU79GrEEUsMc5aPrxcB7TC4YMHGCgo8GMsvG8LyNXgQ,14247
|
@@ -33,8 +33,8 @@ pycoze/utils/env.py,sha256=5pWlXfM1F5ZU9hhv1rHlDEanjEW5wf0nbyez9bNRqqA,559
|
|
33
33
|
pycoze/utils/process.py,sha256=U2MURGmxfyWBqdbKfy5UvyV17M40B6HHlNELgWfgrTE,3824
|
34
34
|
pycoze/utils/socket.py,sha256=4Wm4LlwdWXC_kAV0NnZbUc0Y3Kc6KRMyFRqSw79u-9w,2468
|
35
35
|
pycoze/utils/text_or_file.py,sha256=gpxZVWt2DW6YiEg_MnMuwg36VNf3TX383QD_1oZNB0Y,551
|
36
|
-
pycoze-0.1.
|
37
|
-
pycoze-0.1.
|
38
|
-
pycoze-0.1.
|
39
|
-
pycoze-0.1.
|
40
|
-
pycoze-0.1.
|
36
|
+
pycoze-0.1.470.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
|
37
|
+
pycoze-0.1.470.dist-info/METADATA,sha256=a2FEbeLLXzdKPjEqnRpVAJPyyrWHe1pqW4fX8buXs08,854
|
38
|
+
pycoze-0.1.470.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
39
|
+
pycoze-0.1.470.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
|
40
|
+
pycoze-0.1.470.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|