Package: python-tgpt
python-tgpt>>>importpytgpt.phindasphind>>>bot=phind.PHIND()>>>bot.chat('hello there')'Hello! How can I assist you today?'>>>frompytgpt.consoleimportmain>>>main()WelcometoAIChatinterminal.Type'help'or'h'forusageinfo.Submitanybugathttps://github.com/Simatwa/python-tgpt/issues/new╭─[Smartwa@pyTGPT](phind)~[🕒04:05:55-💻00:00:00-⚡0.0s]╰─>"""This project enables seamless interaction with over45 free LLM providerswithout requiring an API Key as well generating images.The namepython-tgptdraws inspiration from its parent projecttgpt, which operates onGolang. 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🤖 Passawesome-chatgpt promptseasily🧠 Multiple LLM providers -45+🎯 Customizable script generation and execution🔌 Offline support for Large Language Models🎨 Image generation capabilitiesProvidersThese are simply the hosts of the LLMs, which include:Leo-BraveKoboldaiOpenGPTsOpenAI(API key required)WebChatGPT-OpenAI(Session ID required)Bard-Google(Session ID required)Phind-defaultLlama2Blackboxaigpt4all(Offline)Poe- Poe|Quora(Session ID required)41+ Other models proudly offered bygpt4free.To list working providers run:$pytgptgpt4freetest-yPrerequisitesPython>=3.9(Optional)Installation and UsageInstallationDownload binaries for your system fromhere.Alternatively, you can install non-binaries.(Recommended)Developers:pipinstall--upgradepython-tgptCommandline:pipinstall--upgrade"python-tgpt[cli]"Full installation:pipinstall--upgrade"python-tgpt[all]"UsageThis package offers a convenient command-line interface.[!NOTE]phindis the defaultprovider.For a quick response:python-mpytgptgenerate"<Your prompt>"For interactive mode:python-mpytgptinteractive"<Kickoff prompt (though not mandatory)>"Make use of flag--providerfollowed by the provider name of your choice. e.g--provider koboldaiTo list all providers offered by gpt4free, use following commands:pytgpt gpt4free list providersYou can also simply usepytgptinstead ofpython -m pytgpt.Starting from version 0.2.7, running$ pytgptwithout any other command or option will automatically enter theinteractivemode. Otherwise, you'll need to explicitly declare the desired action, for example, by running$ pytgpt generate.Developer DocsGenerate a quick responsefrompytgpt.leoimportLEObot=LEO()resp=bot.chat('<Your prompt>')print(resp)# Output : How may I help you.Get back whole responsefrompytgpt.leoimportLEObot=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 ResponseJust add parameterstreamwith valuetrue.Text Generated onlyfrompytgpt.leoimportLEObot=LEO()resp=bot.chat('<Your prompt>',stream=True)forvalueinresp:print(value)# output"""How mayHow may I helpHow may I help youHow may I help you today?"""Whole Responsefrompytgpt.leoimportLEObot=LEO()resp=bot.ask('<Your Prompt>',stream=True)forvalueinresp: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.Openaiimportpytgpt.openaiasopenaibot=openai.OPENAI("<OPENAI-API-KEY>")print(bot.chat("<Your-prompt>"))Koboldaiimportpytgpt.koboldaiaskoboldaibot=koboldai.KOBOLDAI()print(bot.chat("<Your-prompt>"))Fakeopenimportpytgpt.fakeopenasfakeopenbot=fakeopen.FAKEOPEN()print(bot.chat("<Your-prompt>"))Opengptimportpytgpt.opengptasopengptbot=opengpt.OPENGPT()print(bot.chat("<Your-prompt>"))Bardimportpytgpt.bardasbardbot=bard.BARD('<Path-to-bard.google.com.cookies.json>')print(bot.chat("<Your-prompt>"))phindimportpytgp.phindasphindbot=phind.PHIND()print(bot.chat("<Your-prompt>"))Gpt4free providersimportpytgpt.gpt4freeasgpt4freebot=gpt4free.GPT4FREE(provider="Aura")print(bot.chat("<Your-prompt>"))To obtain more tailored responses, consider utilizingoptimizersusing theoptimizerparameter. Its values can be set to eithercodeorsystem_command.frompytgpt.leoimportLEObot=LEO()resp=bot.ask('<Your Prompt>',optimizer='code')print(resp)[!IMPORTANT]
Commencing fromv0.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-conversationflag in the console to achieve the same functionality.[!CAUTION]Bardautohandles context due to the obvious reason; theis_conversationparameter is not necessary at all hence not required when initializing the class. Also be informed that majority of providers offered bygpt4freerequiresGoogle Chromeinorder to function.Image GenerationThis has been made possible bypollination.ai.$pytgptimager"<prompt>"# e.g pytgpt imager "Coding bot"Developersfrompytgpt.imagerimportImagerimg=Imager()generated_img=img.generate('Coding bot')# [bytes]img.save(generated_img)Download Multiple Imagesfrompytgpt.imagerimportImagerimg=Imager()img_generator=img.generate('Coding bot',amount=3,stream=True)img.save(img_generator)# RAM friendlyAdvanced Usage of PlaceholdersThegeneratefunctionality has been enhanced starting fromv0.3.0to enable comprehensive utilization of the--with-copiedoption and support for accepting piped inputs. This improvement introduces placeholders, offering dynamic values for more versatile interactions.PlaceholderRepresents{{stream}}The piped input{{copied}}The last copied textThis feature is particularly beneficial for intricate operations. For example:$gitdiff|pytgptgenerate"Here is a diff file: {{stream}} Make a concise commit message from it, aligning with my commit message history: {{copied}}"--shell--newIn this illustration,{{stream}}denotes the result of the$ git diffoperation, while{{copied}}signifies the content copied from the output of the$ git logcommand.Introducing RawDogRawDog 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 byyour prompts! To have a bite ofrawdogsimply append the flag--rawdogshortform-rdingenerate/interactivemode. This introduces a never seen-before feature in thetgpt ecosystem. Thanks toAbanteAI/rawdogfor the idea.This can be useful in some ways. For instance :$pytgptgenerate-n-q"Visualize the disk usage using pie chart"--rawdogThis will pop up a window showing system disk usage as shown below.Passing Environment VariablesPytgptv0.4.6introduces a convention way of taking variables from the environment.
To achieve that, set the environment variables in your operating system or script with prefixPYTGPT_followed by the option name in uppercase, replacing dashes with underscores.For example, for the option--provider, you would set an environment variablePYTGPT_PROVIDERto provide a default value for that option. Same case applies to boolean flags such as--rawdogwhose environment variable will bePYTGPT_RAWDOGwith value being eithertrue/false. Finally,--awesome-promptwill take the environment variablePYTGPT_AWESOME_PROMPT.[!NOTE]
This isNOTlimited to any commandThe environment variables can be overridden by explicitly declaring new value.[!TIP]
Save the variables in a.envfile in your current directory or export the them in your.zshrcfile.Dynamic ProviderVersion0.4.6also introduces dynamic provider calledg4fauto, which represents the fastest working g4f-based provider.For more usage info run$ pytgpt --helpUsage: 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-VersionCHANGELOGAcknowledgementstgptgpt4free