No project description provided
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openai_tools_gpt-0.1.6.tar.gz.
File metadata
- Download URL: openai_tools_gpt-0.1.6.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41fba665d25f2848368f1c0e9519dd3eb70cf116bf832de489f83d89ffdd8469
|
|
| MD5 |
498e2f94aeb97ba36284ed73dbc0f364
|
|
| BLAKE2b-256 |
d7e319f2da17e924aa61447f513cd009df9e5e7a7b7bd8fce66dd9657d3651cb
|
File details
Details for the file openai_tools_gpt-0.1.6-py3-none-any.whl.
File metadata
- Download URL: openai_tools_gpt-0.1.6-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b92214d7c1828a9bc412cc09fa52f75849309c355b91a32ae6a3a6cf92881878
|
|
| MD5 |
ef6005b876832a9f5645f69e453ab614
|
|
| BLAKE2b-256 |
4258924e88108d9eecb01c46c263a297d959791a2eed6732b242bff21f03290e
|