Interact with AI without API key
Project description
tgpt2
AI for all
Warning : This project has transitioned from being maintained under
tgpt2
to python-tgpt in response to a raised concern detailed here.
>>> import tgpt2
>>> bot = tgpt2.TGPT()
>>> bot.chat('Hello there')
" Hello! It's nice to meet you. Is there something I can help you with or would you like to chat?"
>>>
This project allows you to interact with AI (LLaMA) without API Key.
The name tgpt2 is inherited from it's parent project tgpt which runs on golang.
Prerequisite
Installation and usage
Installation
Pick either of the following ways to get started.
- From pypi:
pip install tgpt2
- Direct from source
pip install git+https://github.com/Simatwa/tgpt2.git
- Clone and Install
git clone https://github.com/Simatwa/tgpt2.git
cd tgpt2
pip install .
Usage
This package features a ready to use commandline interface.
-
Quick response
python -m tgpt2 generate -P "<Your prompt>"
-
Interactive mode
python -m tgpt2 interactive -P "<Kickoff prompt but not a must>"
Instead of python -m tgpt2
, you can as well just use tgpt2
Developer Docs
- Generate a quick response
from tgpt2 import TGPT
bot = TGPT()
resp = bot.chat('<Your prompt>')
print(resp)
# Output : How may I help you.
- Get back whole response
from tgpt2 import TGPT
bot = TGPT()
resp = bot.ask('<Your Prompt')
print(resp)
# Output
"""
{'completion': "I'm so excited to share with you the incredible experiences...", 'stop_reason': None, 'truncated': False, 'stop': None, 'model': 'llama-2-13b-chat', 'log_id': 'cmpl-3NmRt5A5Djqo2jXtXLBwJ2', 'exception': None}
"""
Stream Response
Just add parameter stream
with value true
.
- Text Generated only
from tgpt2 import TGPT
bot = TGPT()
resp = bot.chat('<Your prompt>', stream=True)
for value in resp:
print(value)
# output
"""
How may
How may I help
How may I help you
How may I help you today?
"""
- Whole Response
from tgpt2 import TGPT
bot = TGPT()
resp = bot.ask('<Your Prompt>', stream=True)
for value in resp:
print(value)
# Output
"""
{'completion': "I'm so", 'stop_reason': None, 'truncated': False, 'stop': None, 'model': 'llama-2-13b-chat', 'log_id': 'cmpl-3NmRt5A5Djqo2jXtXLBwxx', 'exception': None}
{'completion': "I'm so excited to share with.", 'stop_reason': None, 'truncated': False, 'stop': None, 'model': 'llama-2-13b-chat', 'log_id': 'cmpl-3NmRt5A5Djqo2jXtXLBwxx', 'exception': None}
{'completion': "I'm so excited to share with you the incredible ", 'stop_reason': None, 'truncated': False, 'stop': None, 'model': 'llama-2-13b-chat', 'log_id': 'cmpl-3NmRt5A5Djqo2jXtXLBwxx', 'exception': None}
{'completion': "I'm so excited to share with you the incredible experiences...", 'stop_reason': None, 'truncated': False, 'stop': None, 'model': 'llama-2-13b-chat', 'log_id': 'cmpl-3NmRt5A5Djqo2jXtXLBwxx', 'exception': None}
"""
- To get better feedback, you can make use of optimizers using parameter
optimizer
with values (code or system_command)
optimizer
with values (code or system_command)from tgpt2 import TGPT
bot = TGPT()
resp = bot.ask('<Your Prompt>', optimizer='code')
print(resp)
Note : At the time of writing this, Chatting conversationally is not supported
Acknowledgements
- tgpt
- You
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.