01 Skills Create
Function: create
¶
Generates a CodeSkill
instance using different input sources.
Parameters:¶
request
: String detailing the skill functionality.messages
ormessages_json_path
: Messages as a list of dictionaries or a path to a JSON file containing messages.file_content
orfile_path
: String of file content or path to a code/API doc file.skill_path
orskill_json_path
: Directory path with skill name as stem or file path withskill.json
as stem.
Returns:¶
CodeSkill
: The created skill.
Usage:¶
- Creating Skill using a Request String:
skill = create(request="filter how many prime numbers are in 201")
from creator import create
The fundamental principle of the "create API" is to utilize various input sources to assemble messages. These messages are then forwarded to a tagging agent to construct a consistent skill object.
?create
Signature: create( request: Optional[str] = None, messages: Optional[List[dict]] = None, messages_json_path: Optional[str] = None, skill_path: Optional[str] = None, skill_json_path: Optional[str] = None, file_content: Optional[str] = None, file_path: Optional[str] = None, huggingface_repo_id: Optional[str] = None, huggingface_skill_path: Optional[str] = None, save: bool = False, ) -> creator.core.skill.CodeSkill Docstring: Main method to create a new skill. File: ~/miniconda3/envs/open_creator_online/lib/python3.10/site-packages/creator/core/core.py Type: method
1. Creating a Skill Using a Request String¶
The request will be forwarded to a code interpreter agent, which will facilitate multi-turn problem-solving experiences. This process will generate a sequence of messages.
These messages will then be relayed to a skill extractor agent, which will produce a formatted skill object.
skill = create(request="filter how many prime numbers are in 201")
Output()
Output()
Output()
Output()
Output()
Output()
skill.show()
Skill Details: • Name: count_prime_numbers • Description: This skill counts the number of prime numbers within a given range. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. • Version: 1.0.0 • Usage: count_prime_numbers(201) # returns 46 • Parameters: • n (integer): The upper limit of the range within which to count prime numbers. • Required: True • Returns: • prime_count (integer): The number of prime numbers within the given range.
2 Creating Skill using Messages¶
This only use case is for the skill extractor agent. The messages are forwarded to the skill extractor agent, which will produce a formatted skill object.
messages = [
{
"role": "user",
"content": "write a program to list all the python functions and their docstrings in a directory"
},
{
"role": "assistant",
"content": "Sure, I can help with that. Here's the plan:\n\n1. First, we need to get a list of all Python files in the specified directory. We can do this by using the `os` and `glob` modules in Python.\n2. Then, for each Python file, we will parse the file to find all function definitions. We can do this by using the `ast` module in Python, which can parse Python source code into an abstract syntax tree (AST).\n3. For each function definition, we will extract the function's name and its docstring. The `ast` module can also help us with this.\n4. Finally, we will print out the function names and their docstrings.\n\nLet's start with step 1: getting a list of all Python files in the specified directory.",
"function_call": {
"name": "run_code",
"arguments": "{\n \"language\": \"python\",\n \"code\": \"import os\\nimport glob\\n\\n# Get the current working directory\\ncwd = os.getcwd()\\n\\n# Get a list of all Python files in the directory\\npython_files = glob.glob(os.path.join(cwd, '*.py'))\\n\\npython_files\"\n}",
}
}
]
skill = create(messages=messages)
skill.show()
Skill Details: • Name: list_python_functions_and_docstrings • Description: This skill lists all the Python functions and their docstrings in a specified directory. It first gets a list of all Python files in the directory, then parses each file to find all function definitions. For each function definition, it extracts the function's name and its docstring. • Version: 1.0.0 • Usage: list_python_functions_and_docstrings('/path/to/directory') • Parameters: • directory (string): The directory to search for Python files. • Required: True • Returns:
Also, you can pass a messages JSON file path to the messages_json_path
parameter.
skill = create(messages_json_path="./data/messages_example.json")
skill.show()
Skill Details: • Name: extract_pages_from_pdf • Description: This skill extracts a specified range of pages from a PDF file and saves them as a new PDF file. The user needs to provide the path to the original PDF file and the range of pages to be extracted. The extracted pages are saved in a new PDF file in the current working directory. • Version: 1.0.0 • Usage: extract_pages_from_pdf('~/Downloads/voyager.pdf', 2, 5, 'voyager_extracted.pdf') • Parameters: • pdf_path (string): Path to the original PDF file. • Required: True • start_page (integer): The first page to be extracted. Page numbers start from 1. • Required: True • end_page (integer): The last page to be extracted. This page is included in the extraction. • Required: True • output_file (string): Name of the output file where the extracted pages will be saved. • Default: 'extracted_pages.pdf' • Returns: • output_file (string): Name of the output file where the extracted pages were saved.
3. Creating Skill using a File Content (code, API doc, etc.)¶
Different to create a skill by request, we construct the messages by parsing the file content. The messages are then forwarded to the skill extractor agent, which will produce a formatted skill object.
code_file_content = """
from rich import print as rich_print
from rich.markdown import Markdown
from rich.rule import Rule
def display_markdown_message(message):
'''Display markdown message. Works with multiline strings with lots of indentation.
Will automatically make single line > tags beautiful.
'''
for line in message.split("\n"):
line = line.strip()
if line == "":
print("")
elif line == "---":
rich_print(Rule(style="white"))
else:
rich_print(Markdown(line))
if "\n" not in message and message.startswith(">"):
# Aesthetic choice. For these tags, they need a space below them
print("")
"""
skill = create(file_content=code_file_content)
skill.show()
Skill Details: • Name: display_markdown_message • Description: This skill is used to display a markdown message. It works with multiline strings with lots of indentation and will automatically make single line > tags beautiful. • Version: 1.0.0 • Usage: display_markdown_message('> This is a markdown message.') • Parameters: • message (string): The markdown message to be displayed. • Required: True • Returns:
Also, you can pass a API doc to the file_path
parameter.
skill = create(file_path="./data/create_api.md")
skill.show()
Skill Details: • Name: create • Description: This function generates a CodeSkill instance using different input sources. It can take in a request string detailing the skill functionality, messages or a path to a JSON file containing messages, a string of file content or path to a code/API doc file, a directory path with skill name as stem or file path with skill.json as stem, an identifier for a Huggingface repository, or a path to the skill within the Huggingface repository. • Version: 1.0.0 • Usage: from creator import create skill = create(request='...', messages=[...], file_content='...', file_path='...', skill_path='...', skill_json_path='...', huggingface_repo_id='...', huggingface_skill_path='...') • Parameters: • request (string): String detailing the skill functionality. • messages (array): Messages as a list of dictionaries. • messages_json_path (string): Path to a JSON file containing messages. • file_content (string): String of file content. • file_path (string): Path to a code/API doc file. • skill_path (string): Directory path with skill name as stem. • skill_json_path (string): File path with skill.json as stem. • huggingface_repo_id (string): Identifier for a Huggingface repository. • huggingface_skill_path (string): Path to the skill within the Huggingface repository. • Returns: • CodeSkill (object): The created skill.
4. Load a created skill from skill library¶
You can load a skill from the skill library by passing the skill path to the skill_path
parameter. The skill path can be a directory path with skill name as stem or file path with skill.json
as stem.
The default skill library path is ~/.cache/open-creator/skill_library
.
# or
# from creator import save
# save(skill)
skill.save()
▌ saved to /Users/gongjunmin/.cache/open_creator/skill_library/create
skill = create(skill_path="/Users/gongjunmin/.cache/open_creator/skill_library/create_api")
# or
# skill = create(skill_path="/Users/gongjunmin/.cache/open_creator/skill_library/create_api/skill.json")
skill.show()
Skill Details: • Name: create_api • Description: Generates a CodeSkill instance using different input sources. • Version: 1.0.0 • Usage: create_api(request, messages=messages, messages_json_path=messages_json_path, file_content=file_content, file_path=file_path, skill_path=skill_path, skill_json_path=skill_json_path, huggingface_repo_id=huggingface_repo_id, huggingface_skill_path=huggingface_skill_path) • Parameters: • request (string): String detailing the skill functionality. • Required: True • messages (array): Messages as a list of dictionaries. • messages_json_path (string): Path to a JSON file containing messages. • file_content (string): String of file content. • file_path (string): Path to a code/API doc file. • skill_path (string): Directory path with skill name as stem. • skill_json_path (string): File path with skill.json as stem. • huggingface_repo_id (string): Identifier for a Huggingface repository. • huggingface_skill_path (string): Path to the skill within the Huggingface repository. • Returns: • CodeSkill (object): The created skill.
Created: October 18, 2023