Skip to main content

Interact with AI without API key

Project description

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

python-tgpt

>>> import tgpt
>>> bot = tgpt.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 enables seamless interaction with LLaMA AI 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 LLaMA's capabilities (alias LEO by Brave), 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

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.

  • For a quick response:

    python -m tgpt generate "<Your prompt>"
    
  • For interactive mode:

    python -m tgpt interactive "<Kickoff prompt (though not mandatory)>"
    

You can also simply use tgpt instead of python -m tgpt.

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 $ tgpt "<Your prompt>" while $ tgpt will fire up an interactive prompt.

Developer Docs

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

  1. Text Generated only
from tgpt 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?
"""
  1. Whole Response
from tgpt 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 obtain more tailored responses, consider utilizing optimizers using the optimizer parameter. Its values can be set to either code or system_command.

from tgpt import TGPT
bot = TGPT()
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 = tgpt.TGPT(is_conversation=False)

Utilize the --disable-conversation flag in the console to achieve the same functionality.

Acknowledgements

  1. tgpt
  2. You

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-tgpt-0.1.4.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_tgpt-0.1.4-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file python-tgpt-0.1.4.tar.gz.

File metadata

  • Download URL: python-tgpt-0.1.4.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for python-tgpt-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ec201ea1f7de540cd2613b01e440a6d84269efb22ad96ab908afc7385791ef75
MD5 9f1c6297be2ed82524b72f0169d043a5
BLAKE2b-256 3a10e698c9b246578d26df2f260478fa865d6c08d49220ebc191777eb829e102

See more details on using hashes here.

File details

Details for the file python_tgpt-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: python_tgpt-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for python_tgpt-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ca7a35a4d6c51310651e2709bd95e6811fdd5ca1748dbd440c0e282d9268ace8
MD5 970e2630ab6e82d240f8435e34d097d6
BLAKE2b-256 ef22db562a495a998fba887fd8384b55240241f0cab124b12cdf036231392758

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page