Skip to content

Commit

Permalink
fix: solved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixNicolaeBucsa committed Sep 22, 2023
2 parents ccecfb6 + e89caec commit 263714e
Show file tree
Hide file tree
Showing 17 changed files with 265 additions and 164 deletions.
4 changes: 2 additions & 2 deletions pages/apis/cosmpy/network-configurations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Network configurations.

## NetworkkConfigError Objects
## NetworkConfigError Objects

```py
class NetworkConfigError(RuntimeError)
Expand Down Expand Up @@ -92,7 +92,7 @@ fetch mainnet configuration

```py
@classmethod
def fetch_mainnet(cls) - >"NetworkConfig"
def fetch_mainnet(cls) -> "NetworkConfig"
```
Get the fetch mainnet

Expand Down
2 changes: 1 addition & 1 deletion pages/concepts/agent-services/why-agentverse.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Since there are pre-built agents templates and use cases available, _you do not

## Integration with wallets

_Agents have wallets_. This means agents can interact with the Fetch.ai ledger, send and receive transactions, query balances, and a lot more possibilities and use cases.
_uAgents have wallets_, this means agents can interact with the Fetch.ai ledger, send and receive transactions, query balances, and a lot more possibilities and use cases.

## More than a simple search and discovery platform

Expand Down
20 changes: 11 additions & 9 deletions pages/guides/agents/booking-demo.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ We can start by writing the code for our 2 protocols.
Let's start by defining the protocol for querying availability of tables at the restaurant:

1. First of all, we need to navigate towards the protocols folder: `cd protocols`
2. Let's then create a Python script named, and name it: `touch query.py`
2. Let's then create a Python script and name it by running: `touch query.py`
3. In the text editor application, we proceed and define the `table querying protocol`.
4. We now need to import necessary classes and define the _message data models_. Then, create an instance of the `Protocol` class and name it `query_proto`:

Expand Down Expand Up @@ -68,7 +68,7 @@ Let's start by defining the protocol for querying availability of tables at the
for (
num,
status,
) in ctx.storage._data.items() # pylint: disable=protected-access
) in ctx.storage._data.items()
if isinstance(num, int)
}

Expand Down Expand Up @@ -134,7 +134,7 @@ async def handle_query_request(ctx: Context, sender: str, msg: QueryTableRequest
for (
num,
status,
) in ctx.storage._data.items() # pylint: disable=protected-access
) in ctx.storage._data.items()
if isinstance(num, int)
}
available_tables = []
Expand All @@ -161,7 +161,7 @@ async def handle_get_total_queries(ctx: Context, sender: str, _msg: GetTotalQuer
We can now proceed by writing the booking protocol script for booking the table at the restaurant.

1. First of all, navigate towards the protocols folder: `cd protocols`
2. In here, let's create a Python script and name it: `touch book.py`
2. In here, let's create a Python script and name it by running: `touch book.py`
3. In the text editor application, we can proceed to define the **table booking protocol**. We need to import the necessary classes and define the _message data models_. In this case, the booking protocol consists of two message models: `BookTableRequest` and `BookTableResponse`. Then create an instance of the `Protocol` class and name it `book_proto`:

```py copy
Expand Down Expand Up @@ -193,7 +193,7 @@ We can now proceed by writing the booking protocol script for booking the table
for (
num,
status,
) in ctx.storage._data.items() # pylint: disable=protected-access
) in ctx.storage._data.items()
if isinstance(num, int)
}
table = tables[msg.table_number]
Expand Down Expand Up @@ -222,14 +222,16 @@ The overall script should look as follows:

```py copy filename="book.py"
from uagents import Context, Model, Protocol

from .query import TableStatus

class BookTableRequest(Model):
table_number: int
time_start: int
duration: int

class BookTableResponse(Model):
success: bool

book_proto = Protocol()
@book_proto.on_message(model=BookTableRequest, replies=BookTableResponse)
async def handle_book_request(ctx: Context, sender: str, msg: BookTableRequest):
Expand All @@ -238,7 +240,7 @@ async def handle_book_request(ctx: Context, sender: str, msg: BookTableRequest):
for (
num,
status,
) in ctx.storage._data.items() # pylint: disable=protected-access
) in ctx.storage._data.items()
if isinstance(num, int)
}
table = tables[msg.table_number]
Expand All @@ -255,11 +257,11 @@ async def handle_book_request(ctx: Context, sender: str, msg: BookTableRequest):
await ctx.send(sender, BookTableResponse(success=success))
```

