Skip to main content

A magic function decorator using OpenAI ChatCompletion

Project description

Simple demo function using LangChain

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 LLM and expects to get a result.

It can be installed with pip install magic-decorator and used with from magic_decorator import magic.

from langchain import SomeLLMModels
llm = SomeLLMModels()

from magic_decorator import magic
@magic(llm=llm)
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(llm=llm)
def add(a: float, b: float) -> float:
    """
    This function adds a and b.
    """
add(1., 10.)
11.0
from magic_decorator import magic
@magic(llm=llm)
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?'

Added a decorator for langchain. In this case, it becomes LLMChain.

llm = SomeLLMModels()
@magic_langchain(llm=llm)
def mychain(arg1: int, arg2: str):
    ...

mychain.predict(arg1=2, arg2="hi")

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


Download files

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

Source Distribution

magic_decorator-0.0.9.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

magic_decorator-0.0.9-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file magic_decorator-0.0.9.tar.gz.

File metadata

  • Download URL: magic_decorator-0.0.9.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for magic_decorator-0.0.9.tar.gz
Algorithm Hash digest
SHA256 5c1329d4831384bf614dd69000b0b1c93d83a6e918833e07ccd87cb7ef6d9e36
MD5 3e3ed33c96efe1880c4d52cfcf33d5df
BLAKE2b-256 b7dafaea0bd6a82811c2543b1fd8f08458b58a5b2f2326ebce8fbec515ada464

See more details on using hashes here.

File details

Details for the file magic_decorator-0.0.9-py3-none-any.whl.

File metadata

File hashes

Hashes for magic_decorator-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 783b2c2cba229771b8a5ed308613e0f6e61757dd40765b10eb217d5904158c0f
MD5 a5633eeacb8f01ba2e171c1fd1500a05
BLAKE2b-256 b3c1104786fba7053ee9317eb640ba0f5bc31edd08f7a4a7cd7e0932fb68144a

See more details on using hashes here.

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