Skip to content

Commit

Permalink
Merge pull request #40 from shyamjayakannan/fixed_typos
Browse files Browse the repository at this point in the history
typos fixed
  • Loading branch information
Gonmeso authored Apr 22, 2024
2 parents 64e2167 + e55ba66 commit 7224e86
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 102 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The Actions SDK is a Python library designed to facilitate the development of ZK

## Where to start?

Check out our extensive [documentation](https://actions.gizatech.xyz/welcome/giza-actions-sdk) to understand concepts and follow how-to-guides.
Check out our extensive [documentation](https://actions.gizatech.xyz/welcome/giza-actions-sdk) to understand the concepts and follow how-to-guides.

## Installation

Expand Down Expand Up @@ -47,7 +47,7 @@ Optional: you can create an API Key for your user in order to not regenerate you
$ giza users create-api-key
```

To create Actions Runs you will need a Giza Workspace, create it executing the following command in your terminal:
To create Actions Runs you will need a Giza Workspace, create it by executing the following command in your terminal:

```bash
$ giza workspaces create
Expand Down Expand Up @@ -113,9 +113,9 @@ Running this script will do two things:

### Creating Agents

Agents are the entities that interact with the Giza Platform to handle predictions verification and interacting with Smart Contracts. They are responsible for wating until the proof of the prediction is available and verified, and then handling the interaction with the contract.
Agents are the entities that interact with the Giza Platform to handle verification of predictions and interactions with Smart Contracts. They are responsible for wating until the proof of the prediction is available and verified, and then handling the interaction with the contract.

To create the agent, you will first need to create locally an [ape](https://apeworx.io/framework/) account:
To create the agent, you will first need to locally create an [ape](https://apeworx.io/framework/) account:

```bash
$ ape accounts generate <account name>
Expand Down Expand Up @@ -159,7 +159,7 @@ Enter the account name: my_account
}
```
Now to interact with the agent and the contract wou will need to export the passphrase of the account to the environment. The variable name should be `<ACCOUNT NAME>_PASSPHRASE` all in caps. Make sure to keep this secret:
Now, to interact with the agent and the contract, wou will need to export the passphrase of the account to the environment. The variable name should be `<ACCOUNT NAME>_PASSPHRASE`, all in caps. Make sure to keep this secret:
```bash
$ export <ACCOUNT NAME>_PASSPHRASE=<passphrase>
Expand All @@ -176,7 +176,7 @@ result = agent.predict(data={"input": "data"})
# Handle the contracts
with agent.execute() as contracts:
# Wait for the verification and the execute the contract
# Wait for the verification and then execute the contract
contract_result = contracts.my_contract.function(result.value)
# Do anything with the result
Expand Down
8 changes: 4 additions & 4 deletions examples/agents/action_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@

from prefect import get_run_logger

# Process image
# Process the image
@task
def process_image(img):
img = np.resize(img, (28,28))
img = img.reshape(1,1,28,28)
img = img/255.0
print(img.shape)
# For now, we will just use a small tensor as input to a single layer softmax. We will change this when the PoC works
# For now, we will just use a small tensor as input to a single-layer softmax. We will change this when the PoC works
tensor = np.random.rand(1,3)
return tensor

# Get image
# Get the image
@task
def get_image(path):
with Image.open(path) as img:
img = img.convert('L')
img = np.array(img)
return img

# Create Action
# Create the Action
@action(log_prints=True)
def transmission():
logger = get_run_logger()
Expand Down
58 changes: 29 additions & 29 deletions examples/agents/mnist_agent_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
"\n",
"Agents serve as intermediaries between users and Smart Contracts, facilitating seamless interaction with verifiable ML models and executing associated contracts. They handle the verification of proofs, ensuring the integrity and authenticity of data used in contract execution.\n",
"\n",
"In this notebook, we will create an AI Agent to mint a MNIST NFT. Using an existing MNIST endpoint, we will perfomr a prediction on the MNIST dataset and mint an NFT based on the prediction.\n",
"In this notebook, we will create an AI Agent to mint an MNIST NFT. Using an existing MNIST endpoint, we will perform a prediction on the MNIST dataset and mint an NFT based on the prediction.\n",
"\n",
"This tutorial can be thought as the continuation of the previous tutorial [Build a Verifiable Neural Network with Giza Actions](https://actions.gizatech.xyz/tutorials/build-a-verifiable-neural-network-with-giza-actions) where we created a verifiable MNIST model ([notebook](https://github.com/gizatechxyz/actions-sdk/blob/main/examples/verifiable_mnist/verifiable_mnist.ipynb)).\n",
"This tutorial can be thought of as the continuation of the previous tutorial [Build a Verifiable Neural Network with Giza Actions](https://actions.gizatech.xyz/tutorials/build-a-verifiable-neural-network-with-giza-actions) where we created a verifiable MNIST model ([notebook](https://github.com/gizatechxyz/actions-sdk/blob/main/examples/verifiable_mnist/verifiable_mnist.ipynb)).\n",
"\n",
"## Before you begin\n",
"\n",
"1. Python 3.11 or later must be installed on your machine\n",
"2. Giza CLI must be installed on your machine. You can install it by running `pip install giza-cli`\n",
"3. Actions-SDK should be installed with the extra `agents`. You can install it by running `pip install giza-actions[agents]`\n",
"4. You must have an active Giza account. If you don't have one, you can create one [here](https://cli.gizatech.xyz/examples/basic).\n",
"5. You must have a MNIST model deployed on Giza. You can follow the tutorial [Build a Verifiable Neural Network with Giza Actions](https://actions.gizatech.xyz/tutorials/build-a-verifiable-neural-network-with-giza-actions) to deploy a MNIST model on Giza.\n",
"6. During the tutorial, you will need to interact with the Giza CLI, Ape's framework, and provide multiple inputs, like `model-id`, `version-id`, `account name`, etc.\n",
"7. You have to be logged in to the Giza CLI or have an API KEY.\n",
"5. You must have an MNIST model deployed on Giza. You can follow the tutorial [Build a Verifiable Neural Network with Giza Actions](https://actions.gizatech.xyz/tutorials/build-a-verifiable-neural-network-with-giza-actions) to deploy an MNIST model on Giza.\n",
"6. During the tutorial, you will need to interact with the Giza CLI, and Ape's framework, and provide multiple inputs, like `model-id`, `version-id`, `account name`, etc.\n",
"7. You must be logged in to the Giza CLI or have an API KEY.\n",
"\n",
"## Installing the required libraries\n",
"\n",
Expand All @@ -48,25 +48,25 @@
"```\n",
"\n",
"This will create a new account under `$HOME/.ape/accounts` using the keyfile structure from the [eth-keyfile library](https://github.com/ethereum/eth-keyfile)\n",
", for more information on the account management, you can refer to the [Ape's framework documentation](https://docs.apeworx.io/ape/stable/userguides/accounts.html#keyfile-accounts).\n",
". For more information on account management, you can refer to the [Ape's framework documentation](https://docs.apeworx.io/ape/stable/userguides/accounts.html#keyfile-accounts).\n",
"\n",
"In this account generation we will be prompted to enter a passphrase to encrypt the account, this passphrase will be used to unlock the account when needed, so **make sure to keep it safe**.\n",
"During account generation we will be prompted to enter a passphrase to encrypt the account, which will be used to unlock the said account when needed, so **make sure to keep it safe**.\n",
"\n",
"We encourage the creation of a new account for each agent, as it will allow you to manage the agent's permissions and access control more effectively, but importing accounts is also possible.\n",
"\n",
"## Funding the account\n",
"\n",
"Before we can create an AI Agent, we need to fund the account with some ETH. You can do this by sending some ETH to the account address generated in the previous step.\n",
"\n",
"In this case we will use Sepolia testnet, you can get some testnet ETH from a faucet like [Alchemy Sepolia Faucet](https://www.alchemy.com/faucets/ethereum-sepolia) or [LearnWeb3 Faucet](https://learnweb3.io/faucets/sepolia/). This faucets will ask for security meassures to make sure that you are not a bot like having a specific amount of ETH in mainnet or a Github account. There are many faucets available, you can choose the one that suits you the best.\n",
"In this case, we will use Sepolia testnet, you can get some testnet ETH from a faucet like [Alchemy Sepolia Faucet](https://www.alchemy.com/faucets/ethereum-sepolia) or [LearnWeb3 Faucet](https://learnweb3.io/faucets/sepolia/). These faucets will ask for security measures to make sure that you are not a bot (by checking whether you have a specific amount of ETH in the mainnet or a GitHub account, for example). There are many faucets available and you are free to choose the one that suits you the best.\n",
"\n",
"Once, we can recieve the testnet ETH and we have a funded account, we can proceed to create an AI Agent.\n",
"Once the testnet ETH have been received and the account has been funded, we can proceed with the creation of an AI Agent.\n",
"\n",
"![account](img/account.png)\n",
"\n",
"## Creating an AI Agent\n",
"\n",
"Now that we have a funded account, we can create an AI Agent. We can do this by running the following command:\n",
"Now that we have a funded account, we can create an AI Agent. This can be done by running the following command:\n",
"\n",
"```bash\n",
"giza agents create --model-id <model-id> --version-id <version-id> --name <agent name> --description <agent description>\n",
Expand All @@ -76,7 +76,7 @@
"giza agents create --endpoint-id <endpoint-id> --name <agent name> --description <agent description>\n",
"```\n",
"\n",
"This command will prompt you to choose the account you want to use with the agent, once you select the account, the agent will be created and you will receive the agent id. The output will look like this:\n",
"This command will prompt you to choose the account you want to use with the agent. Once you select the account, the agent will be created and you will receive the agent id. The output will look like this:\n",
"\n",
"```console\n",
"[giza][2024-04-10 11:50:24.005] Creating agent ✅\n",
Expand Down Expand Up @@ -108,7 +108,7 @@
"\n",
"## How to use the AI Agent\n",
"\n",
"Now that the agent is created we can start using it through `giza-actions` library. As we will be using the agent to mint a MNIST NFT, we will need to provide the MNIST image to the agent and preprocess it before sending it to the model.\n"
"Now that the agent is created we can start using it through the `giza-actions` library. As we will be using the agent to mint an MNIST NFT, we will need to provide the MNIST image to the agent and preprocess it before sending it to the model."
]
},
{
Expand Down Expand Up @@ -146,7 +146,7 @@
"* Access the prediction result\n",
"* Mint an NFT based on the prediction result\n",
"\n",
"To load and preprocess the image we can use the function that we already created in the previous tutorial [Build a Verifiable Neural Network with Giza Actions](https://actions.gizatech.xyz/tutorials/build-a-verifiable-neural-network-with-giza-actions)."
"To load and preprocess the image, we can use the function that we already created in the previous tutorial [Build a Verifiable Neural Network with Giza Actions](https://actions.gizatech.xyz/tutorials/build-a-verifiable-neural-network-with-giza-actions)."
]
},
{
Expand Down Expand Up @@ -181,7 +181,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, we will create a function to create an instance of the agent. The agent is an exttension of the `GizaModel` class, so we can execute the `predict` as if we were using a model, but the agents needs more information:\n",
"Now, we will create a function to create an instance of the agent. The agent is an extension of the `GizaModel` class, so we can execute `predict` as if we were using a model, but the agents needs more information:\n",
"\n",
"* chain: The chain where the contract and account are deployed\n",
"* contracts: This is a dictionary in the form of `{\"contract_alias\": \"contract_address\"}` that contains the contract alias and address.\n",
Expand Down Expand Up @@ -248,9 +248,9 @@
"source": [
"Once we have the result, we need to access it. The `AgentResult` object contains the `value` attribute that contains the prediction result. In this case, the prediction result is a number from 0 to 9 that represents the digit that the model predicted.\n",
"\n",
"When we access the value, the execution will be blocked until the proof of the prediction has been created and once created it is verified. If the proof is not valid, the execution will raise an exception.\n",
"When we access the value, the execution will be blocked until the proof of the prediction has been created and verified. If the proof is not valid, the execution will raise an exception.\n",
"\n",
"This task is more for didactic purposes, to showcase in the workspaces the time that it can take to verify the proof. In a real scenario, you can use the `AgentResult` value directl in any other task."
"This task is more for didactic purposes, to showcase in the workspaces the time that it takes to verify the proof. In a real scenario, you can use the `AgentResult` value directly in any other task."
]
},
{
Expand Down Expand Up @@ -278,14 +278,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally, we will create a task to mint an NFT based on the prediction result. This task will use the prediction result to mint an NFT with the image of the MNIST digit predicted.\n",
"Finally, we will create a task to mint an NFT based on the predicted result. This task will use the result to mint an NFT with the image of the MNIST digit predicted.\n",
"\n",
"To execute the contract we have the `GizaAgent.execute` context that will yield all the initialized contracts and the agent instance. This context will be used to execute the contract as it handles all the connections to the nodes, networks and contracts.\n",
"To execute the contract, we have the `GizaAgent.execute` context that will yield all the initialized contracts and the agent instance. This context will be used to execute the contract as it handles all the connections to the nodes, networks and contracts.\n",
"\n",
"In our instanciation of the agent we added an `mnist` alias to access the contract to ease its use. For example:\n",
"In our instantiation of the agent, we added an `mnist` alias to access the contract to ease its use. For example:\n",
"\n",
"```python\n",
"# A context is created that yields alll the contracts used in the agent\n",
"# A context is created that yields all the contracts used in the agent\n",
"with agent.execute() as contracts:\n",
" # This is how we access the contract\n",
" contracs.mnist\n",
Expand Down Expand Up @@ -332,15 +332,15 @@
"source": [
"@action(name=\"Mint an NFT with a prediction.\", log_prints=True)\n",
"def mint_nft_with_prediction():\n",
" # Preprocess image\n",
" # Preprocess the image\n",
" image = preprocess_image(\"seven.png\")\n",
" # Create Giza agent\n",
" # Create the Giza agent\n",
" agent = create_agent(MODEL_ID, VERSION_ID, CHAIN, MNIST_CONTRACT)\n",
" # Predict digit\n",
" # Predict the digit\n",
" prediction = predict(agent, image)\n",
" # Get digit\n",
" # Get the digit\n",
" digit = get_digit(prediction)\n",
" # Execute contract\n",
" # Execute the contract\n",
" result = execute_contract(agent, digit)\n",
" pprint.pprint(result)\n"
]
Expand All @@ -349,7 +349,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Remember that we should have kept the passphrase in a safe place? Now it is time to use it. For learning purposes we will use the passphrase in the code, but in a real scenario, you should keep it safe and not hardcode it in the code."
"Remember the passphrase that had to be safely kept? It is now time to use it. For the purpose of learning, we will use the passphrase in the code as an example, but in a real scenario, you should keep it safe and not hardcode it."
]
},
{
Expand All @@ -367,7 +367,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Now lets execute the action."
"Now let's execute the action."
]
},
{
Expand All @@ -385,9 +385,9 @@
"source": [
"## What we have learned\n",
"\n",
"In this tutorial, we learned how to create an AI Agent to mint a MNIST NFT. We created an AI Agent using Ape's framework and interacted with the agent to mint an NFT based on the prediction result of a MNIST image.\n",
"In this tutorial, we learned how to create an AI Agent to mint an MNIST NFT. We created an AI Agent using Ape's framework and interacted with it to mint an NFT based on the predicted result of an MNIST image.\n",
"\n",
"We learned how to load and preprocess the MNIST image, create an instance of the agent, predict the MNIST image using the agent, access the prediction result, and mint an NFT based on the prediction result."
"We learned how to load and preprocess the MNIST image, create an instance of the agent, predict the MNIST image using the agent, access the predicted result, and mint an NFT based on the result."
]
}
],
Expand Down
12 changes: 6 additions & 6 deletions examples/agents/read_contracts.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
"""
For this to work we need to have the PASSPHRASE as an environment variable
For this to work, we need to have the PASSPHRASE as an environment variable
This variable should have the form of "{ACCOUNT_ALIAS}_PASSPHRASE={PASSPHRASE}"
For example, if the ACCOUNT_ALIAS is "sepolia", then the environment variable should be "SEPOLIA_PASSPHRASE"
This is because the GizaAgent will look for the environment variable "{ACCOUNT_ALIAS}_PASSPHRASE" to allow auto signing
In this example we instantiate the agent with the model id, version id, and the addresses of the contracts we want to interact with.
In this example, we instantiate the agent with the model id, version id, and the addresses of the contracts we want to interact with.
The contracts are stored in a dictionary where the key is the contract name and the value is the contract address.
We also specify the chain we want to interact with and the account alias we want to use to sign transactions, in this case "sepolia".
We also specify the chain we want to interact with and the account alias we want to use to sign transactions, which, in this case is "sepolia".
To interact with the contracts we use the execute method of the agent in a `with` block, then the contracts will be available using the dot notation.
For example, our agent has two contracts, "mnist" and "token", so we can access them using `contracts.mnist` and `contracts.token` respectively.
To interact with the contracts, we use the execute method of the agent in a `with` block, so that the contracts will be available using the dot notation.
For example, if our agent has two contracts, "mnist" and "token", then we can access them using `contracts.mnist` and `contracts.token`, respectively.
In this example we call the `name` method of the contracts, which is a method that returns the name of the contract, and we print the result but we could execute any function of a contract in the same way.
In this example, we call the `name` method of the contracts, which is a method that returns the name of the contract, and then we print the result. But we could execute any function of a contract in the same way.
"""

from giza_actions.agent import GizaAgent
Expand Down
Loading

0 comments on commit 7224e86

Please sign in to comment.