AI Ghostfunctions
Project description
AI Ghostfunctions
Write the docstring, call the function, get the results.
Installation
You can install via pip from PyPI:
$ pip install ai-ghostfunctions
Quickstart
import os
from ai_ghostfunctions import ghostfunction
assert os.getenv("OPENAI_API_KEY")
@ghostfunction
def sanitize_messy_string(messy_string: str) -> list[dict]:
"""Return a list of dicts that contain the data from `messy_string`."""
pass
@ghostfunction
def generate_random_words(n: int, startswith: str) -> list:
"""Return a list of `n` random words that start with `startswith`."""
pass
sanitize_messy_string(messy_string="""name|age|nickname
John Brighton Bradford, 34, J.B
Grace B., "24", Grace""")
# '[\n {"name": "John Brighton Bradford", "age": 34, "nickname": "J.B"},\n {"name": "Grace B.", "age": 24, "nickname": "Grace"}\n]'
generate_random_words(n=4, startswith="goo")
# "['gooze', 'goonie', 'gooble', 'goodum']"
generate_random_words(n=3, startswith="foot")
# "['football', 'footstep', 'footnote']"
By default, a ghostfunction will dispatch a sensible prompt to OpenAI GPT-4 that includes the function name, the docstring, and function arguments, parse the result from OpenAI and return it as the result of the function.
Ghostfunctions will retry and send the data to gpt-3.5-turbo if it looks like the OPENAI_API_KEY does not have access to gpt-4.
Yes, it returns strings for now. I'll update that probably soon, so expect a breaking change there.
Customizations
You can control the prompt:
import os
from ai_ghostfunctions import ghostfunction
from ai_ghostfunctions.keywords import SYSTEM, USER
from ai_ghostfunctions.types import Message
assert os.getenv("OPENAI_API_KEY")
@ghostfunction(prompt_function=lambda f, **kwargs: [
Message(role=USER, content=f"tell me a slightly insulting joke about this function name: {f.__name__}.")
])
def recursive_function_that_will_recurse():
"""Recurse until you go crazy."""
pass
recursive_function_that_will_recurse()
# 'Why did the programmer name his function "recursive_function_that_will_recurse"? Because he wanted to make absolutely sure that no one would confuse it for a function that actually does something useful.'
Heh. Not bad.
Prompts to gpt-4 and gpt-3.5-turbo are of type List[ai_ghostfunctions.types.Message]
.
See ghostfunctions.py for the default prompt.
Requirements
Contributing
Contributions are very welcome. To learn more, see the Contributor Guide.
License
Distributed under the terms of the (./LICENSE),
AI Ghostfunctions is free and open source software.
Issues
If you encounter any problems, please file an issue along with a detailed description.
Credits
This project was generated from a fork of @cjolowicz's Hypermodern Python Cookiecutter template.
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
Built Distribution
Hashes for ai_ghostfunctions-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4794475035e2b50bb824e97c9d6a00521a99a8b69b47a46fcd6ea2dc6f5fff8d |
|
MD5 | b5edb6145e2d1770ad99b4f750fcdc9b |
|
BLAKE2b-256 | 29d504aa2a22d20b2049f0586663c1f83acae661c70d85b44daa3c97b1eb5992 |