Interact with AI without API key
Project description
python-tgpt
>>> from pytgpt.leo import LEO
>>> bot = LEO()
>>> 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 enables seamless interaction with free LLMs without requiring an API Key.
The name python-tgpt draws inspiration from its parent project tgpt, which operates on Golang. Through this Python adaptation, users can effortlessly engage with a number of free LLMs available as well as OpenAI's Chapytgpt models, fostering a smoother AI interaction experience.
Features
- 🗨️ Enhanced conversational chat experience
- 💾 Capability to save prompts and responses (Conversation)
- 🔄 Ability to load previous conversations
- ⌨️ Command-line interface
- 🐍 Python package
- 🌊 Stream and non-stream response
- 🚀 Ready to use (No API key required)
- ⛓️ Chained requests via proxy
- 🤖 Pass awesome-chapytgpt prompts easily
- 🧠 Multiple LLM providers
Providers
These are simply the hosts of the LLMs, which include:
- Brave Leo (llama-2-13b-chat)
- FakeOpen
- Koboldai
- OpenGPTs
- OpenAI (API key required)
- WebChatGPT - OpenAI (No API key required)
Prerequisites
- Python>=3.9 (Optional)
Installation and Usage
Installation
Download binaries for your system from here.
Alternatively, you can install non-binaries. (Recommended)
Choose one of the following methods to get started.
-
From PyPI:
pip install --upgrade python-tgpt
-
Directly from the source:
pip install git+https://github.com/Simatwa/python-tgpt.git
-
Clone and Install:
git clone https://github.com/Simatwa/python-tgpt.git cd python-tgpt pip install .
Usage
This package offers a convenient command-line interface.
Note :
leois the default provider.
-
For a quick response:
python -m pytgpt generate "<Your prompt>"
-
For interactive mode:
python -m pytgpt interactive "<Kickoff prompt (though not mandatory)>"
Make use of flag --provider postfixed with the provider name of your choice. e.g --provider koboldai
You can also simply use pytgpt instead of python -m pytgpt.
Starting from version 0.1.2, generate is the default command if you issue a prompt, and interactive takes action if you don't. Therefore, something like this will generate a response and exit $ pytgpt "<Your prompt>" while $ pytgpt will fire up an interactive prompt.
Developer Docs
- Generate a quick response
from pytgpt.leo import LEO
bot = LEO()
resp = bot.chat('<Your prompt>')
print(resp)
# Output : How may I help you.
- Get back whole response
from pytgpt.leo import LEO
bot = LEO()
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 pytgpt.leo import LEO
bot = LEO()
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 pytgpt.leo import LEO
bot = LEO()
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}
"""
Note : All providers have got a common class methods.
Openai
import pytgpt.openai as openai
bot = openai.OPENAI("<OPENAI-API-KEY>")
print(bot.chat("<Your-prompt>"))
Koboldai
import pytgpt.koboldai as koboldai
bot = koboldai.KOBOLDAI()
print(bot.chat("<Your-prompt>"))
Fakeopen
import pytgpt.fakeopen as fakeopen
bot = fakeopen.FAKEOPEN()
print(bot.chat("<Your-prompt>"))
Opengpt
import pytgpt.opengpt as opengpt
bot = opengpt.OPENGPT()
print(bot.chat("<Your-prompt>"))
To obtain more tailored responses, consider utilizing optimizers using the optimizer parameter. Its values can be set to either code or system_command.
optimizer parameter. Its values can be set to either code or system_command.from pytgpt.leo import LEO
bot = LEO()
resp = bot.ask('<Your Prompt>', optimizer='code')
print(resp)
Note: Commencing from v0.1.0, 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.
You can still disable the mode:
bot = koboldai.KOBOLDAI(is_conversation=False)
Utilize the --disable-conversation flag in the console to achieve the same functionality.
For more usage info run $ pytgpt --help
Acknowledgements
- tgpt
- You
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python-tgpt-0.2.4.tar.gz.
File metadata
- Download URL: python-tgpt-0.2.4.tar.gz
- Upload date:
- Size: 28.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
766fe50b5c74a6fa0d9d4968f014d75e8892f3a3a5f88b503800f435a57446dd
|
|
| MD5 |
f85a7e20923f963113f1fb50fd22a781
|
|
| BLAKE2b-256 |
fb17c830059224c9e4c1bf08971e470497e9d65f3238d8e41323601bb1072c1d
|
File details
Details for the file python_tgpt-0.2.4-py3-none-any.whl.
File metadata
- Download URL: python_tgpt-0.2.4-py3-none-any.whl
- Upload date:
- Size: 34.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c725e06e762e5cd670c0626f0ee34b5d561113579c8117226d65928cfba2efd
|
|
| MD5 |
10c68a4c10db9855936721db899724d4
|
|
| BLAKE2b-256 |
f2a66e66f1ad9a44eb8a26a5dc2ce7425ac26ad69a10c48244661e8577db13bd
|