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

CLI improvements #46

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions mech_client/interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,18 @@ def get_mech_config(chain_config: Optional[str] = None) -> MechConfig:
if chain_config is None:
chain_config = next(iter(data))

print(f"Chain configuration: {chain_config}")
print("Chain configuration:")
entry = data[chain_config].copy()
ledger_config = LedgerConfig(**entry.pop("ledger_config"))
mech_config = MechConfig(**entry, ledger_config=ledger_config)

print(f" - Chain ID: {chain_config}")
print(f" - Gas limit: {mech_config.gas_limit}")
print(f" - Contract ABI URL: {mech_config.contract_abi_url}")
print(f" - Transation URL: {mech_config.transaction_url}")
print(f" - Subgraph URL: {mech_config.subgraph_url}")
print("")

return mech_config


Expand Down Expand Up @@ -371,7 +379,9 @@ def send_request( # pylint: disable=too-many-arguments,too-many-locals
v1_file_hash_hex_truncated, v1_file_hash_hex = push_metadata_to_ipfs(
prompt, tool, extra_attributes
)
print(f"Prompt uploaded: https://gateway.autonolas.tech/ipfs/{v1_file_hash_hex}")
print(
f" - Prompt uploaded: https://gateway.autonolas.tech/ipfs/{v1_file_hash_hex}"
)
method_name = "request"
methord_args = {"data": v1_file_hash_hex_truncated}
tx_args = {
Expand Down Expand Up @@ -573,7 +583,7 @@ def interact( # pylint: disable=too-many-arguments,too-many-locals
request_signature=request_event_signature,
deliver_signature=deliver_event_signature,
)
print("Sending request...")
print("Sending Mech request...")
transaction_digest = send_request(
crypto=crypto,
ledger_api=ledger_api,
Expand All @@ -586,19 +596,26 @@ def interact( # pylint: disable=too-many-arguments,too-many-locals
timeout=timeout,
sleep=sleep,
)

if not transaction_digest:
print("Unable to send request")
return None

transaction_url_formatted = mech_config.transaction_url.format(
transaction_digest=transaction_digest
)
print(f"Transaction sent: {transaction_url_formatted}")
print("Waiting for transaction receipt...")
print(f" - Transaction sent: {transaction_url_formatted}")
print(" - Waiting for transaction receipt...")
request_id = watch_for_request_id(
wss=wss,
mech_contract=mech_contract,
ledger_api=ledger_api,
request_signature=request_event_signature,
)
print(f"Created on-chain request with ID {request_id}")
print("Waiting for Mech response...")
print(f" - Created on-chain request with ID {request_id}")
print("")

print("Waiting for Mech deliver...")
data_url = wait_for_data_url(
request_id=request_id,
wss=wss,
Expand All @@ -610,8 +627,9 @@ def interact( # pylint: disable=too-many-arguments,too-many-locals
confirmation_type=confirmation_type,
)
if data_url:
print(f"Data arrived: {data_url}")
data = requests.get(f"{data_url}/{request_id}").json()
print(f"Data from agent: {data}")
print(f" - Data arrived: {data_url}")
data = requests.get(f"{data_url}/{request_id}", timeout=30).json()
print(" - Data from agent:")
print(json.dumps(data, indent=2))
return data
return None
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ skipsdist = True
skip_install = True
deps =
tomte[safety]==0.2.15
commands = safety check -i 37524 -i 38038 -i 37776 -i 38039 -i 39621 -i 40291 -i 39706 -i 41002 -i 51358 -i 51499 -i 67599
commands = safety check -i 37524 -i 38038 -i 37776 -i 38039 -i 39621 -i 40291 -i 39706 -i 41002 -i 51358 -i 51499 -i 67599 -i 70612

[testenv:darglint]
skipsdist = True
Expand Down
Loading