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
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
magic_decorator-0.0.12.tar.gz
(4.6 kB
view hashes)
Built Distribution
Close
Hashes for magic_decorator-0.0.12-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a0e718760071f27328309362458da782d02534a4895adf13fc282a8ddd37255 |
|
MD5 | 90bf94cf735aa8eff2efac8c4f787fdf |
|
BLAKE2b-256 | e90f537c9570527faa0bd73f88323723a9d5ae7dd863a4bc225234e44bfaf5bb |