ch3njust1n / smart

Self-modifying code at runtime with Large Language Models
MIT License
4 stars 0 forks source link

[Metaprogramming] _is_generative #41

Closed ch3njust1n closed 1 year ago

ch3njust1n commented 1 year ago

_is_generative property in decorators and metaclasses indicate a function or class has access to a generative model. Currently unclear how this could be used, but it gives the rest of the program information on what is generative and what is now.

Here is an example that could be used so that a LLM knows it can also manipulate other parts of the program:

import inspect
import textwrap
from meta import gpt4

all_methods = inspect.getmembers(
    cls, predicate=inspect.isfunction
)
available_funcs = [
    (
        method[0],
        textwrap.dedent(inspect.getsource(method[1])),
    )
    for method in all_methods if method._is_generative
]

func_source = gpt4(f'Generate code with these generative functions: {available_funcs}')