refactor: moved org-agent to its own repository as a submodule
This commit is contained in:
57
notes/skill-provider-anthropic.org
Normal file
57
notes/skill-provider-anthropic.org
Normal file
@@ -0,0 +1,57 @@
|
||||
#+TITLE - Anthropic (Claude) Provider Skill
|
||||
#+AUTHOR - org-agent
|
||||
#+SKILL_NAME - skill-provider-anthropic
|
||||
#+DEPENDS_ON - skill-environment-config
|
||||
|
||||
This skill registers Anthropic's Claude as a pluggable System 1 backend.
|
||||
|
||||
* Backend Implementation
|
||||
#+begin_src lisp
|
||||
(defun execute-anthropic-request (prompt system-prompt)
|
||||
"Executes a completion request via the Anthropic (Claude) API."
|
||||
(let ((api-key (org-agent::get-env "ANTHROPIC_API_KEY"))
|
||||
(config-pkg (find-package :org-agent.skills.skill-environment-config)))
|
||||
(unless api-key
|
||||
(return-from execute-anthropic-request "(:type :LOG :payload (:text \"Anthropic key missing\"))"))
|
||||
|
||||
(let* ((get-config-fn (when config-pkg (find-symbol "GET-CONFIG-ATTRIBUTE" config-pkg)))
|
||||
(model (if (and get-config-fn (fboundp get-config-fn))
|
||||
(funcall get-config-fn :LLM_MODEL_ANTHROPIC "claude-3-5-sonnet-20240620")
|
||||
"claude-3-5-sonnet-20240620"))
|
||||
(url "https://api.anthropic.com/v1/messages")
|
||||
(body (cl-json:encode-json-to-string
|
||||
`((model . ,model)
|
||||
(max_tokens . 1024)
|
||||
(system . ,system-prompt)
|
||||
(messages . (((role . "user") (content . ,prompt))))))))
|
||||
(handler-case
|
||||
(let* ((response (dex:post url
|
||||
:headers `(("Content-Type" . "application/json")
|
||||
("x-api-key" . ,api-key)
|
||||
("anthropic-version" . "2023-06-01"))
|
||||
:content body))
|
||||
(json (cl-json:decode-json-from-string response)))
|
||||
;; Extract content from Anthropic response
|
||||
(cdr (assoc :text (car (cdr (assoc :content json))))))
|
||||
(error (c)
|
||||
(format nil "(:type :LOG :payload (:text \"Anthropic Failure (~a) - ~a\"))" model c))))))
|
||||
|
||||
;; Register the backend
|
||||
(org-agent:register-neuro-backend :anthropic #'execute-anthropic-request)
|
||||
(org-agent:register-neuro-backend :claude #'execute-anthropic-request)
|
||||
|
||||
(defun get-available-models ()
|
||||
"Returns the list of LLM models supported by this provider."
|
||||
'((:id "claude-3-5-sonnet-20240620" :context "200k")
|
||||
(:id "claude-3-opus-20240229" :context "200k")
|
||||
(:id "claude-3-haiku-20240307" :context "200k")))
|
||||
#+end_src
|
||||
|
||||
* Registration
|
||||
#+begin_src lisp
|
||||
(defskill :skill-provider-anthropic
|
||||
:priority 100
|
||||
:trigger (lambda (context) nil)
|
||||
:neuro (lambda (context) nil)
|
||||
:symbolic (lambda (action context) action))
|
||||
#+end_src
|
||||
Reference in New Issue
Block a user