56 lines
2.5 KiB
Org Mode
56 lines
2.5 KiB
Org Mode
#+TITLE - OpenAI Provider Skill
|
|
#+AUTHOR - org-agent
|
|
#+SKILL_NAME - skill-provider-openai
|
|
#+DEPENDS_ON - skill-environment-config
|
|
|
|
This skill registers OpenAI as a pluggable System 1 backend for the Neurosymbolic Kernel.
|
|
|
|
* Backend Implementation
|
|
#+begin_src lisp
|
|
(defun execute-openai-request (prompt system-prompt)
|
|
"Executes a completion request via the OpenAI API."
|
|
(let ((api-key (org-agent::get-env "OPENAI_API_KEY"))
|
|
(config-pkg (find-package :org-agent.skills.skill-environment-config)))
|
|
(unless api-key
|
|
(return-from execute-openai-request "(:type :LOG :payload (:text \"OpenAI 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_OPENAI "gpt-4-turbo-preview")
|
|
"gpt-4-turbo-preview"))
|
|
(url "https://api.openai.com/v1/chat/completions")
|
|
(body (cl-json:encode-json-to-string
|
|
`((model . ,model)
|
|
(messages . (((role . "system") (content . ,system-prompt))
|
|
((role . "user") (content . ,prompt))))
|
|
(temperature . 0.2)))))
|
|
(handler-case
|
|
(let* ((response (dex:post url
|
|
:headers `(("Content-Type" . "application/json")
|
|
("Authorization" . ,(format nil "Bearer ~a" api-key)))
|
|
:content body))
|
|
(json (cl-json:decode-json-from-string response)))
|
|
;; Extract content from OpenAI response structure
|
|
(cdr (assoc :content (cdr (assoc :message (car (cdr (assoc :choices json))))))))
|
|
(error (c)
|
|
(format nil "(:type :LOG :payload (:text \"OpenAI Failure (~a) - ~a\"))" model c))))))
|
|
|
|
;; Register the backend upon skill load
|
|
(org-agent:register-neuro-backend :openai #'execute-openai-request)
|
|
|
|
(defun get-available-models ()
|
|
"Returns the list of LLM models supported by this provider."
|
|
'((:id "gpt-4-turbo-preview" :context "128k")
|
|
(:id "gpt-4o" :context "128k")
|
|
(:id "gpt-4" :context "8k")
|
|
(:id "gpt-3.5-turbo" :context "16k")))
|
|
#+end_src
|
|
|
|
* Registration
|
|
#+begin_src lisp
|
|
(defskill :skill-provider-openai
|
|
:priority 100 ; Providers are foundational
|
|
:trigger (lambda (context) nil) ; No cognitive trigger
|
|
:neuro (lambda (context) nil)
|
|
:symbolic (lambda (action context) action))
|
|
#+end_src |