### Restaurant uAgent
### Restaurant Agent

We are now ready to define our restaurant uAgent.

1. Let's now create a Python script in `booking_demo` folder, and name it: `touch restaurant.py`
1. Let's now create a Python script in `booking_demo` folder, and name it by running: `touch restaurant.py`
2. We then need to import the necessary classes from the `uagents` library and the two protocols we previously defined:

```py copy
Expand Down
168 changes: 84 additions & 84 deletions pages/guides/agents/cleaning-demo.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,93 @@ We can start by writing the code for our protocol.

The Cleaning Protocol is made up of two scripts: `__init__.py` and `models.py`.

#### Models

First, we need to define a `models` protocol which defines the structure and relationships of users, service types, providers, and availability within the cleaning service application. The defined models and their relationships will be used for data storage, retrieval, and manipulation throughout the application's logic.

1. First of all, navigate towards the cleaning directory and create a Python script for this task and name it by running: `touch models.py`
2. We then import the necessary classes from `enum` and `tortoise` libraries, and then define the different data models:

```py copy filename="models.py"
from enum import Enum

from tortoise import fields, models

class ServiceType(int, Enum):
FLOOR = 1
WINDOW = 2
LAUNDRY = 3
IRON = 4
BATHROOM = 5

class User(models.Model):
id = fields.IntField(pk=True)
name = fields.CharField(max_length=64)
address = fields.CharField(max_length=100)
created_at = fields.DatetimeField(auto_now_add=True)

class Service(models.Model):
id = fields.IntField(pk=True)
type = fields.IntEnumField(ServiceType)

class Provider(models.Model):
id = fields.IntField(pk=True)
name = fields.CharField(max_length=64)
location = fields.CharField(max_length=64)
created_at = fields.DatetimeField(auto_now_add=True)
availability = fields.ReverseRelation["Availability"]
services = fields.ManyToManyField("models.Service")
markup = fields.FloatField(default=1.1)

class Availability(models.Model):
id = fields.IntField(pk=True)
provider = fields.OneToOneField("models.Provider", related_name="availability")
max_distance = fields.IntField(default=10)
time_start = fields.DatetimeField()
time_end = fields.DatetimeField()
min_hourly_price = fields.FloatField(default=0.0)
```

We defined the following data models:

- `ServiceType` is an enumeration class that defines different types of cleaning services. Each service type is associated with an integer value. Service types include `FLOOR`, `WINDOW`, `LAUNDRY`, `IRON`, and `BATHROOM`.

- `User` is a model representing the users of the cleaning service. It takes in the following fields:
- `id`: Auto-incrementing integer field serving as the primary key.
- `name`: Character field with a maximum length of 64 for the user's name.
- `address`: Character field with a maximum length of 100 for the user's address.
- `created_at`: DateTime field automatically set to the current timestamp when the user is created.

- `Service` is model representing types of cleaning services. It takes in the following fields:
- `id`: Auto-incrementing integer field serving as the primary key.
- `type`: Enum field storing the ServiceType enumeration values.

- `Provider` is a model representing cleaning service providers. It considers the following fields:
- `id`: Auto-incrementing integer field serving as the primary key.
- `name`: Character field with a maximum length of 64 for the provider's name.
- `location`: Character field with a maximum length of 64 for the provider's location.
- `created_at`: DateTime field automatically set to the current timestamp when the provider is created.
- `availability`: Reverse relation to the `Availability` model.
- `services`: Many-to-many relationship with the `Service` model.
- `markup`: Float field representing the markup applied to service prices.

- `Availability` is a model representing the availability of a cleaning service provider. It considers the following fields:
- `id`: Auto-incrementing integer field serving as the primary key.
- `provider`: One-to-one relationship to the `Provider` model.
- `max_distance`: Integer field representing the maximum distance a provider can travel for services.
- `time_start`: DateTime field indicating the start time of availability.
- `time_end`: DateTime field indicating the end time of availability.
- `min_hourly_price`: Float field representing the minimum hourly price for services.

3. Save the script.

Now that we have defined the protocols for this application, we proceed by defining the user and cleaner agents.

#### **init**

First of all, let's define a protocol handling communication between a user requesting a cleaning service and a cleaning service provider.
Now let's define a protocol handling communication between a user requesting a cleaning service and a cleaning service provider.

1. The first step is creating a Python script for this task and name it: `touch __init__.py`
1. Inside the cleaning directory, create a Python script for this task and name it by running: `touch __init__.py`

2. Let's import the necessary classes from `datetime`, `typing`, `geopy.geocoders`, `geopy.distance`, `uagents`, and `.models`. Let's then define the message models and handlers for the service request, service response, service booking, and booking response using the `uagents` library. We then proceed and create a cleaning_proto object using the uagents **Protocol** class. We give it the name `cleaning` and the version `0.1.0`. This protocol will be used to define handlers and manage communication between agents using the defined message models:

Expand Down Expand Up @@ -296,88 +378,6 @@ async def handle_book_request(ctx: Context, sender: str, msg: ServiceBooking):
await ctx.send(sender, BookingResponse(success=success))
```

