Skip to content

Commit

Permalink
chore: add subgraph request timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMinarsch committed Mar 23, 2024
1 parent d8710b5 commit d34c8f0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Commands:
push-to-ipfs Upload a file to IPFS.
```

## Usage:
## CLI Usage:

First, create a private key in file `ethereum_private_key.txt` with this command:

Expand Down Expand Up @@ -94,6 +94,25 @@ Data arrived: https://gateway.autonolas.tech/ipfs/f0170122069b55e077430a00f3cbc3
Data from agent: {'requestId': 81653153529124597849081567361606842861262371002932574194580478443414142139857, 'result': "\n\nA summer breeze, so sweet,\nA gentle reminder of summer's heat.\nThe sky so blue, no cloud in sight,\nA perfect day, a wondrous sight."}
```

## Programmatic Usage:

```python
from mech_client.interact import interact, ConfirmationType

prompt_text = 'Will gnosis pay reach 100k cards in 2024?'
agent_id = 3
tool_name = "prediction-online"

result = interact(
prompt=prompt_text,
agent_id=agent_id,
tool=tool_name,
confirmation_type=ConfirmationType.ON_CHAIN,
private_key_path='PATH_HERE'
)
print(result)
```

## Release guide:

- Bump versions in `pyproject.toml` and `mech_client/__init__.py`
Expand Down
2 changes: 1 addition & 1 deletion mech_client/interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def interact( # pylint: disable=too-many-arguments,too-many-locals
:type sleep: float
:rtype: Any
"""
contract_address = query_agent_address(agent_id=agent_id)
contract_address = query_agent_address(agent_id=agent_id, timeout=timeout)
if contract_address is None:
raise ValueError(f"Agent with ID {agent_id} does not exist!")

Expand Down
5 changes: 3 additions & 2 deletions mech_client/subgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@
)


def query_agent_address(agent_id: int) -> Optional[str]:
def query_agent_address(agent_id: int, timeout: Optional[int] = None) -> Optional[str]:
"""
Query agent address from subgraph.
:param agent_id: The ID of the agent.
:param timeout: Timeout for the request.
:type agent_id: int
:return: The agent address if found, None otherwise.
:rtype: Optional[str]
"""
client = Client(transport=AIOHTTPTransport(url=MECH_SUBGRAPH_URL))
client = Client(transport=AIOHTTPTransport(url=MECH_SUBGRAPH_URL), execute_timeout=timeout or 30)
response = client.execute(
document=gql(
request_string=AGENT_QUERY_TEMPLATE.substitute({"agent_id": agent_id})
Expand Down

0 comments on commit d34c8f0

Please sign in to comment.