Skip to content

Commit 75ffc4a

Browse files
committed
Merge branch 'goog-model-discovery' of github.com:DinoChiesa/chatgpt-shell into goog-model-discovery
2 parents 7e59428 + 5afbdae commit 75ffc4a

7 files changed

+325
-121
lines changed

README.org

Lines changed: 96 additions & 91 deletions
Large diffs are not rendered by default.

chatgpt-shell-anthropic.el

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,23 @@ VALIDATE-COMMAND handler."
9292
(list
9393
;; https://docs.anthropic.com/en/docs/about-claude/models#model-comparison-table
9494
;; A token is equivalent to _about_ 4 characters.
95-
(chatgpt-shell-anthropic--make-model :version "claude-3-5-sonnet-20241022"
96-
:short-version "3-5-sonnet-20241022"
95+
(chatgpt-shell-anthropic--make-model :version "claude-3-7-sonnet-latest"
96+
:short-version "3.7-sonnet"
9797
:token-width 4
9898
:max-tokens 8192
9999
:context-window 200000)
100-
(chatgpt-shell-anthropic--make-model :version "claude-3-5-haiku-20241022"
101-
:short-version "3-5-haiku-20241022"
100+
(chatgpt-shell-anthropic--make-model :version "claude-3-5-sonnet-latest"
101+
:short-version "3.5-sonnet"
102102
:token-width 4
103103
:max-tokens 8192
104104
:context-window 200000)
105-
(chatgpt-shell-anthropic--make-model :version "claude-3-opus-20240229"
106-
:short-version "3-opus-20240229"
105+
(chatgpt-shell-anthropic--make-model :version "claude-3-5-haiku-latest"
106+
:short-version "3.5-haiku"
107+
:token-width 4
108+
:max-tokens 8192
109+
:context-window 200000)
110+
(chatgpt-shell-anthropic--make-model :version "claude-3-opus-latest"
111+
:short-version "3-opus"
107112
:token-width 4
108113
:max-tokens 4096
109114
:context-window 200000)))

chatgpt-shell-deepseek.el

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
;;; chatgpt-shell-deepseek.el --- Deepseek-specific logic -*- lexical-binding: t; -*-
2+
3+
;; Author: Alvaro Ramirez https://xenodium.com
4+
;; URL: https://github.com/xenodium/chatgpt-shell
5+
6+
;; This package is free software; you can redistribute it and/or modify
7+
;; it under the terms of the GNU General Public License as published by
8+
;; the Free Software Foundation; either version 3, or (at your option)
9+
;; any later version.
10+
11+
;; This package is distributed in the hope that it will be useful,
12+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
;; GNU General Public License for more details.
15+
16+
;;; Commentary:
17+
18+
;; Adds DeepSeek specifics for `chatgpt-shell'.
19+
20+
;;; Code:
21+
22+
(declare-function chatgpt-shell-validate-no-system-prompt "chatgpt-shell")
23+
24+
(cl-defun chatgpt-shell-deepseek-make-model (&key label version short-version token-width context-window validate-command other-params)
25+
"Create an DeepSeek model.
26+
27+
Set LABEL, VERSION, SHORT-VERSION, TOKEN-WIDTH, CONTEXT-WINDOW,
28+
VALIDATE-COMMAND and OTHER-PARAMS for `chatgpt-shell-openai-make-model'."
29+
(chatgpt-shell-openai-make-model
30+
:label label
31+
:version version
32+
:short-version short-version
33+
:token-width token-width
34+
:context-window context-window
35+
:other-params other-params
36+
:validate-command #'chatgpt-shell-deepseek--validate-command
37+
:url-base 'chatgpt-shell-deepseek-api-url-base
38+
:path "/chat/completions"
39+
:provider "DeepSeek"
40+
:validate-command validate-command
41+
:key #'chatgpt-shell-deepseek-key
42+
:headers #'chatgpt-shell-deepseek--make-headers
43+
:handler #'chatgpt-shell-deepseek--handle-command
44+
:filter #'chatgpt-shell-deepseek--filter-output))
45+
46+
(defun chatgpt-shell-deepseek-models ()
47+
"Build a list of DeepSeek LLM models."
48+
(list (chatgpt-shell-deepseek-make-model
49+
:version "deepseek-reasoner"
50+
:short-version "reasoner"
51+
:label "DeepSeek"
52+
;; See https://api-docs.deepseek.com/quick_start/token_usage
53+
:token-width 3
54+
;; See https://api-docs.deepseek.com/quick_start/pricing.
55+
:context-window 65536)
56+
(chatgpt-shell-deepseek-make-model
57+
:version "deepseek-chat"
58+
:short-version "chat"
59+
:label "DeepSeek"
60+
;; See https://api-docs.deepseek.com/quick_start/token_usage
61+
:token-width 3
62+
;; See https://api-docs.deepseek.com/quick_start/pricing.
63+
:context-window 65536)))
64+
65+
(defcustom chatgpt-shell-deepseek-api-url-base "https://api.deepseek.com"
66+
"DeepSeek API's base URL.
67+
68+
API url = base + path.
69+
70+
If you use DeepSeek through a proxy service, change the URL base."
71+
:type 'string
72+
:safe #'stringp
73+
:group 'chatgpt-shell)
74+
75+
(defcustom chatgpt-shell-deepseek-key nil
76+
"DeepSeek key as a string or a function that loads and returns it."
77+
:type '(choice (function :tag "Function")
78+
(string :tag "String"))
79+
:group 'chatgpt-shell)
80+
81+
(defun chatgpt-shell-deepseek-key ()
82+
"Get the DeepSeek key."
83+
(cond ((stringp chatgpt-shell-deepseek-key)
84+
chatgpt-shell-deepseek-key)
85+
((functionp chatgpt-shell-deepseek-key)
86+
(condition-case _err
87+
(funcall chatgpt-shell-deepseek-key)
88+
(error
89+
"KEY-NOT-FOUND")))
90+
(t
91+
nil)))
92+
93+
(cl-defun chatgpt-shell-deepseek--handle-command (&key model command context shell settings)
94+
"Handle ChatGPT COMMAND (prompt) using ARGS, MODEL, CONTEXT, SHELL, and SETTINGS."
95+
(chatgpt-shell-openai--handle-chatgpt-command
96+
:model model
97+
:command command
98+
:context context
99+
:shell shell
100+
:settings settings
101+
:key #'chatgpt-shell-deepseek-key
102+
:filter #'chatgpt-shell-deepseek--filter-output
103+
:missing-key-msg "Your chatgpt-shell-deepseek-key is missing"))
104+
105+
(defun chatgpt-shell-deepseek--filter-output (raw-response)
106+
"Filter RAW-RESPONSE when processing responses are sent."
107+
(chatgpt-shell-openai--filter-output raw-response))
108+
109+
(defun chatgpt-shell-deepseek--make-headers (&rest args)
110+
"Create the API headers.
111+
112+
ARGS are the same as for `chatgpt-shell-openai--make-headers'."
113+
(apply #'chatgpt-shell-openai--make-headers
114+
:key #'chatgpt-shell-deepseek-key
115+
args))
116+
117+
(defun chatgpt-shell-deepseek--validate-command (_command _model _settings)
118+
"Return error string if command/setup isn't valid."
119+
(unless chatgpt-shell-deepseek-key
120+
"Variable `chatgpt-shell-deepseek-key' needs to be set to your key.
121+
122+
Try M-x set-variable chatgpt-shell-deepseek-key
123+
124+
or
125+
126+
(setq chatgpt-shell-deepseek-key \"my-key\")"))
127+
128+
(provide 'chatgpt-shell-deepseek)
129+
;;; chatgpt-shell-deepseek.el ends here

chatgpt-shell-ollama.el

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
;; Muffle warning about free variable.
3737
(defvar chatgpt-shell-models)
38+
(defvar chatgpt-shell-request-timeout)
3839
(declare-function chatgpt-shell-crop-context "chatgpt-shell")
3940
(declare-function chatgpt-shell--make-chatgpt-url "chatgpt-shell")
4041
(declare-function chatgpt-shell-openai--user-assistant-messages "chatgpt-shell-openai")
@@ -179,6 +180,7 @@ replace all models with locally installed ollama models."
179180
(list (cons command nil)))
180181
:settings settings)
181182
:filter #'chatgpt-shell-ollama--extract-ollama-response
183+
:timeout chatgpt-shell-request-timeout
182184
:shell shell))
183185

184186
(cl-defun chatgpt-shell-ollama--make-url (&key _command _model _settings)

chatgpt-shell-openai.el

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ HANDLER, FILTER and OTHER-PARAMS."
8686
(when (map-elt settings :system-prompt)
8787
(format "Model \"%s\" does not support system prompts. Please unset via \"M-x chatgpt-shell-swap-system-prompt\" by selecting None."
8888
(map-elt model :version))))))
89+
(chatgpt-shell-openai-make-model
90+
:version "o1"
91+
:token-width 3
92+
;; https://platform.openai.com/docs/models/o1
93+
:context-window 200000
94+
:validate-command #'chatgpt-shell-validate-no-system-prompt)
8995
(chatgpt-shell-openai-make-model
9096
:version "o1-preview"
9197
:token-width 3
@@ -104,6 +110,11 @@ HANDLER, FILTER and OTHER-PARAMS."
104110
(when (map-elt settings :system-prompt)
105111
(format "Model \"%s\" does not support system prompts. Please unset via \"M-x chatgpt-shell-swap-system-prompt\" by selecting None."
106112
(map-elt model :version))))))
113+
(chatgpt-shell-openai-make-model
114+
:version "gpt-4.5-preview"
115+
:token-width 3
116+
;; https://platform.openai.com/docs/models#gpt-4-5
117+
:context-window 128000)
107118
(chatgpt-shell-openai-make-model
108119
:version "gpt-4o"
109120
:token-width 3
@@ -236,8 +247,10 @@ Otherwise:
236247
(let-alist obj
237248
(mapconcat (lambda (choice)
238249
(let-alist choice
239-
(or .delta.content
240-
.message.content)))
250+
(or (and (not (eq .delta.content :null))
251+
.delta.content)
252+
.message.content
253+
"")))
241254
.choices "")))))
242255
(unless (string-empty-p text)
243256
(setq response (concat response text)))

