Procházet zdrojové kódy

Merge pull request #536 from jijiezzhou/fix/issue-522-empty-choices-stream

fix(chapter4): skip empty choices chunks in streaming response
jjyaoao před 1 měsícem
rodič
revize
8ffbe32f9a

+ 2 - 0
code/chapter4/llm_client.py

@@ -42,6 +42,8 @@ class HelloAgentsLLM:
             print("✅ 大语言模型响应成功:")
             collected_content = []
             for chunk in response:
+                if not chunk.choices:
+                    continue
                 content = chunk.choices[0].delta.content or ""
                 print(content, end="", flush=True)
                 collected_content.append(content)

+ 2 - 0
docs/chapter4/Chapter4-Building-Classic-Agent-Paradigms.md

@@ -92,6 +92,8 @@ class HelloAgentsLLM:
             print("✅ Large language model response successful:")
             collected_content = []
             for chunk in response:
+                if not chunk.choices:
+                    continue
                 content = chunk.choices[0].delta.content or ""
                 print(content, end="", flush=True)
                 collected_content.append(content)

+ 2 - 0
docs/chapter4/第四章 智能体经典范式构建.md

@@ -92,6 +92,8 @@ class HelloAgentsLLM:
             print("✅ 大语言模型响应成功:")
             collected_content = []
             for chunk in response:
+                if not chunk.choices:
+                    continue
                 content = chunk.choices[0].delta.content or ""
                 print(content, end="", flush=True)
                 collected_content.append(content)