A magic function decorator using OpenAI ChatCompletion
Project description
Simple demo function using OpenAI's ChatComplete
The only function implemented in this module is magic.
magic
works as a decorator. It simply sends the function's signature and docstring to the GPT and expects to get a result.
It can be installed with pip install magic-decorator
and used with from magic_decorator import magic
.
from magic_decorator import magic
@magic(model="gpt-4")
def transpose(matrix: list[list[int]]) -> list[list[int]]:
"""
This function finds the transpose of the given matrix.
"""
transpose([[1,2,3],[4,5,6]])
[[1, 4], [2, 5], [3, 6]]
from magic_decorator import magic
@magic(model="gpt-4")
def add(a: float, b: float) -> float:
"""
This function adds a and b.
"""
add(1., 10.)
11.0
from magic_decorator import magic
@magic(model="gpt-4")
def friend(message: str) -> str:
"""
This function responds like a friend.
"""
friend("Hi, how are you today?")
'Hey! I am doing great, thank you. How about you?'
Since the magic decorator works with OpenAI's API, you need to put the API_KEY in an environment variable or directly in the decorator.
import os
from magic_decorator import magic
os.environ["OPENAI_API_KEY"] = ...
# or
@magic(model="gpt-4", api_key=...)
def func():
...
Alternatively, you can pre-declare decorators that will be used repeatedly.
cold_magic = magic(model="gpt-4", temperature=0)
@cold_magic
def func():
...
There is no preprocessing, no postprocessing, and no error handling in this module. It's just code to do a simple thing, so there are no prompts to encourage better answers.
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
File details
Details for the file magic_decorator-0.0.4.tar.gz
.
File metadata
- Download URL: magic_decorator-0.0.4.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f15b3e6f96ec56a880099b07d4d60fefb982e47fde186c75c698647dbc913f1 |
|
MD5 | 003a779c34c579b09238d87e61a132e7 |
|
BLAKE2b-256 | 30034ae6dbd7087bf9067c8d2d37903b35fca353aa97e2cb4867333f8a81085f |
File details
Details for the file magic_decorator-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: magic_decorator-0.0.4-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b66107f024866d6621f34e604712ee26bb3092358592110348c2535b6608f7b |
|
MD5 | 066868fa2fd808fa68ce388217dee371 |
|
BLAKE2b-256 | 7fffe57c446d3fa1b8dd35c248fd700cbe6b1a82c27d11c6c116d0044fc2d62c |