Skip to content

Commit

Permalink
Merge pull request #51 from gizatechxyz/feature/giza_namespace
Browse files Browse the repository at this point in the history
add giza as a namespace package
  • Loading branch information
Gonmeso authored May 22, 2024
2 parents 1704bc1 + 9be1001 commit dc807c1
Show file tree
Hide file tree
Showing 34 changed files with 951 additions and 2,963 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/onpush.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:
poetry install --all-extras
- name: Lint with ruff
run: |
poetry run ruff giza_actions
poetry run ruff giza
- name: Pre-commit check
run: |
poetry run pre-commit run --all-files
- name: Testing
run: |
poetry run pytest --cov=giza_actions --cov-report term-missing
poetry run pytest --cov=giza.agents --cov-report term-missing
2 changes: 1 addition & 1 deletion .github/workflows/onrelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
poetry install
- name: Lint with ruff
run: |
poetry run ruff giza_actions
poetry run ruff giza
- name: Build dist
run: poetry build
- name: Publish a Python distribution to PyPI
Expand Down
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The extensible nature of Giza Agents allows developers to enshrine custom strate

## Where to start?

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

## Installation

Expand All @@ -23,10 +23,10 @@ $ source .env/bin/activate
$ .env/Scripts/activate
```

Now you’re ready to install ⚡Actions with the following command:
Now you’re ready to install ⚡Agents with the following command:

```bash
$ pip install giza-actions
$ pip install giza-agents
```

## Setup
Expand All @@ -49,12 +49,6 @@ 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 by executing the following command in your terminal:

```bash
$ giza workspaces create
```

## Usage

### Creating Agents
Expand Down Expand Up @@ -112,7 +106,7 @@ $ export <ACCOUNT NAME>_PASSPHRASE=<passphrase>
```
```python
from giza_actions.agent import Agent
from giza.agents import Agent
# Here we check for the passphrase in the environment
agent = Agent.from_id(id=1, contracts={"my_contract": "0x1234567890"})
Expand All @@ -131,7 +125,7 @@ with agent.execute() as contracts:
## Examples
Examples of how to use the Actions SDK can be found in the `examples` directory. Each example includes a README or a Notebook with detailed instructions on how to run the example.
Examples of how to use the Agents can be found in the `examples` directory. Each example includes a README or a Notebook with detailed instructions on how to run the example.
## Contributing
Expand Down
13 changes: 4 additions & 9 deletions examples/agents/action_agent.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import logging
import pprint
import numpy as np
from PIL import Image
from giza_actions.action import action
from giza_actions.agent import GizaAgent
from giza_actions.task import task
from giza.agents import GizaAgent

from prefect import get_run_logger

# Process the image
@task
def process_image(img):
img = np.resize(img, (28,28))
img = img.reshape(1,1,28,28)
Expand All @@ -19,17 +16,15 @@ def process_image(img):
return tensor

# 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 the Action
@action(log_prints=True)
# Create the execution function
def transmission():
logger = get_run_logger()
logger = logging.getLogger(__name__)
img_path = 'seven.png'
img = get_image(img_path)
img = process_image(img)
Expand Down
24 changes: 8 additions & 16 deletions examples/agents/mnist_agent_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
"\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 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",
"This tutorial can be thought of as the continuation of the previous tutorial [Verifiable MNIST Neural Network](https://docs.gizatech.xyz/tutorials/zkml/verifiable-mnist-neural-network) where we created a verifiable MNIST model ([notebook](https://github.com/gizatechxyz/giza-agents/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",
"3. giza-agents should be installed. You can install it by running `pip install giza-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 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",
"5. You must have an MNIST model deployed on Giza. You can follow the tutorial [Build a Verifiable Neural Network](https://docs.gizatech.xyz/tutorials/zkml/verifiable-mnist-neural-network) 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",
Expand All @@ -29,10 +29,10 @@
"Let's start by installing the required libraries.\n",
"\n",
"```bash\n",
"pip install giza-actions[agents]\n",
"pip install giza-agents\n",
"```\n",
"\n",
"This will install the `giza-actions` library along with the `agents` extra, which contains the necessary tools to create an AI Agent.\n",
"This will install the `giza-agents` library, which contains the necessary tools to create an AI Agent.\n",
"\n",
"## Creating an account\n",
"\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 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."
"Now that the agent is created we can start using it through the `giza-agents` 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 All @@ -121,9 +121,7 @@
"import numpy as np\n",
"from PIL import Image\n",
"\n",
"from giza_actions.agent import GizaAgent, AgentResult\n",
"from giza_actions.action import action\n",
"from giza_actions.task import task\n",
"from giza.agents import GizaAgent, AgentResult\n",
"\n",
"# Make sure to fill these in\n",
"MODEL_ID = ...\n",
Expand All @@ -146,7 +144,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](https://docs.gizatech.xyz/tutorials/zkml/verifiable-mnist-neural-network)."
]
},
{
Expand All @@ -156,7 +154,6 @@
"outputs": [],
"source": [
"# This function is for the previous MNIST tutorial\n",
"@task(name=\"Preprocess an image for the MNIST model.\")\n",
"def preprocess_image(image_path: str):\n",
" \"\"\"\n",
" Preprocess an image for the MNIST model.\n",
Expand Down Expand Up @@ -197,7 +194,6 @@
"metadata": {},
"outputs": [],
"source": [
"@task(name=\"Create a Giza agent for the MNIST model\")\n",
"def create_agent(model_id: int, version_id: int, chain: str, contract: str):\n",
" \"\"\"\n",
" Create a Giza agent for the MNIST model with MNIST \n",
Expand Down Expand Up @@ -225,7 +221,6 @@
"metadata": {},
"outputs": [],
"source": [
"@task(name=\"Predict the digit in an image.\")\n",
"def predict(agent: GizaAgent, image: np.ndarray):\n",
" \"\"\"\n",
" Predict the digit in an image.\n",
Expand Down Expand Up @@ -259,7 +254,6 @@
"metadata": {},
"outputs": [],
"source": [
"@task(name=\"Get the digit from the prediction.\")\n",
"def get_digit(prediction: AgentResult):\n",
" \"\"\"\n",
" Get the digit from the prediction.\n",
Expand Down Expand Up @@ -300,7 +294,6 @@
"metadata": {},
"outputs": [],
"source": [
"@task(name=\"Execute the MNIST to mint a new NFT.\")\n",
"def execute_contract(agent: GizaAgent, digit: int):\n",
" \"\"\"\n",
" Execute the MNIST contract with the predicted digit to mint a new NFT.\n",
Expand Down Expand Up @@ -330,7 +323,6 @@
"metadata": {},
"outputs": [],
"source": [
"@action(name=\"Mint an NFT with a prediction.\", log_prints=True)\n",
"def mint_nft_with_prediction():\n",
" # Preprocess the image\n",
" image = preprocess_image(\"seven.png\")\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/agents/read_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
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
from giza.agents import GizaAgent

MODEL_ID = ...
VERSION_ID = ...
Expand Down
16 changes: 8 additions & 8 deletions examples/agents/using_arbitrum.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
"\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",
"3. giza-agents should be installed. You can install it by running `pip install giza-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 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, Ape's framework, and provide multiple inputs, like `model-id`, `version-id`, `account name`, etc.\n",
"5. You must have an MNIST model deployed on Giza. You can follow the tutorial [Build a Verifiable Neural Network](https://docs.gizatech.xyz/tutorials/zkml/verifiable-mnist-neural-network) 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",
"Let's start by installing the required libraries.\n",
"\n",
"```bash\n",
"pip install giza-actions[agents]\n",
"pip install giza-agents\n",
"```\n",
"\n",
"This will install the `giza-actions` library along with the `agents` extra, which contains the necessary tools to create an AI Agent.\n",
"This will install the `giza-agents` library along with the `agents` extra, which contains the necessary tools to create an AI Agent.\n",
"\n",
"## Creating an account\n",
"\n",
Expand Down Expand Up @@ -174,13 +174,13 @@
"export <Account>_PASSPHRASE=your-passphrase\n",
"```\n",
"\n",
"If you are using it from a notebook, you will need to launch the notebook instance from an environment with the passphrase variable or set it in the code before importing `giza_actions`:\n",
"If you are using it from a notebook, you will need to launch the notebook instance from an environment with the passphrase variable or set it in the code before importing `giza.agents`:\n",
"\n",
"```python\n",
"import os\n",
"os.environ[\"<Account>_PASSPHRASE\"] = \"your-passphrase\"\n",
"\n",
"from giza_actions.agent import GizaAgent\n",
"from giza.agents import GizaAgent\n",
"...\n",
"```\n",
"\n",
Expand All @@ -197,7 +197,7 @@
"os.environ[\"<Account>_PASSPHRASE\"] = ...\n",
"\n",
"\n",
"from giza_actions.agent import GizaAgent\n",
"from giza.agents import GizaAgent\n",
"\n",
"MODEL_ID = ...\n",
"VERSION_ID = ...\n",
Expand Down
14 changes: 7 additions & 7 deletions examples/agents/using_polygon.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"\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. You can install it by running `pip install giza-actions`\n",
"3. giza-agents should be installed. You can install it by running `pip install giza-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 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",
"5. You must have a model deployed on Giza. You can follow the tutorial [Build a Verifiable Neural Network](https://docs.gizatech.xyz/tutorials/zkml/verifiable-mnist-neural-network) to deploy an 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 must be logged in to the Giza CLI or have an API KEY.\n",
"\n",
Expand All @@ -27,10 +27,10 @@
"Let's start by installing the required libraries.\n",
"\n",
"```bash\n",
"pip install giza-actions\n",
"pip install giza-agents\n",
"```\n",
"\n",
"This will install the `giza-actions` library, which contains the necessary tools to create an AI Agent.\n",
"This will install the `giza-agents` library, which contains the necessary tools to create an AI Agent.\n",
"\n",
"## Creating an account\n",
"\n",
Expand Down Expand Up @@ -169,13 +169,13 @@
"export <ACCOUNT>_PASSPHRASE=your-passphrase\n",
"```\n",
"\n",
"If you are using it from a notebook, you will need to launch the notebook instance from an environment with the passphrase variable or set it in the code before importing `giza_actions`:\n",
"If you are using it from a notebook, you will need to launch the notebook instance from an environment with the passphrase variable or set it in the code before importing `giza.agents`:\n",
"\n",
"```python\n",
"import os\n",
"os.environ[\"<ACCOUNT>_PASSPHRASE\"] = \"your-passphrase\"\n",
"\n",
"from giza_actions.agent import GizaAgent\n",
"from giza.agents import GizaAgent\n",
"...\n",
"```\n",
"\n",
Expand All @@ -192,7 +192,7 @@
"os.environ[\"<ACCOUNT>_PASSPHRASE\"] = ...\n",
"\n",
"\n",
"from giza_actions.agent import GizaAgent\n",
"from giza.agents import GizaAgent\n",
"\n",
"MODEL_ID = ...\n",
"VERSION_ID = ...\n",
Expand Down
15 changes: 4 additions & 11 deletions examples/ezkl/linear_regression/predict_action.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import time

import requests
from giza import API_HOST
from giza.client import DeploymentsClient
from giza.cli import API_HOST
from giza.cli.client import DeploymentsClient

from giza_actions.action import Action, action
from giza_actions.model import GizaModel
from giza_actions.task import task
from giza.agents.model import GizaModel

MODEL_ID = ... # The ID of the model
VERSION = ... # The version of the model
Expand All @@ -23,7 +21,6 @@ def get_deployment_id():
return client.list(MODEL_ID, VERSION).__root__[0].id


@task
def predict():
"""
Predict using the model and version for a linear regression model.
Expand All @@ -39,7 +36,6 @@ def predict():
return result, request_id


@task
def wait_for_proof(request_id):
"""
Wait for the proof associated with the request ID. For 240 seconds, it will attempt to retrieve the proof every 5 seconds.
Expand All @@ -65,12 +61,9 @@ def wait_for_proof(request_id):
time.sleep(5)


@action(log_prints=True)
def inference():
result, request_id = predict()
wait_for_proof(request_id)


if __name__ == "__main__":
action_deploy = Action(entrypoint=inference, name="ezkl-linear-regression")
action_deploy.serve(name="ezkl-linear-regression")
inference()
Loading

0 comments on commit dc807c1

Please sign in to comment.