Skip to content

Commit

Permalink
Realign the examples in the documentation with the new source code (#361
Browse files Browse the repository at this point in the history
)

* WIP: Update doc examples

* WIP: Update doc examples

* Update doc examples
  • Loading branch information
harishmohanraj authored Oct 10, 2024
1 parent 0356661 commit 727e727
Show file tree
Hide file tree
Showing 16 changed files with 396 additions and 285 deletions.
4 changes: 2 additions & 2 deletions docs/docs/en/getting-started/images/chat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 24 additions & 19 deletions docs/docs/en/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ To get started, you need to install FastAgency. You can do this using `pip`, Pyt
Depending on the interface you choose, you'll need to import different modules. These imports set up the necessary components for your application:

=== "Console"
```python hl_lines="7"
{!> docs_src/getting_started/main_console.py [ln:1-7] !}
```python hl_lines="8"
{!> docs_src/getting_started/main_console.py [ln:1-8] !}
```

For Console applications, import `ConsoleUI` to handle command-line input and output.

=== "Mesop"
```python hl_lines="7"
{!> docs_src/getting_started/main_mesop.py [ln:1-7] !}
```python hl_lines="8"
{!> docs_src/getting_started/main_mesop.py [ln:1-8] !}
```

For Mesop applications, import `MesopUI` to integrate with the Mesop web interface.
Expand All @@ -137,7 +137,7 @@ Depending on the interface you choose, you'll need to import different modules.
You need to define the workflow that your application will use. This is where you specify how the agents interact and what they do. Here's a simple example of a workflow definition:

```python
{! docs_src/getting_started/main_console.py [ln:9-45] !}
{! docs_src/getting_started/main_console.py [ln:9-53] !}
```

This code snippet sets up a simple learning chat between a student and a teacher. You define the agents and how they should interact, specifying how the conversation should be summarized.
Expand All @@ -148,14 +148,14 @@ Next, define your FastAgency application. This ties together your workflow and t

=== "Console"
```python hl_lines="1"
{!> docs_src/getting_started/main_console.py [ln:47] !}
{!> docs_src/getting_started/main_console.py [ln:55] !}
```

For Console applications, use `ConsoleUI` to handle user interaction via the command line.

=== "Mesop"
```python hl_lines="1"
{!> docs_src/getting_started/main_mesop.py [ln:47] !}
{!> docs_src/getting_started/main_mesop.py [ln:55] !}
```

For Mesop applications, use `MesopUI` to enable web-based interactions.
Expand Down Expand Up @@ -197,7 +197,7 @@ Once everything is set up, you can run your FastAgency application using the fol
fastagency run
```

However, the preferred way of running Mesop application is a Python WSGI HTTP Server such as [Gunicorn](https://gunicorn.org/). First,
However, the preferred way to run the Mesop application is using a Python WSGI HTTP server like [Gunicorn](https://gunicorn.org/). First,
you need to install it using package manager such as `pip`:
```
pip install gunicorn
Expand Down Expand Up @@ -226,26 +226,31 @@ The output will vary based on the interface:
│ │
╰─────────────────────────────╯

╭─ FastAgency -> user [text_input] ────────────────────────────────────────────╮
╭─ FastAgency -> user [workflow_started] ──────────────────────────────────────╮
│ │
│ Starting a new workflow 'simple_learning' with the following │
│ description: │
│ │
│ Student and teacher learning chat │
│ { │
│ "name": "simple_learning", │
│ "description": "Student and teacher │
│ learning chat", │
│ "params": {} │
│ } │
╰──────────────────────────────────────────────────────────────────────────────╯

