Interact with AI without API key
Project description
python-tgpt
>>> import pytgpt.phind as phind
>>> bot = phind.PHIND()
>>> bot.chat('hello there')
'Hello! How can I assist you today?'
# CLI
from pytgpt.console import main
main()
"""
Welcome to AI Chat in terminal. Type 'help' or 'h' for usage info.
Submit any bug at https://github.com/Simatwa/python-tgpt/issues/new
╭─[Smartwa@pyTGPT](phind)~[🕒04:05:55-💻00:00:00-⚡0.0s]
╰─>
"""
This project enables seamless interaction with over 45 free LLM providers 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, 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-chatgpt prompts easily
- 🧠 Multiple LLM providers - 45+
- 🎯 Customizable script generation and execution
- 🔌 Offline support for Large Language Models
Providers
These are simply the hosts of the LLMs, which include:
- Leo - Brave
- Koboldai
- OpenGPTs
- OpenAI (API key required)
- WebChatGPT - OpenAI (Session ID required)
- Bard - Google (Session ID required)
- Phind - default
- Llama2
- Blackboxai
- gpt4all (Offline)
- Poe - Poe|Quora (Session ID required)
41+ Other models proudly offered by gpt4free.
- To list working providers run:
$ pytgpt gpt4free test -y
$ pytgpt gpt4free test -y
- AiChatOnline
- Aura
- Bard
- Bing
- ChatBase
- ChatForAi
- Chatgpt4Online
- ChatgptAi
- ChatgptDemo
- ChatgptNext
- Chatxyz
- DeepInfra
- FakeGpt
- FreeChatgpt
- GPTalk
- GeekGpt
- GeminiProChat
- Gpt6
- GptChatly
- GptForLove
- GptGo
- GptTalkRu
- Hashnode
- HuggingChat
- Koala
- Liaobots
- Llama2
- MyShell
- OnlineGpt
- OpenaiChat
- PerplexityAi
- Phind
- Pi
- Poe
- Raycast
- TalkAi
- Theb
- ThebApi
- You
- Yqcloud
All models. (Include not working)
- AItianhu
- AItianhuSpace
- Acytoo
- AiAsk
- AiChatOnline
- AiChatting
- AiService
- Aibn
- Aichat
- Ails
- Aivvm
- AsyncGeneratorProvider
- AsyncProvider
- Aura
- Bard
- BaseProvider
- Berlin
- Bestim
- Bing
- ChatAiGpt
- ChatAnywhere
- ChatBase
- ChatForAi
- Chatgpt4Online
- ChatgptAi
- ChatgptDemo
- ChatgptDemoAi
- ChatgptDuo
- ChatgptFree
- ChatgptLogin
- ChatgptNext
- ChatgptX
- Chatxyz
- CodeLinkAva
- CreateImagesProvider
- Cromicle
- DeepInfra
- DfeHub
- EasyChat
- Equing
- FakeGpt
- FastGpt
- Forefront
- FreeChatgpt
- FreeGpt
- GPTalk
- GeekGpt
- GeminiProChat
- GetGpt
- Gpt6
- GptChatly
- GptForLove
- GptGo
- GptGod
- GptTalkRu
- H2o
- Hashnode
- HuggingChat
- Koala
- Komo
- Liaobots
- Llama2
- Lockchat
- MikuChat
- MyShell
- Myshell
- OnlineGpt
- Opchatgpts
- OpenAssistant
- OpenaiChat
- PerplexityAi
- Phind
- Pi
- Poe
- Raycast
- RetryProvider
- TalkAi
- Theb
- ThebApi
- V50
- Vercel
- Vitalentum
- Wewordle
- Wuguokai
- Ylokh
- You
- Yqcloud
Prerequisites
- Python>=3.9 (Optional)
Installation and Usage
Installation
Download binaries for your system from here.
Alternatively, you can install non-binaries. (Recommended)
-
Developers:
pip install --upgrade python-tgpt
-
Commandline:
pip install --upgrade "python-tgpt[cli]"
-
Full installation:
pip install --upgrade "python-tgpt[all]"
Usage
This package offers a convenient command-line interface.
[!NOTE]
phind
is 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
followed by the provider name of your choice. e.g --provider koboldai
To list all providers offered by gpt4free, use following commands:
pytgpt gpt4free list providers
You can also simply use pytgpt
instead of python -m pytgpt
.
Starting from version 0.2.7, running $ pytgpt
without any other command or option will automatically enter the interactive
mode. Otherwise, you'll need to explicitly declare the desired action, for example, by running $ pytgpt generate
.
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>"))
Bard
import pytgpt.bard as bard
bot = bard.BARD('<Path-to-bard.google.com.cookies.json>')
print(bot.chat("<Your-prompt>"))
phind
import pytgp.phind as phind
bot = phind.PHIND()
print(bot.chat("<Your-prompt>"))
Gpt4free providers
import pytgpt.gpt4free as gpt4free
bot = gpt4free.GPT4FREE(provider="Aura")
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.
[!WARNING] Bard autohandles context due to the obvious reason; the
is_conversation
parameter is not necessary at all hence not required when initializing the class. Also be informed that majority of providers offered by gpt4free requires Google Chrome inorder to function.
Advanced Usage of Placeholders
The generate
functionality has been enhanced starting from v0.3.0 to enable comprehensive utilization of the --with-copied
option and support for accepting piped inputs. This improvement introduces placeholders, offering dynamic values for more versatile interactions.
Placeholder | Represents |
---|---|
{{stream}} |
The piped input |
{{copied}} |
The last copied text |
This feature is particularly beneficial for intricate operations. For example:
$ git diff | pytgpt generate "Here is a diff file: {{stream}} Make a concise commit message from it, aligning with my commit message history: {{copied}}" -p fakeopen --shell --new
In this illustration,
{{stream}}
denotes the result of the$ git diff
operation, while{{copied}}
signifies the content copied from the output of the$ git log
command.
Introducing RawDog
RawDog is a masterpiece feature that exploits the versatile capabilities of Python to command and control your system as per your needs. You can literally do anything with it, since it generates and executes python codes, driven by your prompts! To have a bite of rawdog simply append the flag --rawdog
shortcut -rd
in generate/interactive mode. This introduces a never seen-before feature in the tgpt ecosystem. Thanks to AbanteAI/rawdog for the idea.
This can be useful in some ways. For instance :
$ pytgpt generate -n -q "Visualize the disk usage using pie chart" --rawdog
This will pop up a window showing system disk usage as shown below.
Passing Environment Variables
Pytgpt v0.4.6 introduces a convention way of taking variables from the environment.
To achieve that, set the environment variables in your operating system or script with prefix PYTGPT_
followed by the option name in uppercase, replacing dashes with underscores.
For example, for the option --provider
, you would set an environment variable PYTGPT_PROVIDER
to provide a default value for that option. Same case applies to boolean flags such as --rawdog
whose environment variable will be PYTGPT_RAWDOG
with value being either true/false
. Finally, --awesome-prompt
will take the environment variable PYTGPT_AWESOME_PROMPT
.
The environment variables can be overridden by explicitly declaring new value.
[!TIP]
Save the variables in a .env
file in your current directory or export the them in your .zshrc
file.
[!NOTE]
This is not limited to any command.
Dynamic Provider
Version 0.4.6 also introduces dynamic provider called g4fauto
, which represents the fastest working g4f-based provider.
For more usage info run $ pytgpt --help
PYTGPT_
followed by the option name in uppercase, replacing dashes with underscores.--provider
, you would set an environment variable PYTGPT_PROVIDER
to provide a default value for that option. Same case applies to boolean flags such as --rawdog
whose environment variable will be PYTGPT_RAWDOG
with value being either true/false
. Finally, --awesome-prompt
will take the environment variable PYTGPT_AWESOME_PROMPT
.[!TIP]
Save the variables in a .env
file in your current directory or export the them in your .zshrc
file.
[!NOTE] This is not limited to any command.
g4fauto
, which represents the fastest working g4f-based provider.$ pytgpt --help
Usage: pytgpt [OPTIONS] COMMAND [ARGS]...
Options:
-v, --version Show the version and exit.
-h, --help Show this message and exit.
Commands:
awesome Perform CRUD operations on awesome-prompts
generate Generate a quick response with AI
gpt4free Discover gpt4free models, providers etc
interactive Chat with AI interactively (Default)
utils Utility endpoint for pytgpt
webchatgpt Reverse Engineered ChatGPT Web-Version
CHANGELOG
Acknowledgements
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
Hashes for python_tgpt-0.5.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30b7a721448e14f985534c2edeb7e5f60d8a94bd2fea6fc3884cf0267559c43b |
|
MD5 | 16b7383000d2177ddfbb27d3041e2bdf |
|
BLAKE2b-256 | 36da7811a939854c4c919e254522c13ff1460b18573e5293dac7fc813c35e18c |