Skip to content
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

Feat/mech quickstart script #1

Merged
merged 9 commits into from
Nov 20, 2024
19 changes: 4 additions & 15 deletions run_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
COST_OF_STAKING = 10**20 # 100 OLAS
COST_OF_BOND_STAKING = 5 * 10**19 # 50 OLAS


CHAIN_ID_TO_METADATA = {
100: {
"name": "Gnosis",
Expand Down Expand Up @@ -89,15 +90,15 @@ def get_service_template(config: MechQuickstartConfig) -> ServiceTemplate:
return ServiceTemplate(
{
"name": "mech_quickstart",
"hash": "bafybeibx772eooap6m7cdjwfyt5pespe22i2mva24y255vw22cd5d7bfuq",
"hash": str(config.mech_hash),
"description": "The mech executes AI tasks requested on-chain and delivers the results to the requester.",
"image": "https://gateway.autonolas.tech/ipfs/bafybeidzpenez565d7vp7jexfrwisa2wijzx6vwcffli57buznyyqkrceq",
"service_version": "v0.1.0",
"home_chain_id": str(config.home_chain_id),
"configurations": {
str(config.home_chain_id): ConfigurationTemplate(
{
"staking_program_id": "mech_service",
"staking_program_id": "mech_marketplace",
"rpc": config.gnosis_rpc,
"nft": "bafybeifgj3kackzfoq4fxjiuousm6epgwx7jbc3n2gjwzjgvtbbz7fc3su",
"cost_of_bond": COST_OF_BOND,
Expand Down Expand Up @@ -144,15 +145,6 @@ def main() -> None:
mech_quickstart_config.password_migrated = True
mech_quickstart_config.store()

# Load account
else:
password = handle_password_migration(operate, mech_quickstart_config)
if password is None:
password = getpass.getpass("Enter local user account password: ")
if not operate.user_account.is_valid(password=password):
print("Invalid password!")
sys.exit(1)

operate.password = password

# Create the main wallet
Expand Down Expand Up @@ -189,10 +181,6 @@ def main() -> None:
os.environ["OPEN_AUTONOMY_SUBGRAPH_URL"] = (
"https://subgraph.autonolas.tech/subgraphs/name/autonolas-staging"
)
os.environ["MAX_PRIORITY_FEE_PER_GAS"] = chain_metadata["gasParams"][
"MAX_PRIORITY_FEE_PER_GAS"
]
os.environ["MAX_FEE_PER_GAS"] = chain_metadata["gasParams"]["MAX_FEE_PER_GAS"]
service_exists = (
manager._get_on_chain_state(chain_config) != OnChainState.NON_EXISTENT
)
Expand Down Expand Up @@ -326,6 +314,7 @@ def main() -> None:
"METADATA_HASH": mech_quickstart_config.metadata_hash,
"MECH_TO_CONFIG": json.dumps(mech_to_config, separators=(',', ':')),
"ON_CHAIN_SERVICE_ID": service.chain_configs[home_chain_id].chain_data.token,
"TOOLS_TO_PACKAGE_HASH": mech_quickstart_config.tools_to_packages_hash,
}
apply_env_vars(env_vars)

Expand Down
47 changes: 47 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# utils.py
import ast
import getpass
import json
import os
Expand Down Expand Up @@ -37,6 +38,10 @@

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 = "bafybeibx772eooap6m7cdjwfyt5pespe22i2mva24y255vw22cd5d7bfuq"

@dataclass
class MechQuickstartConfig(LocalResource):
Expand All @@ -50,6 +55,8 @@ class MechQuickstartConfig(LocalResource):
metadata_hash: t.Optional[str] = None
agent_id: t.Optional[int] = None
mech_address: t.Optional[str] = None
tools_to_packages_hash: t.Optional[dict] = None
mech_hash: t.Optional[str] = None
home_chain_id: t.Optional[int] = None

@classmethod
Expand Down Expand Up @@ -330,6 +337,46 @@ def get_local_config() -> MechQuickstartConfig:
# 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")

if mech_quickstart_config.tools_to_packages_hash is None:
tools_to_packages_hash = (
input(
f"Do you want to set the tools_to_packages_hash dict(set to {DEFAULT_TOOLS_TO_PACKAGE_HASH})? (y/n): "
).lower()
== "y"
)
if tools_to_packages_hash:
while True:
user_input = input(f"Please enter the tools_to_packages_hash dict: ")
tools_to_packages_hash = ast.literal_eval(user_input)
if not isinstance(tools_to_packages_hash, dict):
print("Error: Please enter a valid dict.")
continue
else:
mech_quickstart_config.tools_to_packages_hash = (
tools_to_packages_hash
)
break
else:
mech_quickstart_config.tools_to_packages_hash = (
DEFAULT_TOOLS_TO_PACKAGE_HASH
)

if mech_quickstart_config.mech_hash is None:
mech_hash = (
input(
f"Do you want to set the mech_hash dict(set to {DEFAULT_MECH_HASH})? (y/n): "
).lower()
== "y"
)
if mech_hash:
while True:
user_input = input(f"Please enter the mech_hash: ")
mech_quickstart_config.mech_hash = user_input
break
else:
mech_quickstart_config.mech_hash = DEFAULT_MECH_HASH


mech_quickstart_config.store()
return mech_quickstart_config

Expand Down
Loading