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

added script to create metadata hash for the mech #3

Merged
merged 10 commits into from
Nov 22, 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
35 changes: 0 additions & 35 deletions .github/workflows/backend.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ local_config.json
mech.db

/.api_keys.json

.metadata_hash.json
47 changes: 47 additions & 0 deletions .metadata_hash.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"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": [
"claude-prediction-online"
],
"toolMetadata": {
"claude-prediction-offline": {
"name": "Claude Prediction Offline",
"description": "Makes a prediction using Claude",
"input": {
"type": "text",
"description": "The text to make a prediction on"
},
"output": {
"type": "object",
"description": "A JSON object containing the prediction and confidence",
"schema": {
"type": "object",
"properties": {
"requestId": {
"type": "integer",
"description": "Unique identifier for the request"
},
"result": {
"type": "string",
"description": "Result information in JSON format as a string",
"example": "{\n \"p_yes\": 0.6,\n \"p_no\": 0.4,\n \"confidence\": 0.8,\n \"info_utility\": 0.6\n}"
},
"prompt": {
"type": "string",
"description": "The prompt used to make the prediction."
}
},
"required": [
"requestId",
"result",
"prompt"
]
}
}
}
}
}
80 changes: 69 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,72 @@ Ensure your machine satisfies the requirements:

- You need 1 RPC for your agent instance for Gnosis.

## Setting up Mech metadata hash file

1. Copy over the sample from .metadata_hash.json.example. The example file is valid for a single tool.

```
cp .metadata_hash.json.example .metadata_hash.json
```

2. Define your top level key value pairs
| Name | Value Type | Description |
| :--- | :---: | :--- |
| Name | str | Name of your mech |
| Description | str | Description of your mech |
| inputFormat | str | Can leave it default |
| outputFormat | str | Can leave it default |
| image | str | Link to the imagerepresenting your mech |
| tools | List | List of AI tools your mech supports |
| toolMetadata | Dict | Provides more info on sprecific tools |

> [!IMPORTANT] \
> Each tool mentioned in `tools` should have a corresponding `key` in the `toolsMetadata`.

3. Define your key value pairs for each specific tools.

| Name | Value Type | Description |
| :----------- | :--------: | :-------------------------------------- |
| Name | str | Name of the AI tool |
| Description | str | Description of the AI tool |
| input | Dict | Contains the input schema of the tool |
| output | Dict | Contains the output schema of the tool |
| image | str | Link to the imagerepresenting your mech |
| tools | List | List of AI tools your mech supports |
| toolMetadata | Dict | Provides more info on sprecific tools |

> [!IMPORTANT] \
> Each field mentioned in `required` should have a corresponding `key` in the `properties`.

4. Define your key value pairs for the output schema

| Name | Value Type | Description |
| :--------- | :--------: | :----------------------------------------------------------- |
| type | str | Mentions the type of the schema |
| properties | Dict | Contains the required output data |
| required | List | Contains the list of fields required in the `properties` key |

5. Define your key value pairs for the properties field

| Name | Value Type | Description |
| :-------- | :--------: | :------------------------------------------------------------ |
| requestId | Dict | Contains the request id and it's description |
| result | Dict | Contains the result and it's description with an example |
| prompt | Dict | Contains the prompt used for the request and it's description |

## Setting up api keys file

1. Copy over the sample from .api_keys.json.example.

```
cp .api_keys.json.example .api_keys.json
```

2. Setup key value pairs for every AI tool your mech uses

- The name of the tool will be the `key` used in the file
- The value will be an array of valid API keys the tool can use

## Run the Service

1. Clone this repository:
Expand All @@ -53,9 +119,9 @@ Ensure your machine satisfies the requirements:
```
3. Run the quickstart:

```bash
python run_service.py
```
```bash
bash run_service.sh
```

When prompted, add the requested info, send funds to the prompted address and you're good to go!

Expand All @@ -71,14 +137,6 @@ Please confirm your password:
Creating the main wallet...
```

## Staking

The agent will need your answer on staking. If you plan to run it as a non staking agent, please answer _n_ to the question below. Otherwise, please answer _y_ and, consequently when prompted, fund your agent with the required number of bridged Olas in Optimism Chain.

```bash
Do you want to stake your service? (y/n):
```

### Notes:

