This is a Naptha tool module for generating images using the Stability API. Tool modules can be run independently or used by agents.
Naptha Modules are the building blocks of multi-agent applications, which enable them to run across multiple nodes.
naptha run tool:generate_image_tool -p "tool_name='generate_image_tool', tool_input_data='expansive landscape rolling greens with gargantuan yggdrasil, intricate world-spanning roots towering under a blue alien sky, masterful, ghibli'"
The Generate Image Agent is an example of an agent that uses the generate image tool. In this case, the generate_image module is set as the default tool in the generate_image_agent/configs/tool_deployments.json file.
naptha run agent:generate_image_agent -p "prompt='expansive landscape rolling greens with gargantuan yggdrasil, intricate world-spanning roots towering under a blue alien sky, masterful, ghibli'" --tool_node_urls "http://localhost:7001"
You can check out other examples of tool modules using the following CLI command with the Naptha SDK.
naptha tools
From the official poetry docs:
curl -sSL https://install.python-poetry.org | python3 -
export PATH="/home/$(whoami)/.local/bin:$PATH"
Before deploying a new or updated module to a Naptha node, you should iterate on improvements with the module locally.
Clone the repo using:
git clone https://github.com/NapthaAI/<module_name>
cd <module_name>
Create a copy of the .env file:
cp .env.example .env
If your module calls others modules (e.g. using Agent(), Tool(), or Environment()), you need to set a PRIVATE_KEY
in the .env file (e.g. this can be the same as the PRIVATE_KEY
you use with the Naptha SDK). If using Stability, make sure to set the STABILITY_API_KEY
environment variable.
You can install the module using:
poetry install
The main place to make changes to the code is in the run.py
file. This is the default entry point that will be used when the module run is initiated. The run function can instantiate a class (e.g. an agent class) or call a function.
You can make changes to the configs in the configs
folder. For example:
MODEL: If you would like to use a different model, you can change the llm_config['config_name']
in the tool_deployments.json
file (the config_name
must match the config_name
in the llm_configs.json
file).
After making changes to the module, testing usually involves the following steps:
- Test the module locally without the Naptha Node
- Test the module on a local Naptha Node (with a local Hub)
- Test the module on a hosted Naptha Node (with the hosted Naptha Hub)
You can run the module using:
poetry run python <module_name>/run.py
Now you can iterate on the module and commit your changes. When ready, you can push to your GitHub account or IPFS (or both). Make sure to change the remote origin. Also add a new module version number using e.g.:
git tag v0.1
git push --tags
For this step, you will need to:
- Run your own Naptha Node and Hub. Follow the instructions here (still private, please reach out if you'd like access at [email protected]) to run your own Naptha Node and Hub. To run a local Hub, set
LOCAL_HUB=True
in the .env file for the NapthaAI/node repository. - Install the Naptha SDK using the instructions here. To use the SDK with your local node and hub, set
NODE_URL=http://localhost:7001
andHUB_URL=ws://localhost:3001/rpc
in the .env file for the NapthaAI/naptha-sdk repository.
naptha tools tool_name -p "description='Tool description' module_url='ipfs://QmNer9SRKmJPv4Ae3vdVYo6eFjPcyJ8uZ2rRSYd3koT6jg'"
Make sure to replace the placeholder descriptions and URLs with your own. To check that the tool module is registered correctly, you can run naptha tools
.
Once the tool is registered on the Hub, you can run it on a local Naptha Node using the Naptha SDK:
naptha run tool:tool_name -p "tool_name='func', tool_input_data='nice picture of a cat...'"
For troubleshooting, see the Troubleshooting section in NapthaAI/node for checking the logs.
Have an idea for a cool tool module to build? Get in touch at [email protected].