Skip to content

Commit 89cea93

Browse files
committed
Fully support conversational-chatting
1 parent a534f90 commit 89cea93

File tree

9 files changed

+48
-33
lines changed

9 files changed

+48
-33
lines changed

docs/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,8 @@
5656

5757
**What's new?**
5858
- Chatting conversationally - **Stable**
59+
60+
## v0.1.0
61+
62+
**What's new?**
63+
- Chatting conversationally - **Default Mode**

docs/README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<a href="https://github.com/Simatwa/python-tgpt/actions/workflows/python-test.yml"><img src="https://github.com/Simatwa/python-tgpt/actions/workflows/python-test.yml/badge.svg" alt="Python Test"/></a>
66
-->
77
<a href="https://github.com/Simatwa/python-tgpt/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/static/v1?logo=GPL&color=Blue&message=MIT&label=License"/></a>
8-
<a href="https://pypi.org/project/python-tgpt"><img alt="PyPi" src="https://img.shields.io/static/v1?logo=pypi&label=Pypi&message=v0.0.9&color=green"/></a>
8+
<a href="https://pypi.org/project/python-tgpt"><img alt="PyPi" src="https://img.shields.io/static/v1?logo=pypi&label=Pypi&message=v0.1.0&color=green"/></a>
99
<a href="https://github.com/psf/black"><img alt="Black" src="https://img.shields.io/static/v1?logo=Black&label=Code-style&message=Black"/></a>
1010
<a href="#"><img alt="Passing" src="https://img.shields.io/static/v1?logo=Docs&label=Docs&message=Passing&color=green"/></a>
1111
<a href="https://github.com/Simatwa/python-tgpt/actions/workflows/python-package.yml"><img src="https://github.com/Simatwa/python-tgpt/actions/workflows/python-package.yml/badge.svg"/></a>
@@ -41,6 +41,16 @@ This project enables seamless interaction with [LLaMA](https://ai.meta.com/llama
4141

4242
The name *python-tgpt* draws inspiration from its parent project [tgpt](https://github.com/aandrew-me/tgpt), which operates on [golang](https://go.dev/). Through this Python adaptation, users can effortlessly engage with LLaMA's capabilities, fostering a smoother AI interaction experience.
4343

44+
## Features
45+
46+
- 🗨️ Enhanced conversational chat experience
47+
- 💾 Capability to save prompts and responses (Conversation)
48+
- 🔄 Ability to load previous conversations
49+
- ⌨️ Command-line interface
50+
- 🐍 Python package
51+
- 🌊 Stream and non-stream response
52+
- 🚀 Ready to use (No API key required)
53+
4454
## Prerequisites
4555

4656
- [x] [Python>=3.9](https://python.org)
@@ -168,7 +178,7 @@ for value in resp:
168178

169179
<summary>
170180

171-
- To get better feedback, you can make use of [optimizers](tgpt/utils.py) using parameter `optimizer` with values *(code or system_command)*
181+
To obtain more tailored responses, consider utilizing [optimizers](tgpt/utils.py) using the `optimizer` parameter. Its values can be set to either `code` or `system_command`.
172182

173183
</summary>
174184

@@ -181,17 +191,15 @@ print(resp)
181191

182192
</details>
183193

194+
**Note**: Commencing from [v0.1.0](https://github.com/Simatwa/python-tgpt/releases/), the default mode of interaction is conversational. This mode enhances the interactive experience, offering better control over the chat history. By associating previous prompts and responses, it tailors conversations for a more engaging experience.
184195

185-
186-
**Note**: Starting from [v0.0.7](https://github.com/Simatwa/python-tgpt/releases/), we've introduced an experimental conversational chatting feature:
196+
You can still disable the mode:
187197

188198
```python
189-
bot = tgpt.TGPT(is_conversation=True)
199+
bot = tgpt.TGPT(is_conversation=False)
190200
```
191201

192-
When interacting via the console, simply append the `--conversation` flag. Customize the `history_offset` parameter during the initialization of `TGPT` and utilize the `--history-offset` flag at the console entry point for the same.
193-
194-
This conversational mode opens up a more interactive and engaging experience, allowing greater control over the chat history's handling for a more tailored conversation.
202+
Utilize the `--disable-conversation` flag in the console to achieve the same functionality.
195203

196204

197205
## Acknowledgements

requirements.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name="python-tgpt",
15-
version="0.0.9",
15+
version="0.1.0",
1616
license="MIT",
1717
author="Smartwa",
1818
maintainer="Smartwa",
@@ -39,7 +39,7 @@
3939
"rich==13.3.4",
4040
"clipman==3.1.0",
4141
"pyperclip==1.8.2",
42-
"appdirs==1.4.4"
42+
"appdirs==1.4.4",
4343
],
4444
python_requires=">=3.9",
4545
keywords=[

tests/test_imager.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from tgpt import Imager
2+
3+
# Not working currently

tgpt/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from .tgpt import TGPT
22
from .imager import Imager
33

4-
__version__ = "0.0.9"
4+
__version__ = "0.1.0"
55
__author__ = "Smartwa"
66
__repo__ = "https://github.com/Simatwa/python-tgpt"
77

tgpt/console.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from rich.prompt import Prompt
2222
from typing import Iterator
2323
from tgpt.utils import Optimizers
24+
from tgpt.utils import default_path
2425

2526
getExc = lambda e: e.args[1] if len(e.args) > 1 else str(e)
2627

@@ -177,7 +178,7 @@ def __init__(
177178
model,
178179
brave_key,
179180
timeout,
180-
conversation,
181+
disable_conversation,
181182
filepath,
182183
update_file,
183184
intro,
@@ -196,7 +197,7 @@ def __init__(
196197
proxies = {}
197198
try:
198199
self.bot = tgpt.TGPT(
199-
conversation,
200+
disable_conversation,
200201
max_tokens,
201202
temperature,
202203
top_k,
@@ -564,16 +565,17 @@ def tgpt2_():
564565
"--prettify/--raw", help="Flag for prettifying markdowned response", default=True
565566
)
566567
@click.option(
567-
"-C",
568-
"--conversation",
568+
"-dc",
569+
"--disable-conversation",
569570
is_flag=True,
570-
default=False,
571-
help="Chat conversationally (Experimental)",
571+
default=True, # is_conversation = True
572+
help="Disable chatting conversationally (Stable)",
572573
)
573574
@click.option(
574575
"-fp",
575576
"--filepath",
576577
type=click.Path(),
578+
default=os.path.join(default_path, "chat-history.txt"),
577579
help="Path to chat history - new will be created incase doesn't exist",
578580
)
579581
@click.option(
@@ -628,7 +630,7 @@ def interactive(
628630
timeout,
629631
prompt,
630632
prettify,
631-
conversation,
633+
disable_conversation,
632634
filepath,
633635
update_file,
634636
intro,
@@ -667,7 +669,7 @@ def timeout_handler(signum, frame):
667669
model,
668670
brave_key,
669671
timeout,
670-
conversation,
672+
disable_conversation,
671673
filepath,
672674
update_file,
673675
intro,
@@ -772,16 +774,17 @@ def timeout_handler(signum, frame):
772774
help="Optimize prompt for shell command generation",
773775
)
774776
@click.option(
775-
"-C",
776-
"--conversation",
777+
"-dc",
778+
"--disable-conversation",
777779
is_flag=True,
778-
default=False,
779-
help="Chat conversationally (Experimental)",
780+
default=True, # is_conversation = True
781+
help="Disable chatting conversationally (Stable)",
780782
)
781783
@click.option(
782784
"-fp",
783785
"--filepath",
784786
type=click.Path(),
787+
default=os.path.join(default_path, "chat-history.txt"),
785788
help="Path to chat history - new will be created incase doesn't exist",
786789
)
787790
@click.option(
@@ -839,7 +842,7 @@ def generate(
839842
whole,
840843
code,
841844
shell,
842-
conversation,
845+
disable_conversation,
843846
filepath,
844847
update_file,
845848
intro,
@@ -857,7 +860,7 @@ def generate(
857860
model,
858861
brave_key,
859862
timeout,
860-
conversation,
863+
disable_conversation,
861864
filepath,
862865
update_file,
863866
intro,

tgpt/tgpt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class TGPT:
1111
def __init__(
1212
self,
13-
is_conversation: bool = False,
13+
is_conversation: bool = True,
1414
max_tokens: int = 600,
1515
temperature: float = 0.2,
1616
top_k: int = -1,
@@ -28,7 +28,7 @@ def __init__(
2828
"""Instantiate TGPT
2929
3030
Args:
31-
conversationally (str, optional): Flag for chatting conversationally. Defaults to False.
31+
is_conversation (str, optional): Flag for chatting conversationally. Defaults to True.
3232
brave_key (str, optional): Brave API access key. Defaults to "qztbjzBqJueQZLFkwTTJrieu8Vw3789u".
3333
model (str, optional): Text generation model name. Defaults to "llama-2-13b-chat".
3434
max_tokens (int, optional): Maximum number of tokens to be generated upon completion. Defaults to 600.

tgpt/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ def update_chat_history(self, prompt: str, response: str) -> None:
150150
prompt (str): user prompt
151151
response (str): LLM response
152152
"""
153+
if not self.status:
154+
return
153155
new_history = self.history_format % dict(user=prompt, llm=response)
154156
if self.file and self.update_file:
155157
with open(self.file, "a") as fh:

0 commit comments

Comments
 (0)