#### Models

We now continue and define a `models` protocol which defines the structure and relationships of users, service types, providers, and availability within the cleaning service application. The defined models and their relationships will be used for data storage, retrieval, and manipulation throughout the application's logic.

1. First of all, let's create a Python script for this task and name it: `touch models.py`
2. We then import the necessary classes from `enum` and `tortoise` libraries, and then define the different data models:

```py copy filename="models.py"
from enum import Enum

from tortoise import fields, models

class ServiceType(int, Enum):
FLOOR = 1
WINDOW = 2
LAUNDRY = 3
IRON = 4
BATHROOM = 5

class User(models.Model):
id = fields.IntField(pk=True)
name = fields.CharField(max_length=64)
address = fields.CharField(max_length=100)
created_at = fields.DatetimeField(auto_now_add=True)

class Service(models.Model):
id = fields.IntField(pk=True)
type = fields.IntEnumField(ServiceType)

class Provider(models.Model):
id = fields.IntField(pk=True)
name = fields.CharField(max_length=64)
location = fields.CharField(max_length=64)
created_at = fields.DatetimeField(auto_now_add=True)
availability = fields.ReverseRelation["Availability"]
services = fields.ManyToManyField("models.Service")
markup = fields.FloatField(default=1.1)

class Availability(models.Model):
id = fields.IntField(pk=True)
provider = fields.OneToOneField("models.Provider", related_name="availability")
max_distance = fields.IntField(default=10)
time_start = fields.DatetimeField()
time_end = fields.DatetimeField()
min_hourly_price = fields.FloatField(default=0.0)
```

We defined the following data models:

- `ServiceType` is an enumeration class that defines different types of cleaning services. Each service type is associated with an integer value. Service types include `FLOOR`, `WINDOW`, `LAUNDRY`, `IRON`, and `BATHROOM`.

- `User` is a model representing the users of the cleaning service. It takes in the following fields:
- `id`: Auto-incrementing integer field serving as the primary key.
- `name`: Character field with a maximum length of 64 for the user's name.
- `address`: Character field with a maximum length of 100 for the user's address.
- `created_at`: DateTime field automatically set to the current timestamp when the user is created.

- `Service` is model representing types of cleaning services. It takes in the following fields:
- `id`: Auto-incrementing integer field serving as the primary key.
- `type`: Enum field storing the ServiceType enumeration values.

- `Provider` is a model representing cleaning service providers. It considers the following fields:
- `id`: Auto-incrementing integer field serving as the primary key.
- `name`: Character field with a maximum length of 64 for the provider's name.
- `location`: Character field with a maximum length of 64 for the provider's location.
- `created_at`: DateTime field automatically set to the current timestamp when the provider is created.
- `availability`: Reverse relation to the `Availability` model.
- `services`: Many-to-many relationship with the `Service` model.
- `markup`: Float field representing the markup applied to service prices.

