Skip to content

fix: use system_instruction conditionally #334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions chatgpt-shell-google.el
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,30 @@ This gets set once for each MODEL, based on a heuristic."
"google_search_retrieval"
"google_search")))

(defun chatgpt-shell-google--is-system-instruction-supported (model)
"Returns true if system_instruction is supported in the POST payload.

This is based on a heuristic."
(when-let* ((current-model model)
(is-google (string= (map-elt current-model :provider) "Google"))
(version (map-elt current-model :version)))
(not (string-match "gemma-3-27b-it" version))))


(defun chatgpt-shell-google--maybe-system-prompt (settings model in-sys-instruction)
"returns the appropriate portion of prompt depending on SETTINGS, MODEL, and whether
in system instruction."
(let ((sys-prompt (map-elt settings :system-prompt))
(sys-instruction-supported
(chatgpt-shell-google--is-system-instruction-supported model)))
(when sys-prompt
(if in-sys-instruction
(when sys-instruction-supported
`((system_instruction . ((parts . ((text . ,sys-prompt)))))))
(when (not sys-instruction-supported)
`(((role . "user")
(parts . ,(vconcat `(((text . ,sys-prompt))))))))))))

(defun chatgpt-shell-google-models ()
"Build a list of Google LLM models available."
;; Context windows have been verified as of 11/26/2024. See
Expand Down Expand Up @@ -319,9 +343,9 @@ or

Compose using PROMPT, CONTEXT, SETTINGS and MODEL."
(append
(when (map-elt settings :system-prompt)
`((system_instruction . ((parts . ((text . ,(map-elt settings :system-prompt))))))))
(chatgpt-shell-google--maybe-system-prompt settings model 't)
`((contents . ,(vconcat
(chatgpt-shell-google--maybe-system-prompt settings model 'nil)
(chatgpt-shell-google--gemini-user-model-messages
(append context
(when prompt
Expand Down