Skip to main content

A library to easily create functions based on OpenAI's GPT

Project description

funcgpt: Python library for creating functions with OpenAI's GPT

funcgpt is an easy-to-use Python library that allows you to quickly create Python functions using the power of OpenAI's GPT models. With just a few lines of code, you can create functions that generate human-like responses, answer questions, or anything else that GPT is capable of.

Features

  • Easy to use decorator for creating functions based on GPT models
  • Supports different GPT model versions
  • Customize GPT's behavior with adjustable temperature values
  • Generate responses in streaming or non-streaming modes

Installation

To install funcgpt, use pip:

pip install funcgpt

Usage

To create a function that answers questions like a pirate, you can use the following snippet:

from funcgpt import gpt

@gpt
def answer_like_pirate(message: str) -> str:
    """Answer questions like a pirate."""
    ...

Usage:

>>> answer_like_pirate("How are you doing today?")
"Arrr, I be doin' fine, matey."

To do the same thing, but with a function that streams responses, you can use the following snippet:

from typing import Iterator
from funcgpt import gpt

@gpt
def stream_like_pirate(message: str) -> Iterator[str]:
    """Answers questions like a pirate."""
    ...

Usage:

>>> for token in stream_like_pirate("How are you doing today?"):
...     print(token, end="", flush=True)
...
Arrr, I be doin' fine, matey.

For defining a function that returns a boolean value, you can use the following snippet:

from funcgpt import gpt

@gpt
def is_pirate(message: str) -> bool:
    """Returns true if the message is from a pirate."""
    ...

Usage:

>>> is_pirate("Arrr, I be doin' fine, matey.")
True

For choosing a different model or temperature, you can use the model and temperature keyword arguments:

from funcgpt import gpt

@gpt(model="gpt-4", temperature=0)
def answer_like_pirate(message: str) -> str:
    """Answer questions like a pirate."""
    ...

Contributing

We welcome contributions! Please feel free to fork the repository, make changes, and submit pull requests. If you have any questions or ideas, don't hesitate to open an issue.

License

funcgpt is released under the MIT License. See the LICENSE file 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

funcgpt-1.0.0.tar.gz (6.6 kB view hashes)

Uploaded Source

Built Distribution

funcgpt-1.0.0-py3-none-any.whl (7.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page