Giter Club home page Giter Club logo

python-tgpt's Introduction

License PyPi Black Passing coverage Progress Downloads Downloads Latest release release date wakatime

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:

  1. Leo - Brave
  2. FakeOpen
  3. Koboldai
  4. OpenGPTs
  5. OpenAI (API key required)
  6. WebChatGPT - OpenAI (Session ID required)
  7. Bard - Google (Session ID required)

Prerequisites

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.

  1. From PyPI:

    pip install --upgrade python-tgpt
  2. Directly from the source:

    pip install git+https://github.com/Simatwa/python-tgpt.git
  3. 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 : leo 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 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.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

  1. Generate a quick response
from pytgpt.leo import LEO
bot = LEO()
resp = bot.chat('<Your prompt>')
print(resp)
# Output : How may I help you.
  1. 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.

  1. 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?
"""
  1. 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>"))

To obtain more tailored responses, consider utilizing optimizers using the 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 and WebChatGPT autohandles context due to the obvious reason; the is_conversation parameter is not necessary at all hence not required when initializing the respective classes.

For more usage info run $ pytgpt --help

Acknowledgements

  1. tgpt
  2. You

python-tgpt's People

Contributors

simatwa avatar cahebebe avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.