OpenAI Python API Library Wrapper
This wrapper provides the ability to stream sync and async responses when using or not function calling, it also provides default responses, memory manipulation and some debugging capabilities.
Installation
# install form PyPI
pip install openai-tools-gpt
Usage
Prior to interact with the Class, remember to setup your OpenAI Api Key in your environment.
Jupyter Notebook
os.environ["OPENAI_API_KEY"] = "Your_api_key",
Or in your terminal
export OPENAI_API_KEY="Your_api_key"
The model is set to "gpt-3.5-turbo" by default, full docstring can be inspect within the Class instantiation.
Simple use case
from openai_tools_gpt import ToolsGPT
gpt: ToolsGPT = ToolsGPT()
input: str = "Hey, what's up"
# Regular response
gpt.invoke(input)
# Synchronous streaming response
for token in gpt.stream(input):
print(token, end="", flush=True)
# Asynchronous streaming response
async for token in gpt.astream(input):
print(token, end="", flush=True)
Tools enabled
from typing import Callable
from openai_tools_gpt import ToolsGPT
tools_schema: dict = [
{
"type": "function",
"function": {
"name": "get_dollar",
"description": "describe what is the function goal",
"parameters": {
"type": "object",
"properties": {},
},
},
}
]
def get_dollar() -> str:
return "4000 COP"
tools: dict[str, Callable] = {"get_dollar": get_dollar}
gpt = ToolsGPT(tools_schema=tools_schema,
tools=tools,
tool_choice="auto")
input: str = "How's the dollar doing ?"
# Regular response
gpt.invoke(input)
# Synchronous streaming response
for token in gpt.stream(input):
print(token, end="", flush=True)
# Asynchronous streaming response
async for token in gpt.astream(input):
print(token, end="", flush=True)
Memory
The model has the memory set to False by default, so it won't remember any interaction,
only the initial message (system or user) it set.
from openai_tools_gpt import ToolsGPT
gpt: ToolsGPT = ToolsGPT(with_memory=True,
memory=[{"role": "system",
"content": "You are my friendly assistant"}])
Debugging
You can also see which tool or tools the model is using for generating the response, if using or not, for every single response.
from openai_tools_gpt import ToolsGPT
gpt: ToolsGPT = ToolsGPT(debug=True)
Useful links
Metadata
Release files for openai-tools-gpt 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| openai_tools_gpt-0.1.6.tar.gz | 5.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| openai_tools_gpt-0.1.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.5 kB
Release files / openai_tools_gpt-0.1.6.tar.gz
| Download URL | openai_tools_gpt-0.1.6.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
41fba665d25f2848368f1c0e9519dd3eb70cf116bf832de489f83d89ffdd8469
|
|
BLAKE2b-256 checksum How to use checksums |
d7e319f2da17e924aa61447f513cd009df9e5e7a7b7bd8fce66dd9657d3651cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.7
|
Release files / openai_tools_gpt-0.1.6-py3-none-any.whl
| Download URL | openai_tools_gpt-0.1.6-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b92214d7c1828a9bc412cc09fa52f75849309c355b91a32ae6a3a6cf92881878
|
|
BLAKE2b-256 checksum How to use checksums |
4258924e88108d9eecb01c46c263a297d959791a2eed6732b242bff21f03290e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.7
|