╭─ Workflow -> User [text_input] ──────────────────────────────────────────────╮
│ │
Please enter an
initial message:
I can help you learn about geometry. What subject you would like to
explore?:
╰──────────────────────────────────────────────────────────────────────────────╯
```

For Console applications, you will see a command-line prompt where you can enter the initial message and interact with your workflow.

=== "Mesop"
```console
[2024-10-01 16:18:59 +0000] [20390] [INFO] Starting gunicorn 23.0.0
[2024-10-01 16:18:59 +0000] [20390] [INFO] Listening at: http://127.0.0.1:8000 (20390)
[2024-10-01 16:18:59 +0000] [20390] [INFO] Using worker: sync
[2024-10-01 16:18:59 +0000] [20391] [INFO] Booting worker with pid: 20391
[2024-10-10 13:19:18 +0530] [23635] [INFO] Starting gunicorn 23.0.0
[2024-10-10 13:19:18 +0530] [23635] [INFO] Listening at: http://127.0.0.1:8000 (23635)
[2024-10-10 13:19:18 +0530] [23635] [INFO] Using worker: sync
[2024-10-10 13:19:18 +0530] [23645] [INFO] Booting worker with pid: 23645
```

![Initial message](./images/chat.png)
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/en/tutorial/giphy/images/gifs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/docs/en/tutorial/giphy/images/initial_message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/docs/en/tutorial/giphy/images/scraped_info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/docs/en/tutorial/giphy/images/scraping1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/docs/en/tutorial/giphy/images/scraping2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions docs/docs/en/tutorial/giphy/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ The following lines shows hot to initializes the Giphy API by loading the OpenAP

Also, we configure the **Giphy API** with the __*GIPHY_API_KEY*__ using __*set_security_params*__ to authenticate our requests.
```python
{! docs_src/tutorial/giphy/main.py [ln:26-30] !}
{! docs_src/tutorial/giphy/main.py [ln:25-29] !}
```

For more information, visit [**API Integration User Guide**](../../user-guide/api){target="_blank"}.
Expand All @@ -105,14 +105,14 @@ For more information, visit [**API Integration User Guide**](../../user-guide/ap
Here, we initialize a new workflow using ***AutoGenWorkflows()*** and register it under the name ***"giphy_and_websurfer"***. The ***@wf.register*** decorator registers the function to handle chat flow with security enabled, combining both GiphyAgent and WebSurferAgent.

```python
{! docs_src/tutorial/giphy/main.py [ln:59-62] !}
{! docs_src/tutorial/giphy/main.py [ln:58-61] !}
```

### Interaction with the user
This is a core function used by the **GiphyAgent** to either present the task result or ask a follow-up question to the user. The message is wrapped in a ***TextInput*** object, and then ***ui.process_message()*** sends it for user interaction.

```python
{! docs_src/tutorial/giphy/main.py [ln:66-77] !}
{! docs_src/tutorial/giphy/main.py [ln:65-76] !}
```

### Creating the Giphy and WebSurfer Agents
Expand All @@ -121,20 +121,20 @@ This is a core function used by the **GiphyAgent** to either present the task re
- **WebSurferAgent**: The ***WebSurferAgent*** is responsible for scraping web content and passes the retrieved data to the **GiphyAgent**. It’s configured with a summarizer to condense web content, which is useful when presenting concise data to the user. For more information, visit [**WebSurfer User Guide**](../../user-guide/runtimes/autogen/websurfer){target="_blank"}.

```python
{! docs_src/tutorial/giphy/main.py [ln:79-93] !}
{! docs_src/tutorial/giphy/main.py [ln:78-92] !}
```

### Registering Functions

The function ***present_completed_task_or_ask_question*** is registered to allow the **GiphyAgent** to ask questions or present completed tasks after receiving data from the **WebSurferAgent**.

```python
{! docs_src/tutorial/giphy/main.py [ln:95-102] !}
{! docs_src/tutorial/giphy/main.py [ln:94-101] !}
```

We specify which Giphy API functions can be used by the **GiphyAgent**: *random_gif*, *search_gifs*, and *trending_gifs*. These functions allow the agent to generate GIFs based on user input or trending content.
```python
{! docs_src/tutorial/giphy/main.py [ln:104-110] !}
{! docs_src/tutorial/giphy/main.py [ln:103-109] !}
```

### Initiating the Chat
Expand All @@ -144,15 +144,15 @@ We initiate the conversation between the user, **WebSurferAgent**, and **GiphyAg
Once the conversation ends, the summary is returned to the user, wrapping up the session.

```python
{! docs_src/tutorial/giphy/main.py [ln:112-119] !}
{! docs_src/tutorial/giphy/main.py [ln:118-125] !}
```

### Starting the Application

The FastAgency app is created, using the registered workflows (***wf***) and web-based user interface (***MesopUI***). This makes the conversation between agents and the user interactive.

```python
{! docs_src/tutorial/giphy/main.py [ln:122] !}
{! docs_src/tutorial/giphy/main.py [ln:128] !}
```

For more information, visit [**Mesop User Guide**](../../user-guide/ui/mesop/basics){target="_blank"}.
Expand Down
Loading

0 comments on commit 727e727

Please sign in to comment.