chatgpt-shell-openrouter.el

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ VALIDATE-COMMAND and OTHER-PARAMS for `chatgpt-shell-openai-make-model'."
7676
;;
7777
;; See https://openrouter.ai/qwen/qwq-32b-preview
7878
:other-params '((provider (quantizations . ["bf16"]))))
79+
(chatgpt-shell-openrouter-make-model
80+
:version "openai/o3-mini-high"
81+
:short-version "o3-mini-high"
82+
:label "ChatGPT"
83+
:token-width 3
84+
;; See https://openrouter.ai/openai/o3-mini-high
85+
:context-window 200000
86+
:validate-command #'chatgpt-shell-validate-no-system-prompt)
87+
(chatgpt-shell-openrouter-make-model
88+
:version "openai/o3-mini"
89+
:short-version "o3-mini"
90+
:label "ChatGPT"
91+
:token-width 3
92+
;; See https://openrouter.ai/openai/o1-2024-12-17
93+
:context-window 200000
94+
:validate-command #'chatgpt-shell-validate-no-system-prompt)
7995
(chatgpt-shell-openrouter-make-model
8096
:version "openai/o1"
8197
:short-version "o1"

chatgpt-shell.el

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
;; Author: Alvaro Ramirez https://xenodium.com
66
;; URL: https://github.com/xenodium/chatgpt-shell
7-
;; Version: 2.12.2
7+
;; Version: 2.16.1
88
;; Package-Requires: ((emacs "28.1") (shell-maker "0.76.2"))
9-
(defconst chatgpt-shell--version "2.12.2")
9+
(defconst chatgpt-shell--version "2.16.1")
1010

1111
;; This package is free software; you can redistribute it and/or modify
1212
;; it under the terms of the GNU General Public License as published by
@@ -36,10 +36,12 @@
3636
;;
3737
;; You must set an API key for most cloud services. Check out:
3838
;;
39-
;; `chatgpt-shell-openai-key'.
4039
;; `chatgpt-shell-anthropic-key'.
40+
;; `chatgpt-shell-deepseek-key'
4141
;; `chatgpt-shell-google-key'.
4242
;; `chatgpt-shell-kagi-key'.
43+
;; `chatgpt-shell-openai-key'.
44+
;; `chatgpt-shell-openrouter-key'
4345
;; `chatgpt-shell-perplexity-key'.
4446
;;
4547
;; Alternatively, local services like Ollama do not require an API key.
@@ -67,14 +69,15 @@
6769
(require 'ob-core)
6870
(require 'color)
6971

70-
(require 'chatgpt-shell-prompt-compose)
7172
(require 'chatgpt-shell-anthropic)
73+
(require 'chatgpt-shell-deepseek)
7274
(require 'chatgpt-shell-google)
7375
(require 'chatgpt-shell-kagi)
7476
(require 'chatgpt-shell-ollama)
7577
(require 'chatgpt-shell-openai)
76-
(require 'chatgpt-shell-perplexity)
7778
(require 'chatgpt-shell-openrouter)
79+
(require 'chatgpt-shell-perplexity)
80+
(require 'chatgpt-shell-prompt-compose)
7881

7982
(defcustom chatgpt-shell-request-timeout 600
8083
"How long to wait for a request to time out in seconds."
@@ -233,13 +236,14 @@ Can be used compile or run source block at point."
233236
234237
This function aggregates models from OpenAI, Anthropic, Google, and Ollama.
235238
It returns a list containing all available models from these providers."
236-
(append (chatgpt-shell-openai-models)
237-
(chatgpt-shell-anthropic-models)
239+
(append (chatgpt-shell-anthropic-models)
240+
(chatgpt-shell-deepseek-models)
238241
(chatgpt-shell-google-models)
239242
(chatgpt-shell-kagi-models)
240243
(chatgpt-shell-ollama-models)
241-
(chatgpt-shell-perplexity-models)
242-
(chatgpt-shell-openrouter-models)))
244+
(chatgpt-shell-openai-models)
245+
(chatgpt-shell-openrouter-models)
246+
(chatgpt-shell-perplexity-models)))
243247

244248
(defcustom chatgpt-shell-models
245249
(chatgpt-shell--make-default-models)
@@ -435,7 +439,7 @@ Or nil if none."
435439

436440
(defun chatgpt-shell-validate-no-system-prompt (command model settings)
437441
"Perform validation for COMMAND with MODEL and SETTINGS.
438-
Then enforce that there is no system prompt. This is useful for models like
442+
Then enforce that there is no system prompt. This is useful for models like
439443
OpenAI's o1 that do not allow one."
440444
(or (chatgpt-shell-openai--validate-command command model settings)
441445
(when (map-elt settings :system-prompt)
@@ -517,6 +521,32 @@ Downloaded from https://github.com/f/awesome-chatgpt-prompts."
517521
(setq chatgpt-shell-models (chatgpt-shell--make-default-models))
518522
(message "Reloaded %d models" (length chatgpt-shell-models)))
519523

524+
(defcustom chatgpt-shell-model-filter nil
525+
"Filter models to swap from using this function as a filter.
526+
527+
See `chatgpt-shell-allow-model-versions' and
528+
`chatgpt-shell-ignore-model-versions' as examples."
529+
:type 'function
530+
:group 'chatgpt-shell)
531+
532+
(defun chatgpt-shell-allow-model-versions (versions)
533+
"Return a filter function to keep known model VERSIONS only.
534+
535+
Use with `chatgpt-shell-model-filter'."
536+
(lambda (models)
537+
(seq-filter (lambda (model)
538+
(member (map-elt model :version) versions))
539+
models)))
540+
541+
(defun chatgpt-shell-ignore-model-versions (versions)
542+
"Return a filter function to drop model VERSIONS.
543+
544+
Use with `chatgpt-shell-model-filter'."
545+
(lambda (models)
546+
(seq-filter (lambda (model)
547+
(not (member (map-elt model :version) versions)))
548+
models)))
549+
520550
(defun chatgpt-shell-swap-model ()
521551
"Swap model version from `chatgpt-shell-models'."
522552
(interactive)
@@ -535,7 +565,9 @@ Downloaded from https://github.com/f/awesome-chatgpt-prompts."
535565
(format (format "%%-%ds %%s" width)
536566
(map-elt model :provider)
537567
(map-elt model :version)))
538-
chatgpt-shell-models))
568+
(if chatgpt-shell-model-filter
569+
(funcall chatgpt-shell-model-filter chatgpt-shell-models)
570+
chatgpt-shell-models)))
539571
(selection (nth 1 (split-string (completing-read "Model version: "
540572
models nil t)))))
541573
(progn
@@ -1571,16 +1603,17 @@ With prefix REVIEW prompt before sending to ChatGPT."
15711603
(prin1-to-string
15721604
`(progn
15731605
(interactive)
1574-
(load ,(find-library-name "shell-maker") nil t)
1575-
(load ,(find-library-name "chatgpt-shell-openai") nil t)
1576-
(load ,(find-library-name "chatgpt-shell-openrouter") nil t)
1577-
(load ,(find-library-name "chatgpt-shell-google") nil t)
1606+
(load ,(find-library-name "chatgpt-shell") nil t)
15781607
(load ,(find-library-name "chatgpt-shell-anthropic") nil t)
1579-
(load ,(find-library-name "chatgpt-shell-ollama") nil t)
1608+
(load ,(find-library-name "chatgpt-shell-deepseek") nil t)
1609+
(load ,(find-library-name "chatgpt-shell-google") nil t)
15801610
(load ,(find-library-name "chatgpt-shell-kagi") nil t)
1611+
(load ,(find-library-name "chatgpt-shell-ollama") nil t)
1612+
(load ,(find-library-name "chatgpt-shell-openai") nil t)
1613+
(load ,(find-library-name "chatgpt-shell-openrouter") nil t)
15811614
(load ,(find-library-name "chatgpt-shell-perplexity") nil t)
15821615
(load ,(find-library-name "chatgpt-shell-prompt-compose") nil t)
1583-
(load ,(find-library-name "chatgpt-shell") nil t)
1616+
(load ,(find-library-name "shell-maker") nil t)
15841617
(setq chatgpt-shell-model-temperature 0)
15851618
(setq chatgpt-shell-openai-key ,(chatgpt-shell-openai-key))
15861619
(chatgpt-shell-command-line-from-prompt-file ,prompt-file)))
@@ -3179,11 +3212,12 @@ Of the form
31793212
(line-beginning-position)))
31803213
(end (region-end)))
31813214
;; Barf trailing space from selection.
3182-
(when (string-match "[ \n\t]+$"
3183-
(buffer-substring-no-properties
3184-
start
3185-
end))
3186-
(setq end (- end (length (match-string 0)))))
3215+
(let ((text (buffer-substring-no-properties
3216+
start
3217+
end)))
3218+
(when (string-match "[ \n\t]+$"
3219+
text)
3220+
(setq end (- end (length (match-string 0 text))))))
31873221
(list (cons :start start)
31883222
(cons :end end)
31893223
(cons :buffer (current-buffer))

0 commit comments

Comments
 (0)