Skip to content

Commit f6596e0

Browse files
committed
use latest GPT versions, allow passing arbitrary model, allow setting
model as env variable
1 parent 1645aee commit f6596e0

File tree

3 files changed

+43
-27
lines changed

3 files changed

+43
-27
lines changed

README.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ chatblade -l can we make a gif instead from 00:22:01 to 00:22:04
6161

6262
By default gpt-3.5 is used, you can switch at any point to 4 by using `-c 4`
6363

64+
or you can pass any arbitrary full model name, eg `-c gpt-3.5-turbo-16k`
65+
6466
#### Chatting interactively
6567

6668
If you would prefer to chat interactively instead just use `chatblade -i`.
@@ -221,38 +223,37 @@ chatblade can be used with an Azure OpenAI endpoint, in which case in addition t
221223
### Help
222224

223225
```
224-
usage: Chatblade [-h] [--openai-api-key key] [--temperature t] [-c {3.5,4}] [-i] [-s] [-t] [-p name] [-e] [-r] [-n] [-o] [--theme theme] [-l] [-S sess] [--session-list]
225-
[--session-path] [--session-dump] [--session-delete] [--session-rename newsess]
226-
[query ...]
226+
usage: Chatblade [-h] [--openai-api-key key] [--temperature t] [-c CHAT_GPT] [-i] [-s] [-t] [-p name] [-e] [-r] [-n] [-o] [--theme theme] [-l] [-S sess] [--session-list]
227227
228228
a CLI Swiss Army Knife for ChatGPT
229229
230230
positional arguments:
231-
query Query to send to chat GPT
231+
query Query to send to chat GPT
232232
233233
options:
234-
-h, --help show this help message and exit
235-
--openai-api-key key the OpenAI API key can also be set as env variable OPENAI_API_KEY
236-
--temperature t temperature (openai setting)
237-
-c {3.5,4}, --chat-gpt {3.5,4} chat GPT model
238-
-i, --interactive start an interactive chat session. This will implicitly continue the conversation
239-
-s, --stream Stream the incoming text to the terminal
240-
-t, --tokens display what *would* be sent, how many tokens, and estimated costs
241-
-p name, --prompt-file name prompt name - will load the prompt with that name at ~/.config/chatblade/name or a path to a file
234+
-h, --help show this help message and exit
235+
--openai-api-key key the OpenAI API key can also be set as env variable OPENAI_API_KEY
236+
--temperature t temperature (openai setting)
237+
-c CHAT_GPT, --chat-gpt CHAT_GPT
238+
chat GPT model 3.5/4 shorthand or full qualified model name, can also be set via env variable OPENAI_API_MODEL
239+
-i, --interactive start an interactive chat session. This will implicitly continue the conversation
240+
-s, --stream Stream the incoming text to the terminal
241+
-t, --tokens display what *would* be sent, how many tokens, and estimated costs
242+
-p name, --prompt-file name prompt name - will load the prompt with that name at ~/.config/chatblade/name or a path to a file
242243
243244
result formatting options:
244-
-e, --extract extract content from response if possible (either json or code block)
245-
-r, --raw print session as pure text, don't pretty print or format
246-
-n, --no-format do not add pretty print formatting to output
247-
-o, --only Only display the response, omit query
248-
--theme theme Set the theme for syntax highlighting see https://pygments.org/styles/, can also be set with CHATBLADE_THEME
245+
-e, --extract extract content from response if possible (either json or code block)
246+
-r, --raw print session as pure text, don't pretty print or format
247+
-n, --no-format do not add pretty print formatting to output
248+
-o, --only Only display the response, omit query
249+
--theme theme Set the theme for syntax highlighting see https://pygments.org/styles/, can also be set with CHATBLADE_THEME
249250
250251
session options:
251-
-l, --last alias for '-S last', the default session if none is specified
252-
-S sess, --session sess initiate or continue named session
253-
--session-list list sessions
254-
--session-path show path to session file
255-
--session-dump dump session to stdout
256-
--session-delete delete session
257-
--session-rename newsess rename session
252+
-l, --last alias for '-S last', the default session if none is specified
253+
-S sess, --session sess initiate or continue named session
254+
--session-list list sessions
255+
--session-path show path to session file
256+
--session-dump dump session to stdout
257+
--session-delete delete session
258+
--session-rename newsess rename session
258259
```

chatblade/parser.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ def get_openai_key(options):
1919
else:
2020
return None
2121

22+
model_mappings = {"3.5": "gpt-3.5-turbo-0613", "4": "gpt-4-0613"}
23+
def get_openai_model(options):
24+
choice = options["chat_gpt"]
25+
if not choice:
26+
if "OPENAI_API_MODEL"in os.environ:
27+
choice = os.environ["OPENAI_API_MODEL"]
28+
else:
29+
choice = "3.5"
30+
31+
if choice in model_mappings:
32+
return model_mappings[choice]
33+
else:
34+
return choice
35+
2236
def get_theme(options):
2337
if options["theme"]:
2438
return options["theme"]
@@ -48,7 +62,7 @@ def extract_options(options):
4862
options = vars(options) # to map
4963
options["openai_api_key"] = get_openai_key(options)
5064
options["theme"] = get_theme(options)
51-
options["model"] = {"3.5": "gpt-3.5-turbo", "4": "gpt-4"}[options["chat_gpt"]]
65+
options["model"] = get_openai_model(options)
5266
del options["query"]
5367
del options["chat_gpt"]
5468
return utils.DotDict(options)
@@ -92,7 +106,8 @@ def parse(args):
92106
default=0.0,
93107
)
94108
parser.add_argument(
95-
"-c", "--chat-gpt", choices=["3.5", "4"], help="chat GPT model", default="3.5"
109+
"-c", "--chat-gpt", help="chat GPT model 3.5/4 shorthand or full qualified model name, can also be set via env variable OPENAI_API_MODEL",
110+
type=str
96111
)
97112
parser.add_argument(
98113
"-i",

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = chatblade
3-
version = 0.3.0
3+
version = 0.3.1
44
description = CLI Swiss Army Knife for ChatGPT
55
long_description = file: README.md
66
long_description_content_type=text/markdown

0 commit comments

Comments
 (0)