- `Availability` is a model representing the availability of a cleaning service provider. It considers the following fields:
- `id`: Auto-incrementing integer field serving as the primary key.
- `provider`: One-to-one relationship to the `Provider` model.
- `max_distance`: Integer field representing the maximum distance a provider can travel for services.
- `time_start`: DateTime field indicating the start time of availability.
- `time_end`: DateTime field indicating the end time of availability.
- `min_hourly_price`: Float field representing the minimum hourly price for services.

3. Save the script.

Now that we have defined the protocols for this application, we proceed by defining the user and cleaner agents.

### Cleaner agent

We are now ready to define our `cleaner` agent.
Expand Down
8 changes: 4 additions & 4 deletions pages/guides/agents/communicating-with-other-agents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ We want to start by introducing you to the concept of **local communication**. T

The first step to better understand how uAgents communicate is to introduce how 2 uAgents perform a local communication. Let’s consider a basic example in which two uAgents say hello to each other.

1. First of all, let's create a Python script for this task and name it: `touch agents_communication.py`
1. First of all, let's create a Python script for this task and name it by running: `touch agents_communication.py`

2. Then, let's import these necessary classes from the uagents library: `Agent`, `Context`, `Bureau`, and `Model` Let's then define the message structure for messages to be exchanged between the uAgents using the class `Model`. Then, we would need to create the uAgents, `alice` and `bob`, with name and seed parameters.

Expand Down Expand Up @@ -140,7 +140,7 @@ Let's start by defining the script for **alice**.

#### Alice

1. In `remote_agents_alice.py` script, we would need to import the necessary classes from the `uagents` (`Agent`, `Context`, and `Model`) and from `uagents.setup` (`fund_agent_if_low`). We then need to define the message structure for messages to be exchanged between agents using the class `Model`, as well as the `RECIPIENT_ADDRESS`. This is the address to which `alice` will send messages:
1. In `remote_agents_alice.py` script, we would need to import the necessary classes from the `uagents` (`Agent`, `Context`, and `Model`) and from `uagents.setup` (`fund_agent_if_low`). We then need to define the message structure for messages to be exchanged between agents using the class `Model`, as well as the `RECIPIENT_ADDRESS` (bob's address). Note that if you don't know bob's address yet, you can use **print(bob.address)** after defining agent bob to get this information. This is the address to which `alice` will send messages:

```py copy
from uagents import Agent, Context, Model
Expand Down Expand Up @@ -332,7 +332,7 @@ We make use of the **uAgents Remote Communication** guide above, but now, we spe

#### Alice

1. First of all, let's create a script for `alice`: `touch alice.py`
1. First of all, let's create a script for `alice` by running: `touch alice.py`

2. We need to import the necessary classes from `uagents` (`Agent`, `Context`, `Model`) and `uagents.setup` (`fund_agent_if_low`), and define the `Message` class for messages to be exchanged between our uAgents. We also need to generate a secure `SEED_PHRASE` (e.g., https://pypi.org/project/mnemonic/) and get the address of our agent, which is needed to register it to create a `Mailbox`, alongside a name (i.e., `alice` in this case). Following this, we would need to sign up at [Agentverse ↗️](https://agentverse.ai/) to get an `API key`:

Expand Down Expand Up @@ -420,7 +420,7 @@ if __name__ == "__main__":

#### Bob

1. Let's now create another Python script for **bob**: `touch bob.py`
1. Let's now create another Python script for **bob** by running: `touch bob.py`

2. We can now import the necessary classes from `uagents` and `uagents.setup`, and define the `Message` class for messages to be exchanged between our uAgents. We then need to define `ALICE_ADDRESS` by copying the address generated in the script for `alice` above, as well as generate a second `SEED_PHRASE` (e.g. https://pypi.org/project/mnemonic/), and get the address for our agent, which is needed to register it to create a `Mailbox`, alongside a name (i.e., `bob` in this case). Like for `alice`, head towards the [Agentverse ↗️](https://agentverse.ai/)️ to get the `API key` for `bob`:

Expand Down
Loading

0 comments on commit 263714e

Please sign in to comment.