#+TITLE: AI Configuration
#+PROPERTY: header-args :tangle yes

* AI Settings

** Ellama

#+begin_src elisp :tangle yes
  ;; YOU DON'T NEED NONE OF THIS CODE FOR SIMPLE INSTALL
  ;; IT IS AN EXAMPLE OF CUSTOMIZATION.
  (use-package ellama
    :init
    (require 'llm-openai)
    ;; setup key bindings
    (setq ellama-keymap-prefix "C-c e")
    )
#+end_src

#+begin_src elisp ~/.emacs.d/custom.el :tangle yes
  (setopt ellama-providers
  	'(
  	  ;; Ollama Provider (added here with a name)
  	  ("ollama" . (make-llm-ollama
                               ;; Consider a dedicated embedding model if gemma isn't ideal for it.
                               :chat-model "gemma3:latest"
                               :embedding-model "gemma3:latest" ; Or e.g., "nomic-embed-text"
                               :default-chat-non-standard-params '(("num_ctx" . 8192))))

  	  ("openai" . (make-llm-openai
                         :key (auth-source-pass-get "api-key" "www/openai.com/amr@gharbeia.net")
                         :chat-model "gpt-4o"
  		       :embedding-model "text-embedding-3-large"))

            ("groq" . (make-llm-openai-compatible
                       :url "https://api.groq.com/openai/v1"
                       :key (auth-source-pass-get "api-key" "www/console.groq.com/groq@amr.gharbeia.net")
                       ;; Check Groq console for available models, these might change
                       :chat-model "llama3-70b-8192" ; Example, verify on Groq
                       :embedding-model "llama3-70b-8192")) ; Groq might not offer dedicated embedding models via this API
            ))

  ;; --- Set Active Providers ---
  ;; Choose your default provider from the list above by its name
  (setopt ellama-provider "ollama") ; Or "ollama", "openai", "groq"

  ;; You can specify different providers for different tasks if needed
  (setopt ellama-translation-provider "ollama")
  (setopt ellama-naming-provider "ollama")
  (setopt ellama-naming-scheme 'ellama-generate-name-by-llm)

  (setq llm-debug t)
#+end_src

#+begin_src elisp
  (use-package ellama
  :ensure t
  :bind ("C-c e" . ellama)
  ;; send last message in chat buffer with C-c C-c
  :hook (org-ctrl-c-ctrl-c-final . ellama-chat-send-last-message)
  :init (setopt ellama-auto-scroll t)
  :config
  ;; show ellama context in header line in all buffers
  (ellama-context-header-line-global-mode +1)
  ;; show ellama session id in header line in all buffers
  (ellama-session-header-line-global-mode +1))
#+end_src

** GPTel
   
#+begin_src elisp :tangle yes
  (use-package gptel)
#+end_src

#+begin_src elisp :tangle yes
  (setq gptel-api-key (auth-source-pass-get "api-key" "www/console.groq.com/groq@amr.gharbeia.net"))
#+end_src

#+begin_src elisp :tangle yes
  (gptel-make-openai "Groq"               ;Any name you want
  :host "api.groq.com"
  :endpoint "/openai/v1/chat/completions"
  :stream t
  :key (auth-source-pass-get "api-key" "www/console.groq.com/groq@amr.gharbeia.net")                   ;can be a function that returns the key
  :models '(llama-3.1-70b-versatile
            llama-3.1-8b-instant
            llama3-70b-8192
            llama3-8b-8192
            mixtral-8x7b-32768
            gemma-7b-it))
#+end_src

** Elisa

#+begin_src elisp :tangle yes
  (use-package elisa
    :defer t
    :init
    (setopt elisa-limit 5)
    (require 'llm-ollama)
    (setopt elisa-embeddings-provider (make-llm-ollama :embedding-model "nomic-embed-text"))
    (setopt elisa-chat-provider (make-llm-ollama
                                 :chat-model "sskostyaev/openchat:8k-rag"
                                 :embedding-model "nomic-embed-text"))
    )
#+end_src

** OpenCortex (Local Foundry)

#+begin_src elisp :tangle yes
  (use-package opencortex
    :straight nil
    :load-path "~/.local/share/opencortex/src"
    :commands (opencortex-connect opencortex-disconnect)
    :init
    (setq opencortex-host "127.0.0.1")
    (setq opencortex-port 9105)
    (setq opencortex-executable-path "~/.local/share/opencortex/bin/opencortex-server")
    :config
    (message "opencortex: Local brain configured at %s" opencortex-executable-path))
#+end_src