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.12.tar.gz (4.6 kB view hashes)

Uploaded Source

Built Distribution

magic_decorator-0.0.12-py3-none-any.whl (4.0 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