fix(chaos): use standard getenv for absolute tangle paths
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#+PROPERTY: header-args:lisp :tangle (concat (uiop:getenv "INSTALL_DIR") "/skills/org-skill-llm-gateway.lisp" (expand-file-name ""))
|
||||
#+PROPERTY: header-args:lisp :tangle (concat (getenv "INSTALL_DIR") "/skills/org-skill-llm-gateway.lisp" (expand-file-name ""))
|
||||
:PROPERTIES:
|
||||
:ID: llm-gateway-spec
|
||||
:CREATED: [2026-04-10 Thu]
|
||||
@@ -11,7 +11,7 @@
|
||||
The *LLM Gateway* skill provides a unified interface for interacting with multiple Large Language Model providers.
|
||||
|
||||
* Test Suite
|
||||
#+begin_src lisp :tangle (concat (uiop:getenv "INSTALL_DIR") "/skills/llm-gateway-tests.lisp" (expand-file-name ""))
|
||||
#+begin_src lisp :tangle (concat (getenv "INSTALL_DIR") "/skills/llm-gateway-tests.lisp" (expand-file-name ""))
|
||||
(defpackage :opencortex-llm-gateway-tests
|
||||
(:use :cl :fiveam :opencortex)
|
||||
(:export #:llm-gateway-suite))
|
||||
@@ -24,10 +24,10 @@ The *LLM Gateway* skill provides a unified interface for interacting with multip
|
||||
(test test-llm-gateway-timeout
|
||||
"Tier 2 Chaos: Verify that LLM Gateway handles connection failures gracefully."
|
||||
;; Point to a non-existent port to force a connection error
|
||||
(let ((old-host (uiop:getenv "OLLAMA_HOST")))
|
||||
(let ((old-host (getenv "OLLAMA_HOST")))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(setf (uiop:getenv "OLLAMA_HOST") "localhost:1")
|
||||
(setf (getenv "OLLAMA_HOST") "localhost:1")
|
||||
(let ((fn (or (find-symbol "EXECUTE-LLM-REQUEST" :opencortex.skills.org-skill-llm-gateway)
|
||||
(find-symbol "EXECUTE-LLM-REQUEST" :opencortex))))
|
||||
(if fn
|
||||
@@ -35,18 +35,18 @@ The *LLM Gateway* skill provides a unified interface for interacting with multip
|
||||
(is (eq (getf result :status) :error))
|
||||
(is (uiop:string-prefix-p "Ollama Failure" (getf result :message))))
|
||||
(fail "Could not find EXECUTE-LLM-REQUEST symbol"))))
|
||||
(setf (uiop:getenv "OLLAMA_HOST") old-host))))
|
||||
(setf (getenv "OLLAMA_HOST") old-host))))
|
||||
#+end_src
|
||||
|
||||
* Implementation
|
||||
|
||||
** Package Context
|
||||
#+begin_src lisp :tangle (concat (uiop:getenv "INSTALL_DIR") "/skills/org-skill-llm-gateway.lisp" (expand-file-name ""))
|
||||
#+begin_src lisp :tangle (concat (getenv "INSTALL_DIR") "/skills/org-skill-llm-gateway.lisp" (expand-file-name ""))
|
||||
(in-package :opencortex)
|
||||
#+end_src
|
||||
|
||||
** Skill Metadata
|
||||
#+begin_src lisp :tangle (concat (uiop:getenv "INSTALL_DIR") "/skills/org-skill-llm-gateway.lisp" (expand-file-name ""))
|
||||
#+begin_src lisp :tangle (concat (getenv "INSTALL_DIR") "/skills/org-skill-llm-gateway.lisp" (expand-file-name ""))
|
||||
(defparameter *skill-llm-gateway*
|
||||
'(:name "llm-gateway"
|
||||
:description "Unified provider-agnostic LLM interface."
|
||||
@@ -56,15 +56,15 @@ The *LLM Gateway* skill provides a unified interface for interacting with multip
|
||||
#+end_src
|
||||
|
||||
** Request Execution
|
||||
#+begin_src lisp :tangle (concat (uiop:getenv "INSTALL_DIR") "/skills/org-skill-llm-gateway.lisp" (expand-file-name ""))
|
||||
#+begin_src lisp :tangle (concat (getenv "INSTALL_DIR") "/skills/org-skill-llm-gateway.lisp" (expand-file-name ""))
|
||||
(defun execute-llm-request (&key prompt system-prompt provider model)
|
||||
"Generic executor for all LLM providers."
|
||||
(let* ((active-provider (or provider :ollama))
|
||||
(api-key (uiop:getenv (format nil "~:@(~a_API_KEY~)" active-provider)))
|
||||
(api-key (getenv (format nil "~:@(~a_API_KEY~)" active-provider)))
|
||||
(full-prompt (if system-prompt (format nil "~a~%~%~a" system-prompt prompt) prompt)))
|
||||
(case active-provider
|
||||
(:ollama
|
||||
(let* ((host (or (uiop:getenv "OLLAMA_HOST") "localhost:11434"))
|
||||
(let* ((host (or (getenv "OLLAMA_HOST") "localhost:11434"))
|
||||
(url (format nil "http://~a/api/generate" host))
|
||||
(body (cl-json:encode-json-to-string `((model . ,(or model "llama3")) (prompt . ,full-prompt) (stream . :false)))))
|
||||
(handler-case
|
||||
@@ -76,13 +76,13 @@ The *LLM Gateway* skill provides a unified interface for interacting with multip
|
||||
#+end_src
|
||||
|
||||
** Cognitive Tools
|
||||
#+begin_src lisp :tangle (concat (uiop:getenv "INSTALL_DIR") "/skills/org-skill-llm-gateway.lisp" (expand-file-name ""))
|
||||
#+begin_src lisp :tangle (concat (getenv "INSTALL_DIR") "/skills/org-skill-llm-gateway.lisp" (expand-file-name ""))
|
||||
(def-cognitive-tool :get-ollama-embedding
|
||||
"Generates vector embeddings via Ollama API."
|
||||
((:text :type :string :description "Text to embed."))
|
||||
:body (lambda (args)
|
||||
(let ((text (getf args :text)))
|
||||
(let* ((host (or (uiop:getenv "OLLAMA_HOST") "localhost:11434"))
|
||||
(let* ((host (or (getenv "OLLAMA_HOST") "localhost:11434"))
|
||||
(url (format nil "http://~a/api/embeddings" host))
|
||||
(body (cl-json:encode-json-to-string `((model . "nomic-embed-text") (prompt . ,text)))))
|
||||
(handler-case
|
||||
@@ -92,7 +92,7 @@ The *LLM Gateway* skill provides a unified interface for interacting with multip
|
||||
(error (c) (harness-log "OLLAMA EMBED ERROR: ~a" c) nil))))))
|
||||
#+end_src
|
||||
|
||||
#+begin_src lisp :tangle (concat (uiop:getenv "INSTALL_DIR") "/skills/org-skill-llm-gateway.lisp" (expand-file-name ""))
|
||||
#+begin_src lisp :tangle (concat (getenv "INSTALL_DIR") "/skills/org-skill-llm-gateway.lisp" (expand-file-name ""))
|
||||
(def-cognitive-tool :ask-llm
|
||||
"Unified interface for interacting with LLM providers."
|
||||
((:prompt :type :string :description "The user prompt")
|
||||
@@ -107,7 +107,7 @@ The *LLM Gateway* skill provides a unified interface for interacting with multip
|
||||
#+end_src
|
||||
|
||||
** Skill Registration
|
||||
#+begin_src lisp :tangle (concat (uiop:getenv "INSTALL_DIR") "/skills/org-skill-llm-gateway.lisp" (expand-file-name ""))
|
||||
#+begin_src lisp :tangle (concat (getenv "INSTALL_DIR") "/skills/org-skill-llm-gateway.lisp" (expand-file-name ""))
|
||||
(defskill :skill-llm-gateway
|
||||
:priority 50
|
||||
:trigger (lambda (ctx) (declare (ignore ctx)) t)
|
||||
|
||||
Reference in New Issue
Block a user