Skip to main content

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 Object remembe to setup your OpenAI Api Key in your environment.

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 = ToolsGPT()

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


Download files

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

Source Distribution

openai_tools_gpt-0.1.5.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

openai_tools_gpt-0.1.5-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file openai_tools_gpt-0.1.5.tar.gz.

File metadata

  • Download URL: openai_tools_gpt-0.1.5.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for openai_tools_gpt-0.1.5.tar.gz
Algorithm Hash digest
SHA256 bc0ec86e068594ace958098077ce022626572e756d68682d6f10547f219f50cc
MD5 c9a9539a055b53915d44abf495b26da4
BLAKE2b-256 7a391b8c219dd7de23dda8bf016b1f6564a39297c695c556b54f490efa912ba5

See more details on using hashes here.

File details

Details for the file openai_tools_gpt-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for openai_tools_gpt-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a1ac4c67de5e917d202c4fde3cb1c13f9d4317e10e081ac9eb9b34307a71cf41
MD5 507482ea6b7c4f1887de378a5f3e0b97
BLAKE2b-256 4c7214392b0a861c761dae03180d55877fcd3d813de3aea6d27ecbddbaf88ab3

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