-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added script to create metadata hash for the mech #3
Changes from 2 commits
067993c
b2fe914
0472c0b
9583a1e
2b74ae4
4c0c007
0bb952f
fc0239e
845f248
5d1ee1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,3 +54,5 @@ local_config.json | |
mech.db | ||
|
||
/.api_keys.json | ||
|
||
.metadata_hash.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "Autonolas Mech Quickstart", | ||
"description": "The mech executes AI tasks requested on-chain and delivers the results to the requester.", | ||
"inputFormat": "ipfs-v0.1", | ||
"outputFormat": "ipfs-v0.1", | ||
"image": "https://gateway.autonolas.tech/ipfs/bafybeidzpenez565d7vp7jexfrwisa2wijzx6vwcffli57buznyyqkrceq", | ||
"tools": [ | ||
"openai-gpt-4" | ||
] | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it makes sense that this gets called upon setup of local config on |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from typing import Tuple | ||
|
||
import multibase | ||
import multicodec | ||
from aea.helpers.cid import to_v1 | ||
from aea_cli_ipfs.ipfs_utils import IPFSTool | ||
from utils import ( | ||
print_title, | ||
OPERATE_HOME, | ||
MechQuickstartConfig, | ||
input_with_default_value, | ||
OperateApp, | ||
) | ||
|
||
|
||
def main() -> None: | ||
""" | ||
Push the metadata file to IPFS. | ||
""" | ||
|
||
print_title("Mech Quickstart: Metadata hash setup") | ||
print("This script will assist you in setting up the metadata hash for your mech.") | ||
print() | ||
|
||
operate = OperateApp( | ||
home=OPERATE_HOME, | ||
) | ||
operate.setup() | ||
|
||
path = OPERATE_HOME / "local_config.json" | ||
if path.exists(): | ||
mech_quickstart_config = MechQuickstartConfig.load(path) | ||
else: | ||
mech_quickstart_config = MechQuickstartConfig(path) | ||
|
||
metadata_hash_path = input_with_default_value( | ||
"Please provide the path to your metadata_hash.json file", | ||
"./.metadata_hash.json", | ||
) | ||
Comment on lines
+62
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should do some validation as well. Basically needs to follow the schema like here. |
||
|
||
response = IPFSTool().client.add( | ||
metadata_hash_path, pin=True, recursive=True, wrap_with_directory=False | ||
) | ||
v1_file_hash = to_v1(response["Hash"]) | ||
cid_bytes = multibase.decode(v1_file_hash) | ||
multihash_bytes = multicodec.remove_prefix(cid_bytes) | ||
v1_file_hash_hex = "f01" + multihash_bytes.hex() | ||
|
||
mech_quickstart_config.metadata_hash = v1_file_hash_hex | ||
mech_quickstart_config.store() | ||
|
||
print() | ||
print_title("Metadata hash successfully generated and stored in config") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,10 +39,8 @@ | |
WARNING_ICON = colored("\u26A0", "yellow") | ||
OPERATE_HOME = Path.cwd() / ".mech_quickstart" | ||
DEFAULT_TOOLS_TO_PACKAGE_HASH = None | ||
DEFAULT_MECH_TO_SUBSCRIPTION = None | ||
DEFAULT_MECH_TO_CONFIG = None | ||
DEFAULT_MECH_HASH = "bafybeig544gw6i7ahlwj6d64djlwfltjuznz3p66kmwk4m6bzqtn2bjfbq" | ||
|
||
DEFAULT_MECH_METADATA_HASH = "f01701220caa53607238e340da63b296acab232c18a48e954f0af6ff2b835b2d93f1962f0" | ||
@dataclass | ||
class MechQuickstartConfig(LocalResource): | ||
"""Local configuration.""" | ||
|
@@ -348,8 +346,27 @@ def get_local_config() -> MechQuickstartConfig: | |
load_api_keys(mech_quickstart_config) | ||
|
||
if mech_quickstart_config.metadata_hash is None: | ||
# TODO: default value is not a good idea here, we need to think of better ways to do this. | ||
mech_quickstart_config.metadata_hash = input_with_default_value("Please provide the metadata hash", "f01701220caa53607238e340da63b296acab232c18a48e954f0af6ff2b835b2d93f1962f0") | ||
metadata_hash = ( | ||
input( | ||
f"Do you want to update the metadata_hash str(set to {DEFAULT_MECH_METADATA_HASH})? (y/n): " | ||
).lower() | ||
== "y" | ||
) | ||
if metadata_hash: | ||
while True: | ||
user_input = input(f"Please enter the metadata_hash str: ") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we just call the other function here |
||
if not isinstance(user_input, str): | ||
print("Error: Please enter a valid str.") | ||
continue | ||
else: | ||
mech_quickstart_config.metadata_hash = ( | ||
user_input | ||
) | ||
break | ||
else: | ||
mech_quickstart_config.metadata_hash = ( | ||
DEFAULT_MECH_METADATA_HASH | ||
) | ||
|
||
if mech_quickstart_config.tools_to_packages_hash is None: | ||
tools_to_packages_hash = ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The metadata is missing here. Check example here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not seperate the tool metadata into the tool's yaml?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a future version yes, atm no. It will take too much time.