-
Notifications
You must be signed in to change notification settings - Fork 7
Creating a Hello World prompt tool
Creating a new "tool" in Octopus Copilot simply means you want to include additional functionality to handle another prompt case.
In this exercise, we'll create a tool that responds to prompts like:
Hello world, from Andrew
The first step is to navigate to the project's tools
folder. This folder contains the tools that are executed when OpenAI matches a user's prompt to one of the tools in this folder.
The tools are further categorized by the types of the tools. For example, we have tools that are classified under:
-
CLI: These tools live in the
cli
folder. They are executed from the command line. See this section for an example. -
Generic: These tools live in the
generic
folder and aren't specific to any particular context (with regards to how they are called) -
GitHub Actions: These tools live in the
githubactions
folder. These are where most of the tools live today, as users originally interacted with the tools via the GitHub Copilot chat window in VS Code or Jetbrains Rider, etc.
Note
You might have noticed that there is a wrapper
folder too. To separate the implementation of the prompt handler from its definition, we add slim function definitions in this folder. In nearly all cases, they pass through a callback to the actual implementation and add some basic comments to help OpenAI make the right selection when choosing a tool, e.g., by providing sample prompts it should use.
First, we create the wrapper for the Hello World tool. Create a new Python file called hello_world.py
in the tools/wrapper
folder and include the following code:
def hello_world_wrapper(query, callback, logging):
def hello_world(
persons_name,
**kwargs,
):
"""Answers a prompt like "Hello World!". Use this function when the query is not a question but someone
saying Hello World to you, optionally including their own name. Queries can look like those in the following list:
* Hello World!
* Hello World, from Mary!
Args:
persons_name: The person's name
"""
if logging:
logging("Enter:", "hello_world")
for key, value in kwargs.items():
if logging:
logging(f"Unexpected Key: {key}", "Value: {value}")
# This is just a passthrough to the original callback
return callback(query, persons_name)
return hello_world
The code provides a comment at the top, and a single parameter called persons_name
. The comment provides help to the LLM (OpenAI) by giving examples of the type of prompt that could be suitable for this function. There is no consistently reliable way to build these examples in the comments, it's mostly trial and error and executing tests to ensure the right function is selected at runtime by the LLM (OpenAI).
You can add multiple parameters as necessary. Just ensure you pass them through in the callback at the end.
The function also adds basic logging to show the call is being executed and logs any unexpected arguments passed to it. This can be beneficial for debugging since AI has been known to hallucinate.
Next, we'll create the tool implementation. Open the tools/githubactions
folder and create a file called hello_world_implementation.py
.
Add the following code: