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 details)

Uploaded Source

Built Distribution

magic_decorator-0.0.12-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for magic_decorator-0.0.12.tar.gz
Algorithm Hash digest
SHA256 5bf90bd79ce8c39f760fe6fa6d7d03571e260ccaf3a69380ac55297da8faa199
MD5 925899e9bd08948150785fc4300d8e0b
BLAKE2b-256 9555395570f4ae5a6d64901633131f31fa67f7e481e4d0951e1f6dbe2f04d8c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for magic_decorator-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 1a0e718760071f27328309362458da782d02534a4895adf13fc282a8ddd37255
MD5 90bf94cf735aa8eff2efac8c4f787fdf
BLAKE2b-256 e90f537c9570527faa0bd73f88323723a9d5ae7dd863a4bc225234e44bfaf5bb

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