知识卡片
流式响应按协议逐项处理
逐行流式JSON需要区分内容、结束及错误记录,处理空行和中断,并设置超时。只拼接message.content的教学代码没有完整覆盖失败语义;保存原始响应和调用状态,避免把不完整文本当作正常评估输出。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- · 查看原书依据
#G Read and decode each line #H Parse each line into JSON Here's an example of how to use the query_model function from listing F.6 that we just implemented: ollama_model = "gpt-oss:20b" result = query_model("What is 1+2?", ollama_model) print(result) The resulting response is "3". (It differs from what we'd get if we ran Ollama run or the Ollama application due to different default settings.) Using
参考来源
- 位置:《Build a Reasoning Model (From Scratch)》第10章《附录F 常见模型评估方法》(来源项目:a19c7933-4eda-4176-aebd-30fe7e1ad292;源文件:extracted/Build a Reasoning Model (From Scratch)/_epub-src/OEBPS/Text/appendix-f.html)
- 结论依据:摘录中关于流式响应按协议逐项处理的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。
- 原始内容:#G Read and decode each line #H Parse each line into JSON Here's an example of how to use the query_model function from listing F.6 that we just implemented: ollama_model = "gpt-oss:20b" result = query_model("What is 1+2?", ollama_model) print(result) The resulting response is "3". (It differs from what we'd get if we ran Ollama run or the Ollama application due to different default settings.) Using