branch: externals/llm
commit 1e729721ac19f138c7b13e3f3221a3b97fbcf894
Author: Andrew Hyatt <[email protected]>
Commit: GitHub <[email protected]>
Handle empty Claude API responses gracefully (#221)
---
NEWS.org | 2 ++
llm-claude.el | 10 ++++++----
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/NEWS.org b/NEWS.org
index a095905f9d..ebb1e921cc 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -1,3 +1,5 @@
+* Version 0.28.1
+- Fix error on empty Claude responses
* Version 0.28.0
- Add tool calling options, for forbidding or forcing tool choice.
- Fix bug (or perhaps breaking change) in Ollama tool use.
diff --git a/llm-claude.el b/llm-claude.el
index ccb7d6d50e..4becc74670 100644
--- a/llm-claude.el
+++ b/llm-claude.el
@@ -176,12 +176,14 @@
tool-uses))))
(cl-defmethod llm-provider-chat-extract-result ((_ llm-claude) response)
- (let ((content (aref (assoc-default 'content response) 0)))
- (assoc-default 'text content)))
+ (when (> (length (assoc-default 'content response)) 0)
+ (let ((content (aref (assoc-default 'content response) 0)))
+ (assoc-default 'text content))))
(cl-defmethod llm-provider-extract-reasoning ((_ llm-claude) response)
- (let ((content (aref (assoc-default 'content response) 0)))
- (assoc-default 'thinking content)))
+ (when (> (length (assoc-default 'content response)) 0)
+ (let ((content (aref (assoc-default 'content response) 0)))
+ (assoc-default 'thinking content))))
(cl-defmethod llm-provider-streaming-media-handler ((_ llm-claude)
receiver err-receiver)