找出这段生成的Ollama流收集器中的完成状态错误。 import json
def collect ( response ):
parts = []
for line in response :
event = json . loads (line)
parts . append (event. get ( "response" , "" ))
return "" . join (parts)
查看答案
上一道练习 审查生成的私有摘要器 审查AI代码
问问你的AI 让你的AI把这段代码改成引导式找错练习。
Claude ChatGPT 复制提示词 I am reading "找出这段生成的Ollama流收集器中的完成状态错误。" on CodeWiki (https://codewiki.com/zh/practice/spotbug/ai/local-llms/spot-incomplete-stream/).
Context (verbatim from the page):
"""
import json
def collect(response):
parts = []
for line in response:
event = json.loads(line)
parts.append(event.get("response", ""))
return "".join(parts)
"""
Introduce three subtle bugs into the example above and let me find them. Reveal each answer only after I have guessed.
Answer in 中文. Keep code examples in python. Where you are unsure, say so.