Skip to content

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ccqpein committed Nov 20, 2024
1 parent be1b5e1 commit bbea0fa
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 71 deletions.
67 changes: 37 additions & 30 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ Streaming is enabled by default. =(setq chatgpt-shell-streaming nil)= to disable
(push `(,symbol
,(car
(split-string
(or (get (indirect-variable symbol)
(or (documentation-property symbol 'variable-documentation)
(get (indirect-variable symbol)
'variable-documentation)
(get symbol 'variable-documentation)
"")
Expand All @@ -240,39 +241,44 @@ Streaming is enabled by default. =(setq chatgpt-shell-streaming nil)= to disable
#+RESULTS:
| Custom variable | Description |
|------------------------------------------------------------------+------------------------------------------------------------------------------|
| chatgpt-shell-prompt-compose-view-mode-hook | Hook run after entering or leaving `chatgpt-shell-prompt-compose-view-mode'. |
| chatgpt-shell-display-function | Function to display the shell. Set to `display-buffer' or custom function. |
| chatgpt-shell-model-versions | The list of ChatGPT OpenAI models to swap from. |
| chatgpt-shell-system-prompt | The system prompt `chatgpt-shell-system-prompts' index. |
| chatgpt-shell-default-prompts | List of default prompts to choose from. |
| chatgpt-shell-read-string-function | Function to read strings from user. |
| chatgpt-shell-model-temperature | What sampling temperature to use, between 0 and 2, or nil. |
| chatgpt-shell-transmitted-context-length | Controls the amount of context provided to chatGPT. |
| chatgpt-shell-system-prompts | List of system prompts to choose from. |
| chatgpt-shell-streaming | Whether or not to stream ChatGPT responses (show chunks as they arrive). |
| chatgpt-shell-prompt-header-refactor-code | Prompt header of `refactor-code`. |
| chatgpt-shell-auth-header | Function to generate the request's `Authorization' header string. |
| chatgpt-shell-prompt-header-whats-wrong-with-last-command | Prompt header of `whats-wrong-with-last-command`. |
| chatgpt-shell-prompt-header-write-git-commit | Prompt header of `git-commit`. |
| chatgpt-shell-logging | Logging disabled by default (slows things down). |
| chatgpt-shell-google-api-url-base | Google API’s base URL. |
| chatgpt-shell-anthropic-models | List of Anthropic LLM models available. |
| chatgpt-shell-google-models | List of Google LLM models available. |
| chatgpt-shell-openai-models | List of OpenAI LLM models available. |
| chatgpt-shell-prompt-header-write-git-commit | Prompt header of ‘git-commit‘. |
| chatgpt-shell-highlight-blocks | Whether or not to highlight source blocks. |
| chatgpt-shell-display-function | Function to display the shell. Set to ‘display-buffer’ or custom function. |
| chatgpt-shell-prompt-header-generate-unit-test | Prompt header of ‘generate-unit-test‘. |
| chatgpt-shell-prompt-header-refactor-code | Prompt header of ‘refactor-code‘. |
| chatgpt-shell-prompt-header-proofread-region | Prompt header used by ‘chatgpt-shell-proofread-region‘. |
| chatgpt-shell-welcome-function | Function returning welcome message or nil for no message. |
| chatgpt-shell-prompt-query-response-style | Determines the prompt style when invoking from other buffers. |
| chatgpt-shell-root-path | Root path location to store internal shell files. |
| chatgpt-shell-prompt-header-proofread-region | Promt header of `proofread-region`. |
| chatgpt-shell-model-version | The active ChatGPT OpenAI model index. |
| chatgpt-shell-logging | Logging disabled by default (slows things down). |
| chatgpt-shell-api-url-base | OpenAI API’s base URL. |
| chatgpt-shell-google-key | Google API key as a string or a function that loads and returns it. |
| chatgpt-shell-babel-headers | Additional headers to make babel blocks work. |
| chatgpt-shell--pretty-smerge-mode-hook | Hook run after entering or leaving ‘chatgpt-shell--pretty-smerge-mode’. |
| chatgpt-shell-source-block-actions | Block actions for known languages. |
| chatgpt-shell-insert-dividers | Whether or not to display a divider between requests and responses. |
| chatgpt-shell-prompt-header-eshell-summarize-last-command-output | Prompt header of `eshell-summarize-last-command-output`. |
| chatgpt-shell-welcome-function | Function returning welcome message or nil for no message. |
| chatgpt-shell-api-url-path | OpenAI API's URL path. |
| chatgpt-shell-additional-curl-options | Additional options for `curl' command. |
| chatgpt-shell-openai-key | OpenAI key as a string or a function that loads and returns it. |
| chatgpt-shell-default-prompts | List of default prompts to choose from. |
| chatgpt-shell-anthropic-key | Anthropic API key as a string or a function that loads and returns it. |
| chatgpt-shell-prompt-header-eshell-summarize-last-command-output | Prompt header of ‘eshell-summarize-last-command-output‘. |
| chatgpt-shell-system-prompt | The system prompt ‘chatgpt-shell-system-prompts’ index. |
| chatgpt-shell-transmitted-context-length | Controls the amount of context provided to chatGPT. |
| chatgpt-shell-root-path | Root path location to store internal shell files. |
| chatgpt-shell-prompt-header-whats-wrong-with-last-command | Prompt header of ‘whats-wrong-with-last-command‘. |
| chatgpt-shell-read-string-function | Function to read strings from user. |
| chatgpt-shell-after-command-functions | Abnormal hook (i.e. with parameters) invoked after each command. |
| chatgpt-shell-prompt-header-describe-code | Prompt header of `describe-code`. |
| chatgpt-shell-api-url-base | OpenAI API's base URL. |
| chatgpt-shell-babel-headers | Additional headers to make babel blocks work. |
| chatgpt-shell-highlight-blocks | Whether or not to highlight source blocks. |
| chatgpt-shell-system-prompts | List of system prompts to choose from. |
| chatgpt-shell-openai-key | OpenAI key as a string or a function that loads and returns it. |
| chatgpt-shell-prompt-header-describe-code | Prompt header of ‘describe-code‘. |
| chatgpt-shell-insert-dividers | Whether or not to display a divider between requests and responses. |
| chatgpt-shell-models | The list of models to swap from. |
| chatgpt-shell-language-mapping | Maps external language names to Emacs names. |
| chatgpt-shell-prompt-header-generate-unit-test | Prompt header of `generate-unit-test`. |
| chatgpt-shell-prompt-compose-view-mode-hook | Hook run after entering or leaving ‘chatgpt-shell-prompt-compose-view-mode’. |
| chatgpt-shell-streaming | Whether or not to stream ChatGPT responses (show chunks as they arrive). |
| chatgpt-shell-anthropic-api-url-base | Anthropic API’s base URL. |
| chatgpt-shell-model-temperature | What sampling temperature to use, between 0 and 2, or nil. |
| chatgpt-shell-request-timeout | How long to wait for a request to time out in seconds. |

There are more. Browse via =M-x set-variable=
Expand Down Expand Up @@ -349,6 +355,7 @@ Thanks to [[https://github.com/tuhdo][tuhdo]] for the custom display function.
| | chatgpt-shell-prompt-compose-swap-model-version | Swap the compose buffer's model version. |
| | chatgpt-shell-describe-code | Describe code from region using ChatGPT. |
| C-<up> or M-p | chatgpt-shell-previous-input | Cycle backwards through input history, saving input. |
| C-c C-v | chatgpt-shell-swap-model | Swap model version from `chatgpt-shell-models'. |
| C-x C-s | chatgpt-shell-save-session-transcript | Save shell transcript to file. |
| | chatgpt-shell-proofread-region | Proofread text from region using ChatGPT. |
| | chatgpt-shell-prompt-compose-quit-and-close-frame | Quit compose and close frame if it's the last window. |
Expand Down Expand Up @@ -381,9 +388,9 @@ Thanks to [[https://github.com/tuhdo][tuhdo]] for the custom display function.
| | chatgpt-shell-rename-buffer | Rename current shell buffer. |
| | chatgpt-shell-remove-block-overlays | Remove block overlays. Handy for renaming blocks. |
| | chatgpt-shell-send-region | Send region to ChatGPT. |
| C-c C-v | chatgpt-shell-swap-model-version | Swap model version from `chatgpt-shell-model-versions'. |
| | chatgpt-shell-send-and-review-region | Send region to ChatGPT, review before submitting. |
| C-M-h | chatgpt-shell-mark-at-point-dwim | Mark source block if at point. Mark all output otherwise. |
| | chatgpt-shell--pretty-smerge-mode | Minor mode to display overlays for conflict markers. |
| | chatgpt-shell-mark-block | Mark current block in compose buffer. |
| | chatgpt-shell-prompt-compose-reply | Reply as a follow-up and compose another query. |
| | chatgpt-shell-set-as-primary-shell | Set as primary shell when there are multiple sessions. |
Expand Down
42 changes: 18 additions & 24 deletions chatgpt-shell.el
Original file line number Diff line number Diff line change
Expand Up @@ -199,28 +199,22 @@ Can be used compile or run source block at point."
(cons (const primary-action) (function :tag "Action:"))))
:group 'chatgpt-shell)

(defcustom chatgpt-shell-model-versions
(defcustom chatgpt-shell-models
(append chatgpt-shell-openai-models
chatgpt-shell-anthropic-models
chatgpt-shell-google-models)
"The list of ChatGPT OpenAI models to swap from.
"The list of models to swap from.
The list of models supported by /v1/chat/completions endpoint is
documented at
https://platform.openai.com/docs/models/model-endpoint-compatibility."
The list of models supported by chatgpt-shell.el."
:type '(repeat (alist :key-type symbol :value-type sexp))
:group 'chatgpt-shell)

(defcustom chatgpt-shell-model-version 0
"The active ChatGPT OpenAI model index.
See `chatgpt-shell-model-versions' for available model versions.
See `chatgpt-shell-models' for available model versions.
Swap using `chatgpt-shell-swap-model-version'.
The list of models supported by /v1/chat/completions endpoint is
documented at
https://platform.openai.com/docs/models/model-endpoint-compatibility."
Swap using `chatgpt-shell-swap-model'."
:type '(choice (string :tag "String")
(integer :tag "Integer")
(const :tag "Nil" nil))
Expand Down Expand Up @@ -317,7 +311,7 @@ Or nil if none."
chatgpt-shell-model-version)
((integerp chatgpt-shell-model-version)
(let ((model (nth chatgpt-shell-model-version
chatgpt-shell-model-versions)))
chatgpt-shell-models)))
(cond ((stringp model)
model)
((stringp (map-elt model :version))
Expand Down Expand Up @@ -415,15 +409,15 @@ Downloaded from https://github.com/f/awesome-chatgpt-prompts."
(interactive)
(message "chatgpt-shell v%s" chatgpt-shell--version))

(defun chatgpt-shell-swap-model-version ()
"Swap model version from `chatgpt-shell-model-versions'."
(defun chatgpt-shell-swap-model ()
"Swap model version from `chatgpt-shell-models'."
(interactive)
(if-let* ((last-label (chatgpt-shell--model-label))
(all-models (seq-remove
(lambda (item)
(string-equal (map-elt item :version)
(chatgpt-shell-model-version)))
chatgpt-shell-model-versions))
chatgpt-shell-models))
(width (let ((width))
(mapc (lambda (model)
(unless width
Expand Down Expand Up @@ -556,7 +550,7 @@ or
(or (seq-find (lambda (model)
(equal (map-elt model :version)
(or versioned (chatgpt-shell-model-version))))
chatgpt-shell-model-versions)
chatgpt-shell-models)
(error "Service %s not found"
(chatgpt-shell-model-version))))

Expand Down Expand Up @@ -634,7 +628,7 @@ Set SYSTEM-PROMPT to override variable `chatgpt-shell-system-prompt'"
(define-key chatgpt-shell-mode-map (kbd "C-c C-c")
#'chatgpt-shell-ctrl-c-ctrl-c)
(define-key chatgpt-shell-mode-map (kbd "C-c C-v")
#'chatgpt-shell-swap-model-version)
#'chatgpt-shell-swap-model)
(define-key chatgpt-shell-mode-map (kbd "C-c C-s")
#'chatgpt-shell-swap-system-prompt)
(define-key chatgpt-shell-mode-map (kbd "C-c C-p")
Expand Down Expand Up @@ -767,10 +761,10 @@ This is used for sending a prompt to in the background."
(lambda ()
(interactive)
(setq-local chatgpt-shell-model-version
(seq-position chatgpt-shell-model-versions ,version))
(seq-position chatgpt-shell-models ,version))
(chatgpt-shell--update-prompt t)
(chatgpt-shell-interrupt nil))])
chatgpt-shell-model-versions))
chatgpt-shell-models))
("Prompts"
,@(mapcar (lambda (prompt)
`[,(car prompt)
Expand All @@ -785,7 +779,7 @@ This is used for sending a prompt to in the background."
(easy-menu-add chatgpt-shell-system-prompts-menu))

(defun chatgpt-shell--update-prompt (rename-buffer)
"Update prompt and prompt regexp from `chatgpt-shell-model-versions'.
"Update prompt and prompt regexp from `chatgpt-shell-models'.
Set RENAME-BUFFER to also rename the buffer accordingly."
(unless (derived-mode-p 'chatgpt-shell-mode)
Expand Down Expand Up @@ -1433,7 +1427,7 @@ With prefix REVIEW prompt before sending to ChatGPT."
QUERY: Request query text.
BUFFER (optional): Buffer to insert to or omit to insert to current buffer.
MODEL-VERSION (optional): Index from `chatgpt-shell-model-versions' or string.
MODEL-VERSION (optional): Index from `chatgpt-shell-models' or string.
SYSTEM-PROMPT (optional): As string.
STREAMING (optional): Non-nil to stream insertion.
START (optional): Beginning of region to replace (overrides active region).
Expand Down Expand Up @@ -1509,7 +1503,7 @@ END (optional): End of region to replace (overrides active region)."
QUERY: Request query text.
ON-OUTPUT: Of the form (lambda (output))
ON-FINISHED: Of the form (lambda (success))
MODEL-VERSION (optional): Index from `chatgpt-shell-model-versions' or string.
MODEL-VERSION (optional): Index from `chatgpt-shell-models' or string.
SYSTEM-PROMPT (optional): As string.
STREAMING (optional): non-nil to received streamed ON-OUTPUT events."
(unless query
Expand Down Expand Up @@ -2797,7 +2791,7 @@ Do not wrap snippets in markdown blocks.\n\n"
QUERY: Request query text.
BUFFER (optional): Buffer to insert to or omit to insert to current buffer.
MODEL-VERSION (optional): Index from `chatgpt-shell-model-versions' or string.
MODEL-VERSION (optional): Index from `chatgpt-shell-models' or string.
SYSTEM-PROMPT (optional): As string."
(unless query
(error "Missing mandatory \"query\" param"))
Expand Down Expand Up @@ -3279,7 +3273,7 @@ If BACKWARDS is non-nil, go to previous interaction."
(unless (derived-mode-p 'chatgpt-shell-prompt-compose-mode)
(user-error "Not in a shell compose buffer"))
(with-current-buffer (chatgpt-shell--primary-buffer)
(chatgpt-shell-swap-model-version))
(chatgpt-shell-swap-model))
(rename-buffer (chatgpt-shell-prompt-compose-buffer-name)))

(defun chatgpt-shell-prompt-compose-buffer ()
Expand Down
Loading

0 comments on commit bbea0fa

Please sign in to comment.