Skip to content
This repository was archived by the owner on Jan 25, 2023. It is now read-only.

Commit a46707a

Browse files
authored
Merge pull request #4 from labteral/feature/interactive-refresh
add cli commands, update readme, minor changes
2 parents 05d0982 + 556ff7c commit a46707a

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,21 @@ Create the file `config.json` in your working directory:
3131

3232

3333
## Usage
34-
### Interactive chat
34+
### CLI
35+
You can launch the CLI with:
3536
```bash
3637
chatgpt
3738
```
3839
or
3940
```bash
4041
python -m chatgpt
4142
```
43+
44+
These are the available commands:
45+
- `reset`: forget the context of the current conversation.
46+
- `clear`: clear the terminal.
47+
- `exit`: exit the CLI.
48+
4249
### SDK
4350
```python
4451
from chatgpt import Conversation

chatgpt/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
from .chatgpt import *
55

6-
__version__ = '1.2212.0'
6+
__version__ = '1.2212.1'

chatgpt/__main__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,22 @@ def main():
77
conversation = Conversation()
88

99
while True:
10-
message = input('> ')
11-
if message.lower().strip() == 'exit':
10+
message = input('> ').lower().strip()
11+
12+
if not message:
13+
continue
14+
15+
if message == 'exit':
1216
break
17+
18+
elif message == 'reset':
19+
conversation.reset()
20+
continue
21+
22+
elif message == 'clear':
23+
print('\033c', end='')
24+
continue
25+
1326
print(conversation.chat(message), end='\n\n')
1427

1528

chatgpt/chatgpt.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def chat(self, message: List[str], retry_on_401: bool = True):
381381
else:
382382
try:
383383
exception_message = json.loads(ex.msg)["detail"]
384-
except ValueError as e:
384+
except ValueError:
385385
exception_message = ex.msg
386386

387387
except TLSClientExeption as ex:
@@ -394,8 +394,6 @@ def chat(self, message: List[str], retry_on_401: bool = True):
394394

395395
raise ChatgptError(
396396
exception_message, exception_code)
397-
398-
399397

400398
def reset(self):
401399
self._message_id = None

0 commit comments

Comments
 (0)