Skip to content

Instantly share code, notes, and snippets.

@kaznak
Created February 10, 2026 05:09
Show Gist options
  • Select an option

  • Save kaznak/31f7c76f919f4111340471e094ac2a9f to your computer and use it in GitHub Desktop.

Select an option

Save kaznak/31f7c76f919f4111340471e094ac2a9f to your computer and use it in GitHub Desktop.
emacs gptel で tool use 付きで gemini と対話するための設定, leaf.el 使用版
(leaf gptel
:doc "LLM Client (Gemini Main)"
:bind (("C-c <return>" . gptel-send)
("C-c C-<return>" . gptel-menu))
:config
;; ログレベル (動作確認用: 問題なければ 'info に戻す)
(setq gptel-log-level 'debug)
;; Google (Gemini) 設定
(let ((google-key (my/get-secret 'google-ai-studio-sandbox)))
(when google-key
(setq gptel-backend
(gptel-make-gemini "Gemini"
:key google-key
:stream t
:models '(
gemini-2.0-flash
gemini-2.5-flash
)))))
;; デフォルトモデル
(setq gptel-model 'gemini-2.0-flash)
;; ★ ツール (Google Search) 自動注入設定
(defun my/gptel-gemini-add-search-tool (orig-fun &rest args)
"Gemini へのリクエスト時のみ、Google Search ツールを注入する"
(let ((data (apply orig-fun args))
(backend (car args)))
(if (and (gptel-backend-p backend)
(string-match-p "Gemini" (gptel-backend-name backend)))
;; パラメータを追加
(append data
`(:tools [((googleSearch . ,(make-hash-table)))]))
;; Gemini 以外はそのまま
data)))
;; アドバイスを適用
(advice-add 'gptel--request-data :around #'my/gptel-gemini-add-search-tool))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment