Last active
October 20, 2024 00:16
-
-
Save konsumer/95290c13cb7309d7e7d0d2f717199973 to your computer and use it in GitHub Desktop.
Generate AI tool description from a python file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from docstring_parser import parse | |
import tools | |
def tool_parse(tools): | |
""" | |
build AI tools-definition from python functions & docs | |
""" | |
toolsOut = [] | |
for fname in dir(tools): | |
if not fname.startswith('__'): | |
f = getattr(tools, fname) | |
d = parse(f.__doc__) | |
newtool = { "parameters": {"type": "object", "properties": {}}, "required": [], "name":fname, "description": d.description.strip() } | |
for p in d.params: | |
newtool["parameters"]["properties"][p.arg_name] = { | |
"type": p.type_name, | |
"description": p.description | |
} | |
if not p.is_optional: | |
newtool["required"].append(p.arg_name) | |
toolsOut.append(newtool) | |
return toolsOut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def download_torrent(id): | |
""" | |
Download a torrent by ID. | |
Parameters: | |
id (str): The ID of the torrent to download | |
Returns: | |
None | |
""" | |
pass | |
def get_torrents_for_movie(title, year): | |
""" | |
Get a list of torrents available for a movie. | |
Parameters: | |
title (str): The title of the movie, without the year | |
year (int?): The year the movie was made | |
Returns: | |
list: A list of torrent IDs | |
""" | |
pass | |
def get_torrents_for_an_album(title, artist, year): | |
""" | |
Get a list of torrents available for a music album. | |
Parameters: | |
title (str): The title of the album | |
artist (str?): The artist that made the album | |
year (int?): The year the album was made | |
Returns: | |
list: A list of torrent IDs | |
""" | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"parameters": { | |
"type": "object", | |
"properties": { | |
"id": { | |
"type": "str", | |
"description": " The ID of the torrent to download" | |
} | |
} | |
}, | |
"required": [ | |
"id" | |
], | |
"name": "download_torrent", | |
"description": "Download a torrent by ID." | |
}, | |
{ | |
"parameters": { | |
"type": "object", | |
"properties": { | |
"title": { | |
"type": "str", | |
"description": "The title of the album" | |
}, | |
"artist": { | |
"type": "str", | |
"description": "The artist that made the album" | |
}, | |
"year": { | |
"type": "int", | |
"description": "The year the album was made" | |
} | |
} | |
}, | |
"required": [ | |
"title" | |
], | |
"name": "get_torrents_for_an_album", | |
"description": "Get a list of torrents available for a music album." | |
}, | |
{ | |
"parameters": { | |
"type": "object", | |
"properties": { | |
"title": { | |
"type": "str", | |
"description": "The title of the movie, without the year" | |
}, | |
"year": { | |
"type": "int", | |
"description": "The year the movie was made" | |
} | |
} | |
}, | |
"required": [ | |
"title" | |
], | |
"name": "get_torrents_for_movie", | |
"description": "Get a list of torrents available for a movie." | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment