Simple Wrapper For The ChatGPT API
This module is designed for asynchronous usage and provides a simple interface to the OpenAI ChatGPT API
It also provides a command-line interface for interactive usage.
While it does provide synchronous methods, it is recommended to use the asynchronous methods for better performance.
Features
- Asynchronous API
- Get/Stream responses
- Save/Load session history
- Change parameters on the fly
- Embed images in messages
- Register functions to
tool_callswith ease - Interactive command-line interface
Installation
pip install -U ngptbot
Usage
Command Line
Configuration
gptbot requires a model and an API key to be set.
You can use config file, command parameters or interactive input to set these values.
By default, gptbot will look for files named config.json and session.json in the user config and cache directory.
gptbot -c /path/to/config.json # Use a config file
gptbot -m "gpt-3.5-turbo" # Set model, input API key interactively
gptbot -k /path/to/config.json # create config file
Parameters
-c,--config: Path to a JSON file-m,--model: Model name-k,--create-config: Create a config file interactively-s,--session: Session history file-V,--version: Show version
Precedence: Interactive input > Command parameters > Config file
Interactive Mode
This mode mimics a chat interface. You can type your message and get a response.
Commands are started with a / and are case-sensitive.
/exit: Exit the program/save <path>: Save the session history to a file/load <path>: Load a session history from a file/rollback <step>: Rollback to the previous state/clear: Clear the session history/role: Switch role/model: Switch model/tokens: Show used tokens/help: Show help
To embed an image, insert #image(<url>) in your message.
Use double # to escape embedding.
await bot.send("""
What are these?
#image(https://example.com/image.png)
#image(file:///path/to/image.png)
#image(base64://<base64-encoded-image>)
""")
All URLs will be downloaded and embedded as base64-encoded images.
API
import asyncio
import gptbot
bot = gptbot.Bot(model="gpt-3.5-turbo", api_key="your-api-key")
async def main():
response = await bot.send("Hello, how are you?")
print(response)
async for r in bot.stream("I'm fine, thank you."):
print(r, end='')
async for res in bot.stream_raw("What is the answer to life, the universe, and everything?"):
"""
stream_raw returns a stream of `FullChunkResponse`.
It contains all raw data from the API.
"""
bot.send_sync("Goodbye!") # Synchronous version of `send`
# Bot class is stateless, to keep track of the conversation, use the `Session` class
session = bot.new_session()
# You can use session just like the bot
async for r in session.stream("Hello!"):
print(r, end='')
print(await session.send("Goodbye!"))
asyncio.run(main())
Registering Functions
Functions are under Bot.funcs and can be registered with the add_func decorator.
@bot.add_func
def my_func(data: str, default:int = 123): # parameters must be annotated, variadic parameters are not supported
"""Documentation goes here"""
return data # return value must be stringifiable
Metadata
Release files for ngptbot 0.3.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ngptbot-0.3.5.tar.gz | 15.1 kB | Without provenance | Details for ngptbot-0.3.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ngptbot-0.3.5-py3-none-any.whl | Python 3 | none | any | Details for ngptbot-0.3.5-py3-none-any.whl |
Total release size: 29.2 kB
Release files / ngptbot-0.3.5.tar.gz
| Download URL | ngptbot-0.3.5.tar.gz |
|---|---|
| Size | 15.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
95b9221db6b451eacffe378f5761428dbe84d699e20d1db109baacf0621913d1
|
|
BLAKE2b-256 checksum How to use checksums |
1ff180d6f4059132776474d882e7a50bd66f5747e98b4b0cf577aecbe5aa4a82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.12.2 Linux/6.5.0-35-generic
|
Release files / ngptbot-0.3.5-py3-none-any.whl
| Download URL | ngptbot-0.3.5-py3-none-any.whl |
|---|---|
| Size | 14.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b958fe82657d196c594f8948a25759db299729dedc7a03dd7d02eb84539f3165
|
|
BLAKE2b-256 checksum How to use checksums |
e102ad9f0dee973e1685a3e00252acc2759a8c01226ed76f02135a4277a67963
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.12.2 Linux/6.5.0-35-generic
|
Security for ngptbot 0.3.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.