Top Hat
Do you know how magicians could pull stuff out of an apparently empty top hat?
I only recently discovered how that worked, and apparently it was dunder methods all along! Who would have thought!
So I decided to implement something similar in Python: you can import any method whatsoever from this magical magic_top_hat, even if the module itself seems empty!
import magic_top_hat
dir(magic_top_hat) # returns []
BUT! With sleight of hand you can actually import anything you want out of the magic_top_hat:
from magic_top_hat import get_day_out_of_datetime
from datetime import datetime
def get_today_day() -> str:
today = datetime.now()
day = get_day_out_of_datetime(today)
return day # this will return the day name
and a function will be generated that satisfies your every need*!
Do you need to know how the function generated your result? No, right? Implementation is just a detail for the code monkeys! If you really have no trust in this (as you should), you can set the environmental variable I_DONT_TRUST_ROBOTS to have each implementation printed out.
*satisfaction not guaranteed. You will need to set a OPENAI_API_KEY env parameter for this to work. And even then, it might not work.
How
Well, I simply send the caller code to OpenAI and ask ChatGPT to generate a function that will fulfill the request, given the context in which it was called, the name it was given and the parameters it received.
So the results may vary from abysmal to groteque.
Why
It was really fun to try and build something like this, also I had a couple of hours to kill before sleep. Also, I can honestly say that this is AI powered!
Examples
Look at scripts/example.py for a couple of simple examples!
Release files for magic-top-hat 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| magic_top_hat-0.1.0.tar.gz | 3.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| magic_top_hat-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.0 kB
Release files / magic_top_hat-0.1.0.tar.gz
| Download URL | magic_top_hat-0.1.0.tar.gz |
|---|---|
| Size | 3.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
88b3040d879769e3b4a5d921f3b6a170cddf87cd08a0164feece3e0ef2b3d42d
|
|
BLAKE2b-256 checksum How to use checksums |
67e17768616e51fdac476e2c6d322f773f61c492f4620287765ce6abaacce144
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.3
|
Release files / magic_top_hat-0.1.0-py3-none-any.whl
| Download URL | magic_top_hat-0.1.0-py3-none-any.whl |
|---|---|
| Size | 2.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1649f5cbe7dea9171798da6fb1981175b383af0034462277a11a84a3d81779b7
|
|
BLAKE2b-256 checksum How to use checksums |
0de65c47a5e339ca0ba477dfcba325dc037449b63aca9b86bb27790028fedd09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.3
|