Skip to main content

A library for generating tools for OpenAI projects

Project description

A clean way to generate tools to be used with openai projects

Example using Openai Completions:

from typing import Annotated
from enum import Enum
import json
from openai import OpenAI
from openai_toolgen import tool

class Unit(str, Enum):
    Celcius = "c"
    Farenheit = "f"

@tool
def get_temperature(
        location: Annotated[str, "Location to fetch the tempereature from"],
        unit: Annotated[Unit, "Temperature will be returned in this unit"] = Unit.Celcius
    ):
    """Call this function when the user wants to know the temperature"""

    return { "temperature": 32, "unit": unit.value, "location": location }

client = OpenAI()
messages = [{"role": "user", "content": "What's the temperature in Stockholm today?"}]
completion = client.chat.completions.create(
    model="gpt-4o",
    messages=messages,
    tools=tool.export_all(),
    tool_choice="required"
)

Check out the tests for more details

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-toolgen-0.2.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

openai_toolgen-0.2.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file openai-toolgen-0.2.0.tar.gz.

File metadata

  • Download URL: openai-toolgen-0.2.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for openai-toolgen-0.2.0.tar.gz
Algorithm Hash digest
SHA256 09629c6ba45b28d4913f53507b341ead8291129ec34c3fc7647c4101415f8ebf
MD5 2528f010c4bd6370b524193465bb8d8f
BLAKE2b-256 8ff61d8ace1821cc69f694b4b65ccfed1620464c9a0ce6dd841854dfebb1b98e

See more details on using hashes here.

File details

Details for the file openai_toolgen-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: openai_toolgen-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for openai_toolgen-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a24ae1a19b4ffe295af32f6d40e60143fce12ec4d69a492d896fa6624a832d0c
MD5 559af0a89d472e04173309a18134ccb9
BLAKE2b-256 e2e49a827447dfa57c81d446d8b6955e2d825f67f133dd3a0ad4281556344d2c

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