branch: externals/llm
commit faaa5ba71be54590b3c025d51914bfd6b944a23b
Author: Andrew Hyatt <[email protected]>
Commit: Andrew Hyatt <[email protected]>
Make Claude streaming more reslient to whitespace changes
Also, add Claude addition to the NEWS file
---
NEWS.org | 2 ++
llm-claude.el | 7 ++++---
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/NEWS.org b/NEWS.org
index 3132d70bb9..3593d304ee 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -1,3 +1,5 @@
+* Version 0.12.0
+- Add provider =llm-claude=, for Anthropic's Claude.
* Version 0.11.0
- Introduce function calling, now available only in Open AI and Gemini.
- Introduce =llm-capabilities=, which returns a list of extra capabilities for
each backend.
diff --git a/llm-claude.el b/llm-claude.el
index 21af406c2d..15a50484de 100644
--- a/llm-claude.el
+++ b/llm-claude.el
@@ -72,7 +72,7 @@ STREAM is a boolean indicating whether the response should be
streamed."
(defun llm-claude-get-partial-response (response)
"Return the partial response from text RESPONSE."
(let ((regex (rx (seq "\"text\":" (0+ whitespace)
- (group-n 1 ?\" (* anychar) ?\") "}}"))))
+ (group-n 1 ?\" (0+ anychar) ?\") (0+ whitespace) ?}
(0+ whitespace) ?}))))
(with-temp-buffer
(insert response)
;; We use the quick and dirty solution of just looking for any line that
@@ -85,8 +85,9 @@ STREAM is a boolean indicating whether the response should be
streamed."
(line-end-position))
matched-lines))
(mapconcat (lambda (line)
- (string-match regex line)
- (read (match-string 1 line)))
+ (if (string-match regex line)
+ (read (match-string 1 line))
+ (warn "Could not parse streaming response: %s" line)))
(nreverse matched-lines) "")))))
(cl-defmethod llm-chat ((provider llm-claude) prompt)