- Staking is currently in a testing phase, so the number of trader agents that can be staked might be limited.
Expand Down
4 changes: 1 addition & 3 deletions operate/ledger/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@
"optimus_alpha": "0x88996bbdE7f982D93214881756840cE2c77C4992",
},
ChainType.ETHEREUM: {},
ChainType.BASE: {
"meme_alpha": "0x06702A05312091013FdB50C8b60B98ca30762931"
},
ChainType.BASE: {"meme_alpha": "0x06702A05312091013FdB50C8b60B98ca30762931"},
ChainType.CELO: {
"meme_alpha": "0xf39cd0eE4C502Df7D26F28cFAdd579724A3CFCe8",
},
Expand Down
4 changes: 2 additions & 2 deletions operate/services/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ def fund_service( # pylint: disable=too-many-arguments,too-many-locals
chain_id: str = "10",
) -> None:
"""Fund service if required."""
from_safe = False # hack
from_safe = False # hack
service = self.load_or_create(hash=hash)
chain_config = service.chain_configs[chain_id]
ledger_config = chain_config.ledger_config
Expand Down Expand Up @@ -1177,7 +1177,7 @@ def fund_service( # pylint: disable=too-many-arguments,too-many-locals
amount=int(to_transfer),
chain_type=ledger_config.chain,
rpc=rpc or ledger_config.rpc,
from_safe=False # hack
from_safe=False, # hack
)

def fund_service_erc20( # pylint: disable=too-many-arguments,too-many-locals
Expand Down
30 changes: 9 additions & 21 deletions operate/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ def try_update_runtime_params(
# "on_chain_service_id"
# ] = service_id

# service id not used tmp workaround
print(f"{service_id=}")

override["type"] = component_id.package_type.value
override["public_id"] = str(component_id.public_id)

Expand Down Expand Up @@ -471,21 +474,6 @@ def _build_docker(
(build / volume).mkdir(exist_ok=True)
_volumes.append(f"./{volume}:{mount}:Z")

# not needed and causes issues
# for node in deployment["services"]:
# if "abci" in node:
# deployment["services"][node]["volumes"].extend(_volumes)
# if (
# "SKILL_TRADER_ABCI_MODELS_PARAMS_ARGS_MECH_REQUEST_PRICE=0"
# in deployment["services"][node]["environment"]
# ):
# deployment["services"][node]["environment"].remove(
# "SKILL_TRADER_ABCI_MODELS_PARAMS_ARGS_MECH_REQUEST_PRICE=0"
# )
# deployment["services"][node]["environment"].append(
# "SKILL_TRADER_ABCI_MODELS_PARAMS_ARGS_MECH_REQUEST_PRICE=10000000000000000"
# )

with (build / DOCKER_COMPOSE_YAML).open("w", encoding="utf-8") as stream:
yaml_dump(data=deployment, stream=stream)

Expand Down Expand Up @@ -566,9 +554,9 @@ def _build_host(self, force: bool = True, chain_id: str = "100") -> None:
# Mech price patch.
agent_vars = json.loads(Path(build, "agent.json").read_text(encoding="utf-8"))
if "SKILL_TRADER_ABCI_MODELS_PARAMS_ARGS_MECH_REQUEST_PRICE" in agent_vars:
agent_vars["SKILL_TRADER_ABCI_MODELS_PARAMS_ARGS_MECH_REQUEST_PRICE"] = (
"10000000000000000"
)
agent_vars[
"SKILL_TRADER_ABCI_MODELS_PARAMS_ARGS_MECH_REQUEST_PRICE"
] = "10000000000000000"
Path(build, "agent.json").write_text(
json.dumps(agent_vars, indent=4),
encoding="utf-8",
Expand Down Expand Up @@ -806,9 +794,9 @@ def update_user_params_from_template(
) -> None:
"""Update user params from template."""
for chain, config in service_template["configurations"].items():
self.chain_configs[chain].chain_data.user_params = (
OnChainUserParams.from_json(dict(config))
)
self.chain_configs[
chain
].chain_data.user_params = OnChainUserParams.from_json(dict(config))

self.store()

Expand Down
1 change: 0 additions & 1 deletion run_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ def main() -> None:
# TODO: no way to update this atm after its provided, user is expected to update the file itself.
"API_KEYS": json.dumps(api_keys, separators=(',', ':')),
"AGENT_ID": str(mech_quickstart_config.agent_id),
# TODO this will be very unclear for the general user how to come up with
"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,
Expand Down
Loading
Loading