From c101f1d7f778da8b20daeb746a933d175367cc5f Mon Sep 17 00:00:00 2001 From: Robert Jambrecic Date: Mon, 11 Nov 2024 10:09:11 +0000 Subject: [PATCH 01/12] wip --- docs/docs/en/tutorials/whatsapp/index.md | 44 +++++++++++++++++++----- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/docs/docs/en/tutorials/whatsapp/index.md b/docs/docs/en/tutorials/whatsapp/index.md index 3fbd4f7f..089ceb18 100644 --- a/docs/docs/en/tutorials/whatsapp/index.md +++ b/docs/docs/en/tutorials/whatsapp/index.md @@ -22,20 +22,48 @@ We will walk through setting up each agent, handling API security, and creating Let’s dive into creating a powerful interactive agent system with **FastAgency**! +## Project setup -## Installation and API Key Setup +We **strongly recommend** using [**Cookiecutter**](../cookiecutter/index.md) for setting up the project. It creates the project folder structure, default workflow, automatically installs all the necessary requirements, and creates a [devcontainer](https://code.visualstudio.com/docs/devcontainers/containers){target="_blank"} that can be used with [Visual Studio Code](https://code.visualstudio.com/){target="_blank"} for development. -Before we dive into building our agents, let’s go over the necessary setup. We will guide you through installing the **FastAgency** framework and obtaining the API key needed for the **Infobip WhatsApp API** integration. +You could also use virtual environment managers such as [venv](https://docs.python.org/3/library/venv.html){target="_blank"}, and a Python package manager, such as [pip](https://en.wikipedia.org/wiki/Pip_(package_manager)). -### Installing FastAgency -To get started, you need to install FastAgency with OpenAPI submodule. You can do this using `pip`, Python's package installer. +{! docs/en/user-guide/cookiecutter/index.md[ln:6-16] !} -```bash -pip install "fastagency[autogen,mesop,openapi]" -``` +3. Depending on the type of the project, choose the appropriate option in step 3: + + ```console + [1/4] project_name (My FastAgency App): + [2/4] project_slug (my_fastagency_app): + [3/4] Select app_type + 1 - fastapi+mesop + 2 - mesop + 3 - nats+fastapi+mesop + Choose from [1/2/3] (1): 2 + [4/4] Select python_version + 1 - 3.12 + 2 - 3.11 + 3 - 3.10 + Choose from [1/2/3] (1): + ``` + + This command installs FastAgency with support for both the Console and Mesop interfaces for AutoGen workflows. + + +4. Executing the `cookiecutter` command will create the following file structure: + + ```console + {!> docs_src/getting_started/mesop/folder_structure.txt !} + ``` + +{! docs/en/user-guide/cookiecutter/index.md[ln:88-129] !} + + +!!! info + If you used a different `project_slug` than the default `my_fastagency_app` this will be reflected in the project module naming. Keep this in mind when running the commands further in this guide (in [Run Application](#run-application)), you will need to replace `my_fastagency_app` with your `project_slug` name. +----- -Alternatively, you can use [**Cookiecutter**](../../user-guide/cookiecutter/index.md), which is the preferred method. Cookiecutter creates the project folder structure, default workflow, automatically installs all the necessary requirements, and creates a [devcontainer](https://code.visualstudio.com/docs/devcontainers/containers){target="_blank"} that can be used with [Visual Studio Code](https://code.visualstudio.com/){target="_blank"}. ### API Key Setup [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer/WebSurferAgent.md) requires an **Bing Web Search** API key and **WhatsAppAgent** requires an API key to interact with Infobip's WhatsApp service. Follow these steps to create your API keys: From dfbb43910bb4d75478417e646ef5685607cbab7c Mon Sep 17 00:00:00 2001 From: Robert Jambrecic Date: Mon, 11 Nov 2024 11:05:55 +0000 Subject: [PATCH 02/12] wip --- docs/docs/en/tutorials/whatsapp/index.md | 25 ++++++++++++++++++++++-- docs/docs_src/tutorials/whatsapp/main.py | 6 +----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/docs/docs/en/tutorials/whatsapp/index.md b/docs/docs/en/tutorials/whatsapp/index.md index 089ceb18..8e038233 100644 --- a/docs/docs/en/tutorials/whatsapp/index.md +++ b/docs/docs/en/tutorials/whatsapp/index.md @@ -121,11 +121,32 @@ You can set the API keys in your terminal as an environment variable: ## Complete Application Code +### Complete Workflow Code +You need to define the workflow that your application will use. This is where you specify how the agents interact and what they do. +=== "Cookiecutter" + Workflow will be generated within the `my_fastagency_app/workflow.py` folder. You will need to replace the existing `workflow.py` with the code bellow. +=== "env + pip" + Create `workflow.py` and paste the code bellow inside. + +
+workflow.py +```python +{! docs_src/tutorials/whatsapp/main.py [ln:1-127] !} +``` +
+ +### Deployment Code +=== "Cookiecutter" + Deployment files will be generated under `my_fastagency_app/deployment` folder. You will need to replace the existing `main.py` with the code bellow. +=== "env + pip" + Create `deployment/main.py` and paste the code bellow inside. +
main.py ```python -{! docs_src/tutorials/whatsapp/main.py !} +{!> docs_src/getting_started/mesop/my_fastagency_app/my_fastagency_app/deployment/main.py !} ``` +
@@ -211,7 +232,7 @@ The preferred way to run the [**Mesop**](https://google.github.io/mesop/){target === "Cookiecutter" !!! note "Terminal" ```console - gunicorn main:app + gunicorn my_fastagency_app.deployment.main:app ``` === "env + pip" diff --git a/docs/docs_src/tutorials/whatsapp/main.py b/docs/docs_src/tutorials/whatsapp/main.py index a189da54..53134a91 100644 --- a/docs/docs_src/tutorials/whatsapp/main.py +++ b/docs/docs_src/tutorials/whatsapp/main.py @@ -4,12 +4,11 @@ from autogen import register_function from autogen.agentchat import ConversableAgent -from fastagency import UI, FastAgency +from fastagency import UI from fastagency.api.openapi.client import OpenAPI from fastagency.api.openapi.security import APIKeyHeader from fastagency.runtimes.autogen import AutoGenWorkflows from fastagency.runtimes.autogen.agents.websurfer import WebSurferAgent -from fastagency.ui.mesop import MesopUI llm_config = { "config_list": [ @@ -126,6 +125,3 @@ def present_completed_task_or_ask_question( ) return chat_result.summary # type: ignore[no-any-return] - - -app = FastAgency(provider=wf, ui=MesopUI(), title="WhatsApp chat") From 8a1640799dba233358f5a22e059d035c43b19f18 Mon Sep 17 00:00:00 2001 From: Robert Jambrecic Date: Mon, 11 Nov 2024 11:16:20 +0000 Subject: [PATCH 03/12] wip --- docs/docs/en/tutorials/whatsapp/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/en/tutorials/whatsapp/index.md b/docs/docs/en/tutorials/whatsapp/index.md index 8e038233..7c35e1e3 100644 --- a/docs/docs/en/tutorials/whatsapp/index.md +++ b/docs/docs/en/tutorials/whatsapp/index.md @@ -122,7 +122,7 @@ You can set the API keys in your terminal as an environment variable: ## Complete Application Code ### Complete Workflow Code -You need to define the workflow that your application will use. This is where you specify how the agents interact and what they do. +You need to define the workflow that your application will use. This is where you specify how the agents interact and what they do. === "Cookiecutter" Workflow will be generated within the `my_fastagency_app/workflow.py` folder. You will need to replace the existing `workflow.py` with the code bellow. === "env + pip" From fc9acac6f8cfe7c029a066702f81a4e137627c51 Mon Sep 17 00:00:00 2001 From: Robert Jambrecic Date: Mon, 11 Nov 2024 11:39:01 +0000 Subject: [PATCH 04/12] wip --- docs/docs/en/tutorials/whatsapp/index.md | 36 ++++++++++++++++-------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/docs/docs/en/tutorials/whatsapp/index.md b/docs/docs/en/tutorials/whatsapp/index.md index 7c35e1e3..890888b0 100644 --- a/docs/docs/en/tutorials/whatsapp/index.md +++ b/docs/docs/en/tutorials/whatsapp/index.md @@ -29,6 +29,8 @@ We **strongly recommend** using [**Cookiecutter**](../cookiecutter/index.md) for You could also use virtual environment managers such as [venv](https://docs.python.org/3/library/venv.html){target="_blank"}, and a Python package manager, such as [pip](https://en.wikipedia.org/wiki/Pip_(package_manager)). +### a) Using Cookiecutter (**Recommended**) + {! docs/en/user-guide/cookiecutter/index.md[ln:6-16] !} 3. Depending on the type of the project, choose the appropriate option in step 3: @@ -59,12 +61,24 @@ You could also use virtual environment managers such as [venv](https://docs.pyth {! docs/en/user-guide/cookiecutter/index.md[ln:88-129] !} +9. Install additional dependencies which will be needed for this tutorial: + ```bash + pip install "fastagency[openapi]" + ``` + !!! info If you used a different `project_slug` than the default `my_fastagency_app` this will be reflected in the project module naming. Keep this in mind when running the commands further in this guide (in [Run Application](#run-application)), you will need to replace `my_fastagency_app` with your `project_slug` name. ------ +### b) Using Virtual Environment (**Alternative**) + +To get started, you need to install FastAgency with OpenAPI submodule. You can do this using `pip`, Python's package installer. + +```bash +pip install "fastagency[autogen,mesop,openapi]" +``` + ### API Key Setup [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer/WebSurferAgent.md) requires an **Bing Web Search** API key and **WhatsAppAgent** requires an API key to interact with Infobip's WhatsApp service. Follow these steps to create your API keys: @@ -144,7 +158,7 @@ You need to define the workflow that your application will use. This is where yo
main.py ```python -{!> docs_src/getting_started/mesop/my_fastagency_app/my_fastagency_app/deployment/main.py !} +{! docs_src/getting_started/mesop/my_fastagency_app/my_fastagency_app/deployment/main.py [ln:1-10] !} ```
@@ -170,7 +184,7 @@ 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 ***"whatsapp_and_websurfer"***. The ***@wf.register*** decorator registers the function to handle chat flow with security enabled, combining both WhatsAppAgent and WebSurferAgent. ```python -{! docs_src/tutorials/whatsapp/main.py [ln:61-65] !} +{! docs_src/tutorials/whatsapp/main.py [ln:63-64] !} ... ``` @@ -178,7 +192,7 @@ Here, we initialize a new workflow using ***AutoGenWorkflows()*** and register i This is a core function used by the **WhatsAppAgent** 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/tutorials/whatsapp/main.py [ln:69-79] !} +{! docs_src/tutorials/whatsapp/main.py [ln:68-78] !} ``` ### Creating the WhatsApp and WebSurfer Agents @@ -187,7 +201,7 @@ This is a core function used by the **WhatsAppAgent** to either present the task - [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer/WebSurferAgent.md): The [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer/WebSurferAgent.md) is responsible for scraping web content and passes the retrieved data to the **WhatsAppAgent**. 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.md). ```python -{! docs_src/tutorials/whatsapp/main.py [ln:81-97] !} +{! docs_src/tutorials/whatsapp/main.py [ln:80-97] !} ``` @@ -196,13 +210,13 @@ This is a core function used by the **WhatsAppAgent** to either present the task The function ***present_completed_task_or_ask_question*** is registered to allow the **WhatsAppAgent** to ask questions or present completed tasks after receiving data from the [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer/WebSurferAgent.md). ```python -{! docs_src/tutorials/whatsapp/main.py [ln:99-106] !} +{! docs_src/tutorials/whatsapp/main.py [ln:98-106] !} ``` We register the WhatsApp API, which allows the **WhatsAppAgent** to handle tasks like suggesting messages that will be sent to the user. ```python -{! docs_src/tutorials/whatsapp/main.py [ln:108-113] !} +{! docs_src/tutorials/whatsapp/main.py [ln:107-113] !} ``` ### Initiating the Chat @@ -212,7 +226,7 @@ We initiate the conversation between the user, [**`WebSurferAgent`**](../../api/ Once the conversation ends, the summary is returned to the user, wrapping up the session. ```python -{! docs_src/tutorials/whatsapp/main.py [ln:121-126] !} +{! docs_src/tutorials/whatsapp/main.py [ln:120-127] !} ``` ### Starting the Application @@ -220,7 +234,7 @@ Once the conversation ends, the summary is returned to the user, wrapping up the The FastAgency app is created, using the registered workflows (**`wf`**) and web-based user interface ([**`MesopUI`**](../../api/fastagency/ui/mesop/MesopUI.md)). This makes the conversation between agents and the user interactive. ```python -{! docs_src/tutorials/whatsapp/main.py [ln:131] !} +{! docs_src/getting_started/mesop/my_fastagency_app/my_fastagency_app/deployment/main.py [ln:6-10] !} ``` For more information, visit [**Mesop User Guide**](../../user-guide/ui/mesop/basics.md){target="_blank"}. @@ -242,14 +256,14 @@ The preferred way to run the [**Mesop**](https://google.github.io/mesop/){target !!! note "Terminal" ```console pip install gunicorn - gunicorn main:app + gunicorn deployment.main:app ``` === "Windows" !!! note "Terminal" ```console pip install waitress - waitress-serve --listen=0.0.0.0:8000 main:app + waitress-serve --listen=0.0.0.0:8000 deployment.main:app ``` ```console From d3e20f8693e0f2260ae2a94b4220e3d718bb65d9 Mon Sep 17 00:00:00 2001 From: Robert Jambrecic Date: Mon, 11 Nov 2024 11:48:38 +0000 Subject: [PATCH 05/12] wip --- docs/docs/en/tutorials/whatsapp/index.md | 123 ++++++++++++++++------- 1 file changed, 86 insertions(+), 37 deletions(-) diff --git a/docs/docs/en/tutorials/whatsapp/index.md b/docs/docs/en/tutorials/whatsapp/index.md index 890888b0..8a8c056d 100644 --- a/docs/docs/en/tutorials/whatsapp/index.md +++ b/docs/docs/en/tutorials/whatsapp/index.md @@ -29,55 +29,104 @@ We **strongly recommend** using [**Cookiecutter**](../cookiecutter/index.md) for You could also use virtual environment managers such as [venv](https://docs.python.org/3/library/venv.html){target="_blank"}, and a Python package manager, such as [pip](https://en.wikipedia.org/wiki/Pip_(package_manager)). -### a) Using Cookiecutter (**Recommended**) - -{! docs/en/user-guide/cookiecutter/index.md[ln:6-16] !} - -3. Depending on the type of the project, choose the appropriate option in step 3: - - ```console - [1/4] project_name (My FastAgency App): - [2/4] project_slug (my_fastagency_app): - [3/4] Select app_type - 1 - fastapi+mesop - 2 - mesop - 3 - nats+fastapi+mesop - Choose from [1/2/3] (1): 2 - [4/4] Select python_version - 1 - 3.12 - 2 - 3.11 - 3 - 3.10 - Choose from [1/2/3] (1): - ``` +=== "Cookiecutter" + + 1. Install Cookiecutter with the following command: + ```console + pip install cookiecutter + ``` + + 2. Run the `cookiecutter` command: + ```console + cookiecutter https://github.com/airtai/cookiecutter-fastagency.git + ``` - This command installs FastAgency with support for both the Console and Mesop interfaces for AutoGen workflows. + 3. Depending on the type of the project, choose the appropriate option in step 3: + ```console + [1/4] project_name (My FastAgency App): + [2/4] project_slug (my_fastagency_app): + [3/4] Select app_type + 1 - fastapi+mesop + 2 - mesop + 3 - nats+fastapi+mesop + Choose from [1/2/3] (1): 2 + [4/4] Select python_version + 1 - 3.12 + 2 - 3.11 + 3 - 3.10 + Choose from [1/2/3] (1): + ``` -4. Executing the `cookiecutter` command will create the following file structure: + This command installs FastAgency with support for both the Console and Mesop interfaces for AutoGen workflows. - ```console - {!> docs_src/getting_started/mesop/folder_structure.txt !} - ``` -{! docs/en/user-guide/cookiecutter/index.md[ln:88-129] !} + 4. Executing the `cookiecutter` command will create the following file structure: -9. Install additional dependencies which will be needed for this tutorial: - ```bash - pip install "fastagency[openapi]" - ``` + ```console + {!> docs_src/getting_started/mesop/folder_structure.txt !} + ``` + 5. To run LLM-based applications, you need an API key for the LLM used. The most commonly used LLM is [OpenAI](https://platform.openai.com/docs/models). To use it, create an [OpenAI API Key](https://openai.com/index/openai-api/) and set it as an environment variable in the terminal using the following command: + + ```console + export OPENAI_API_KEY=openai_api_key_here + ``` + + If you want to use a different LLM provider, follow [this guide](https://fastagency.ai/latest/user-guide/runtimes/autogen/using_non_openai_models/). + + Alternatively, you can skip this step and set the LLM API key as an environment variable later in the devcontainer's terminal. If you open the project in [Visual Studio Code](https://code.visualstudio.com/){target="_blank"} using GUI, you will need to manually set the environment variable in the devcontainer's terminal. + + 6. Open the generated project in [Visual Studio Code](https://code.visualstudio.com/){target="_blank"} with the following command: + ```console + code my_fastagency_app + ``` + + 7. Once the project is opened, you will get the following option to reopen it in a devcontainer: + + + + 8. After reopening the project in devcontainer, you can verify that the setup is correct by running the provided tests with the following command: + + ```console + pytest -s + ``` + + You should get the following output if everything is correctly setup. + ```console + =================================== test session starts =================================== + platform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0 + rootdir: /workspaces/my_fastagency_app + configfile: pyproject.toml + plugins: asyncio-0.24.0, anyio-4.6.2.post1 + asyncio: mode=Mode.STRICT, default_loop_scope=None + collected 1 item + + tests/test_workflow.py . [100%] + + ==================================== 1 passed in 1.02s ==================================== + ``` + + Running the test could take up to 30 seconds, depending on latency and throughput of OpenAI (or other LLM providers). + + + 9. Install additional dependencies which will be needed for this tutorial: + ```bash + pip install "fastagency[openapi]" + ``` -!!! info - If you used a different `project_slug` than the default `my_fastagency_app` this will be reflected in the project module naming. Keep this in mind when running the commands further in this guide (in [Run Application](#run-application)), you will need to replace `my_fastagency_app` with your `project_slug` name. + !!! info + If you used a different `project_slug` than the default `my_fastagency_app` this will be reflected in the project module naming. Keep this in mind when running the commands further in this guide (in [Run Application](#run-application)), you will need to replace `my_fastagency_app` with your `project_slug` name. -### b) Using Virtual Environment (**Alternative**) -To get started, you need to install FastAgency with OpenAPI submodule. You can do this using `pip`, Python's package installer. +=== "Using Virtual Environment" -```bash -pip install "fastagency[autogen,mesop,openapi]" -``` + To get started, you need to install FastAgency with OpenAPI submodule. You can do this using `pip`, Python's package installer. + + ```bash + pip install "fastagency[autogen,mesop,openapi]" + ``` ### API Key Setup [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer/WebSurferAgent.md) requires an **Bing Web Search** API key and **WhatsAppAgent** requires an API key to interact with Infobip's WhatsApp service. Follow these steps to create your API keys: From 934638c519027665e02bf1a1ce6015b8d6b0079f Mon Sep 17 00:00:00 2001 From: Robert Jambrecic Date: Mon, 11 Nov 2024 12:05:49 +0000 Subject: [PATCH 06/12] wip --- docs/docs/en/tutorials/whatsapp/index.md | 38 ++++++++++++------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/docs/en/tutorials/whatsapp/index.md b/docs/docs/en/tutorials/whatsapp/index.md index 8a8c056d..f24898f8 100644 --- a/docs/docs/en/tutorials/whatsapp/index.md +++ b/docs/docs/en/tutorials/whatsapp/index.md @@ -30,7 +30,7 @@ You could also use virtual environment managers such as [venv](https://docs.pyth === "Cookiecutter" - + 1. Install Cookiecutter with the following command: ```console pip install cookiecutter @@ -68,30 +68,30 @@ You could also use virtual environment managers such as [venv](https://docs.pyth ``` 5. To run LLM-based applications, you need an API key for the LLM used. The most commonly used LLM is [OpenAI](https://platform.openai.com/docs/models). To use it, create an [OpenAI API Key](https://openai.com/index/openai-api/) and set it as an environment variable in the terminal using the following command: - + ```console export OPENAI_API_KEY=openai_api_key_here ``` - + If you want to use a different LLM provider, follow [this guide](https://fastagency.ai/latest/user-guide/runtimes/autogen/using_non_openai_models/). - + Alternatively, you can skip this step and set the LLM API key as an environment variable later in the devcontainer's terminal. If you open the project in [Visual Studio Code](https://code.visualstudio.com/){target="_blank"} using GUI, you will need to manually set the environment variable in the devcontainer's terminal. - + 6. Open the generated project in [Visual Studio Code](https://code.visualstudio.com/){target="_blank"} with the following command: ```console code my_fastagency_app ``` - + 7. Once the project is opened, you will get the following option to reopen it in a devcontainer: - + - + 8. After reopening the project in devcontainer, you can verify that the setup is correct by running the provided tests with the following command: - + ```console pytest -s ``` - + You should get the following output if everything is correctly setup. ```console =================================== test session starts =================================== @@ -101,14 +101,14 @@ You could also use virtual environment managers such as [venv](https://docs.pyth plugins: asyncio-0.24.0, anyio-4.6.2.post1 asyncio: mode=Mode.STRICT, default_loop_scope=None collected 1 item - + tests/test_workflow.py . [100%] - + ==================================== 1 passed in 1.02s ==================================== ``` - + Running the test could take up to 30 seconds, depending on latency and throughput of OpenAI (or other LLM providers). - + 9. Install additional dependencies which will be needed for this tutorial: ```bash @@ -184,12 +184,12 @@ You can set the API keys in your terminal as an environment variable: ## Complete Application Code -### Complete Workflow Code +### Workflow Code You need to define the workflow that your application will use. This is where you specify how the agents interact and what they do. === "Cookiecutter" - Workflow will be generated within the `my_fastagency_app/workflow.py` folder. You will need to replace the existing `workflow.py` with the code bellow. + Workflow will be generated within the `my_fastagency_app/workflow.py` folder. You will need to replace the existing `workflow.py` with the code below. === "env + pip" - Create `workflow.py` and paste the code bellow inside. + Create `workflow.py` and paste the code below inside.
workflow.py @@ -200,9 +200,9 @@ You need to define the workflow that your application will use. This is where yo ### Deployment Code === "Cookiecutter" - Deployment files will be generated under `my_fastagency_app/deployment` folder. You will need to replace the existing `main.py` with the code bellow. + Deployment files will be generated under `my_fastagency_app/deployment` folder. Generated `main.py` should be the same as the code below. You don't need change anything. === "env + pip" - Create `deployment/main.py` and paste the code bellow inside. + Create `deployment/main.py` and paste the code below inside.
main.py From 6c74d8823edb33dd6eeba2b22e033694649470f0 Mon Sep 17 00:00:00 2001 From: Robert Jambrecic Date: Mon, 11 Nov 2024 12:32:48 +0000 Subject: [PATCH 07/12] wip --- docs/docs/en/tutorials/mesop_template.md | 178 +++++++++++++++++++++++ docs/docs/en/tutorials/whatsapp/index.md | 170 +--------------------- 2 files changed, 184 insertions(+), 164 deletions(-) create mode 100644 docs/docs/en/tutorials/mesop_template.md diff --git a/docs/docs/en/tutorials/mesop_template.md b/docs/docs/en/tutorials/mesop_template.md new file mode 100644 index 00000000..1f60b40a --- /dev/null +++ b/docs/docs/en/tutorials/mesop_template.md @@ -0,0 +1,178 @@ +## Project setup + +We **strongly recommend** using [**Cookiecutter**](../cookiecutter/index.md) for setting up the project. It creates the project folder structure, default workflow, automatically installs all the necessary requirements, and creates a [devcontainer](https://code.visualstudio.com/docs/devcontainers/containers){target="_blank"} that can be used with [Visual Studio Code](https://code.visualstudio.com/){target="_blank"} for development. + +You could also use virtual environment managers such as [venv](https://docs.python.org/3/library/venv.html){target="_blank"}, and a Python package manager, such as [pip](https://en.wikipedia.org/wiki/Pip_(package_manager)). + + +=== "Cookiecutter" + + 1. Install Cookiecutter with the following command: + ```console + pip install cookiecutter + ``` + + 2. Run the `cookiecutter` command: + ```console + cookiecutter https://github.com/airtai/cookiecutter-fastagency.git + ``` + + 3. Depending on the type of the project, choose the appropriate option in step 3: + + ```console + [1/4] project_name (My FastAgency App): + [2/4] project_slug (my_fastagency_app): + [3/4] Select app_type + 1 - fastapi+mesop + 2 - mesop + 3 - nats+fastapi+mesop + Choose from [1/2/3] (1): 2 + [4/4] Select python_version + 1 - 3.12 + 2 - 3.11 + 3 - 3.10 + Choose from [1/2/3] (1): + ``` + + This command installs FastAgency with support for both the Console and Mesop interfaces for AutoGen workflows. + + + 4. Executing the `cookiecutter` command will create the following file structure: + + ```console + {!> docs_src/getting_started/mesop/folder_structure.txt !} + ``` + + 5. To run LLM-based applications, you need an API key for the LLM used. The most commonly used LLM is [OpenAI](https://platform.openai.com/docs/models). To use it, create an [OpenAI API Key](https://openai.com/index/openai-api/) and set it as an environment variable in the terminal using the following command: + + ```console + export OPENAI_API_KEY=openai_api_key_here + ``` + + If you want to use a different LLM provider, follow [this guide](https://fastagency.ai/latest/user-guide/runtimes/autogen/using_non_openai_models/). + + Alternatively, you can skip this step and set the LLM API key as an environment variable later in the devcontainer's terminal. If you open the project in [Visual Studio Code](https://code.visualstudio.com/){target="_blank"} using GUI, you will need to manually set the environment variable in the devcontainer's terminal. + + 6. Open the generated project in [Visual Studio Code](https://code.visualstudio.com/){target="_blank"} with the following command: + ```console + code my_fastagency_app + ``` + + 7. Once the project is opened, you will get the following option to reopen it in a devcontainer: + + + + 8. After reopening the project in devcontainer, you can verify that the setup is correct by running the provided tests with the following command: + + ```console + pytest -s + ``` + + You should get the following output if everything is correctly setup. + ```console + =================================== test session starts =================================== + platform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0 + rootdir: /workspaces/my_fastagency_app + configfile: pyproject.toml + plugins: asyncio-0.24.0, anyio-4.6.2.post1 + asyncio: mode=Mode.STRICT, default_loop_scope=None + collected 1 item + + tests/test_workflow.py . [100%] + + ==================================== 1 passed in 1.02s ==================================== + ``` + + Running the test could take up to 30 seconds, depending on latency and throughput of OpenAI (or other LLM providers). + + + 9. Install additional dependencies which will be needed for this tutorial: + ```bash + pip install "fastagency[openapi]" + ``` + + + !!! info + If you used a different `project_slug` than the default `my_fastagency_app` this will be reflected in the project module naming. Keep this in mind when running the commands further in this guide (in [Run Application](#run-application)), you will need to replace `my_fastagency_app` with your `project_slug` name. + + +=== "Using Virtual Environment" + + To get started, you need to install FastAgency with OpenAPI submodule. You can do this using `pip`, Python's package installer. + + ```bash + pip install "fastagency[autogen,mesop,openapi]" + ``` + +## Workflow Code +You need to define the workflow that your application will use. This is where you specify how the agents interact and what they do. +=== "Cookiecutter" + Workflow will be generated within the `my_fastagency_app/workflow.py` folder. You will need to replace the existing `workflow.py` with the code below. +=== "env + pip" + Create `workflow.py` and paste the code below inside. + + +## Deployment Code +=== "Cookiecutter" + Deployment files will be generated under `my_fastagency_app/deployment` folder. Generated `main.py` should be the same as the code below. You don't need change anything. +=== "env + pip" + Create `deployment/main.py` and paste the code below inside. + +
+main.py +```python +{! docs_src/getting_started/mesop/my_fastagency_app/my_fastagency_app/deployment/main.py [ln:1-10] !} +``` + +
+ + +## Starting the Application + +The FastAgency app is created, using the registered workflows (**`wf`**) and web-based user interface ([**`MesopUI`**](../../api/fastagency/ui/mesop/MesopUI.md)). This makes the conversation between agents and the user interactive. + +```python +{! docs_src/getting_started/mesop/my_fastagency_app/my_fastagency_app/deployment/main.py [ln:6-10] !} +``` + +For more information, visit [**Mesop User Guide**](../../user-guide/ui/mesop/basics.md){target="_blank"}. + + +## Running the Application + +The preferred way to run the [**Mesop**](https://google.github.io/mesop/){target="_blank"} application is using a Python WSGI HTTP server like [**Gunicorn**](https://gunicorn.org/){target="_blank"} on Linux and Mac or [**Waitress**](https://docs.pylonsproject.org/projects/waitress/en/stable/){target="_blank"} on Windows. + +=== "Cookiecutter" + !!! note "Terminal" + ```console + gunicorn my_fastagency_app.deployment.main:app + ``` +=== "env + pip" + + First, install the package using package manager such as `pip` and then run it: + + === "Linux/MacOS" + !!! note "Terminal" + ```console + pip install gunicorn + gunicorn deployment.main:app + ``` + + === "Windows" + !!! note "Terminal" + ```console + pip install waitress + waitress-serve --listen=0.0.0.0:8000 deployment.main:app + ``` + +```console +[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 +``` + +The command will launch a web interface where users can input their requests and interact with the agents (in this case ***http://localhost:8000***) + +!!! note + Ensure that your OpenAI API key is set in the environment, as the agents rely on it to interact using GPT-4o. If the API key is not correctly configured, the application may fail to retrieve LLM-powered responses. diff --git a/docs/docs/en/tutorials/whatsapp/index.md b/docs/docs/en/tutorials/whatsapp/index.md index f24898f8..9545c85b 100644 --- a/docs/docs/en/tutorials/whatsapp/index.md +++ b/docs/docs/en/tutorials/whatsapp/index.md @@ -22,111 +22,8 @@ We will walk through setting up each agent, handling API security, and creating Let’s dive into creating a powerful interactive agent system with **FastAgency**! -## Project setup +{! docs/en/tutorials/mesop_template.md[ln:1-105] !} -We **strongly recommend** using [**Cookiecutter**](../cookiecutter/index.md) for setting up the project. It creates the project folder structure, default workflow, automatically installs all the necessary requirements, and creates a [devcontainer](https://code.visualstudio.com/docs/devcontainers/containers){target="_blank"} that can be used with [Visual Studio Code](https://code.visualstudio.com/){target="_blank"} for development. - -You could also use virtual environment managers such as [venv](https://docs.python.org/3/library/venv.html){target="_blank"}, and a Python package manager, such as [pip](https://en.wikipedia.org/wiki/Pip_(package_manager)). - - -=== "Cookiecutter" - - 1. Install Cookiecutter with the following command: - ```console - pip install cookiecutter - ``` - - 2. Run the `cookiecutter` command: - ```console - cookiecutter https://github.com/airtai/cookiecutter-fastagency.git - ``` - - 3. Depending on the type of the project, choose the appropriate option in step 3: - - ```console - [1/4] project_name (My FastAgency App): - [2/4] project_slug (my_fastagency_app): - [3/4] Select app_type - 1 - fastapi+mesop - 2 - mesop - 3 - nats+fastapi+mesop - Choose from [1/2/3] (1): 2 - [4/4] Select python_version - 1 - 3.12 - 2 - 3.11 - 3 - 3.10 - Choose from [1/2/3] (1): - ``` - - This command installs FastAgency with support for both the Console and Mesop interfaces for AutoGen workflows. - - - 4. Executing the `cookiecutter` command will create the following file structure: - - ```console - {!> docs_src/getting_started/mesop/folder_structure.txt !} - ``` - - 5. To run LLM-based applications, you need an API key for the LLM used. The most commonly used LLM is [OpenAI](https://platform.openai.com/docs/models). To use it, create an [OpenAI API Key](https://openai.com/index/openai-api/) and set it as an environment variable in the terminal using the following command: - - ```console - export OPENAI_API_KEY=openai_api_key_here - ``` - - If you want to use a different LLM provider, follow [this guide](https://fastagency.ai/latest/user-guide/runtimes/autogen/using_non_openai_models/). - - Alternatively, you can skip this step and set the LLM API key as an environment variable later in the devcontainer's terminal. If you open the project in [Visual Studio Code](https://code.visualstudio.com/){target="_blank"} using GUI, you will need to manually set the environment variable in the devcontainer's terminal. - - 6. Open the generated project in [Visual Studio Code](https://code.visualstudio.com/){target="_blank"} with the following command: - ```console - code my_fastagency_app - ``` - - 7. Once the project is opened, you will get the following option to reopen it in a devcontainer: - - - - 8. After reopening the project in devcontainer, you can verify that the setup is correct by running the provided tests with the following command: - - ```console - pytest -s - ``` - - You should get the following output if everything is correctly setup. - ```console - =================================== test session starts =================================== - platform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0 - rootdir: /workspaces/my_fastagency_app - configfile: pyproject.toml - plugins: asyncio-0.24.0, anyio-4.6.2.post1 - asyncio: mode=Mode.STRICT, default_loop_scope=None - collected 1 item - - tests/test_workflow.py . [100%] - - ==================================== 1 passed in 1.02s ==================================== - ``` - - Running the test could take up to 30 seconds, depending on latency and throughput of OpenAI (or other LLM providers). - - - 9. Install additional dependencies which will be needed for this tutorial: - ```bash - pip install "fastagency[openapi]" - ``` - - - !!! info - If you used a different `project_slug` than the default `my_fastagency_app` this will be reflected in the project module naming. Keep this in mind when running the commands further in this guide (in [Run Application](#run-application)), you will need to replace `my_fastagency_app` with your `project_slug` name. - - -=== "Using Virtual Environment" - - To get started, you need to install FastAgency with OpenAPI submodule. You can do this using `pip`, Python's package installer. - - ```bash - pip install "fastagency[autogen,mesop,openapi]" - ``` ### API Key Setup [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer/WebSurferAgent.md) requires an **Bing Web Search** API key and **WhatsAppAgent** requires an API key to interact with Infobip's WhatsApp service. Follow these steps to create your API keys: @@ -185,32 +82,17 @@ You can set the API keys in your terminal as an environment variable: ## Complete Application Code ### Workflow Code -You need to define the workflow that your application will use. This is where you specify how the agents interact and what they do. -=== "Cookiecutter" - Workflow will be generated within the `my_fastagency_app/workflow.py` folder. You will need to replace the existing `workflow.py` with the code below. -=== "env + pip" - Create `workflow.py` and paste the code below inside. +{! docs/en/tutorials/mesop_template.md[ln:108-112] !}
workflow.py ```python -{! docs_src/tutorials/whatsapp/main.py [ln:1-127] !} +{! docs_src/tutorials/whatsapp/main.py !} ```
### Deployment Code -=== "Cookiecutter" - Deployment files will be generated under `my_fastagency_app/deployment` folder. Generated `main.py` should be the same as the code below. You don't need change anything. -=== "env + pip" - Create `deployment/main.py` and paste the code below inside. - -
-main.py -```python -{! docs_src/getting_started/mesop/my_fastagency_app/my_fastagency_app/deployment/main.py [ln:1-10] !} -``` - -
+{! docs/en/tutorials/mesop_template.md[ln:116-127] !} ## Code Walkthrough @@ -280,52 +162,12 @@ Once the conversation ends, the summary is returned to the user, wrapping up the ### Starting the Application -The FastAgency app is created, using the registered workflows (**`wf`**) and web-based user interface ([**`MesopUI`**](../../api/fastagency/ui/mesop/MesopUI.md)). This makes the conversation between agents and the user interactive. - -```python -{! docs_src/getting_started/mesop/my_fastagency_app/my_fastagency_app/deployment/main.py [ln:6-10] !} -``` - -For more information, visit [**Mesop User Guide**](../../user-guide/ui/mesop/basics.md){target="_blank"}. +{! docs/en/tutorials/mesop_template.md[ln:132-138] !} ## Running the Application -The preferred way to run the [**Mesop**](https://google.github.io/mesop/){target="_blank"} application is using a Python WSGI HTTP server like [**Gunicorn**](https://gunicorn.org/){target="_blank"} on Linux and Mac or [**Waitress**](https://docs.pylonsproject.org/projects/waitress/en/stable/){target="_blank"} on Windows. - -=== "Cookiecutter" - !!! note "Terminal" - ```console - gunicorn my_fastagency_app.deployment.main:app - ``` -=== "env + pip" - - First, install the package using package manager such as `pip` and then run it: - - === "Linux/MacOS" - !!! note "Terminal" - ```console - pip install gunicorn - gunicorn deployment.main:app - ``` - - === "Windows" - !!! note "Terminal" - ```console - pip install waitress - waitress-serve --listen=0.0.0.0:8000 deployment.main:app - ``` - -```console -[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 -``` +{! docs/en/tutorials/mesop_template.md[ln:143-178] !} -The command will launch a web interface where users can input their requests and interact with the agents (in this case ***http://localhost:8000***) - -!!! note - Ensure that your OpenAI API key is set in the environment, as the agents rely on it to interact using GPT-4o. If the API key is not correctly configured, the application may fail to retrieve LLM-powered responses. ## Chat Example In this scenario, the user instructs the agents to scrape [BBC Sport](https://www.bbc.com/sport) for the latest sports news. From ecee3085f49a704d3f2edd7eb4e03d3a73a6adba Mon Sep 17 00:00:00 2001 From: Robert Jambrecic Date: Mon, 11 Nov 2024 12:53:43 +0000 Subject: [PATCH 08/12] wip --- docs/docs/en/tutorials/giphy/index.md | 66 +++++------------------- docs/docs/en/tutorials/mesop_template.md | 2 +- docs/docs/en/tutorials/whatsapp/index.md | 4 +- 3 files changed, 16 insertions(+), 56 deletions(-) diff --git a/docs/docs/en/tutorials/giphy/index.md b/docs/docs/en/tutorials/giphy/index.md index 696e30ed..337af5bb 100644 --- a/docs/docs/en/tutorials/giphy/index.md +++ b/docs/docs/en/tutorials/giphy/index.md @@ -22,19 +22,10 @@ We will walk through setting up each agent, handling API security, and creating Let’s dive into creating a powerful interactive agent system with **FastAgency**! -## Installation and API Key Setup +## Project setup -Before we dive into building our agents, let’s go over the necessary setup. We will guide you through installing the **FastAgency** framework and obtaining the API key needed for the Giphy integration. +{! docs/en/tutorials/mesop_template.md[ln:3-105] !} -### Installing FastAgency - -To get started, you need to install FastAgency with OpenAPI submodule. You can do this using `pip`, Python's package installer. - -```bash -pip install "fastagency[autogen,mesop,openapi]" -``` - -Alternatively, you can use [**Cookiecutter**](../../user-guide/cookiecutter/index.md), which is the preferred method. Cookiecutter creates the project folder structure, default workflow, automatically installs all the necessary requirements, and creates a [devcontainer](https://code.visualstudio.com/docs/devcontainers/containers){target="_blank"} that can be used with [Visual Studio Code](https://code.visualstudio.com/){target="_blank"}. ### API Key Setup [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer/WebSurferAgent.md) requires an **Bing Web Search** API key and **Giphy agent** requires an API key to interact with Giphy's service. Follow these steps to create your API keys: @@ -81,13 +72,20 @@ You can set the API keys in your terminal as an environment variable: ## Complete Application Code +### Workflow Code +{! docs/en/tutorials/mesop_template.md[ln:108-112] !} +
-main.py +workflow.py ```python {! docs_src/tutorials/giphy/main.py !} ```
+### Deployment Code +{! docs/en/tutorials/mesop_template.md[ln:116-127] !} + + ## Code Walkthrough @@ -152,52 +150,12 @@ Once the conversation ends, the summary is returned to the user, wrapping up the ### 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/tutorials/giphy/main.py [ln:127] !} -``` - -For more information, visit [**Mesop User Guide**](../../user-guide/ui/mesop/basics.md){target="_blank"}. +{! docs/en/tutorials/mesop_template.md[ln:132-138] !} ## Running the Application -The preferred way to run the [**Mesop**](https://google.github.io/mesop/){target="_blank"} application is using a Python WSGI HTTP server like [**Gunicorn**](https://gunicorn.org/){target="_blank"} on Linux and Mac or [**Waitress**](https://docs.pylonsproject.org/projects/waitress/en/stable/){target="_blank"} on Windows. - -=== "Cookiecutter" - !!! note "Terminal" - ```console - gunicorn main:app - ``` -=== "env + pip" - - First, install the package using package manager such as `pip` and then run it: - - === "Linux/MacOS" - !!! note "Terminal" - ```console - pip install gunicorn - gunicorn main:app - ``` - - === "Windows" - !!! note "Terminal" - ```console - pip install waitress - waitress-serve --listen=0.0.0.0:8000 main:app - ``` - -```console -[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 -``` - -The command will launch a web interface where users can input their requests and interact with the agents (in this case ***http://localhost:8000***) +{! docs/en/tutorials/mesop_template.md[ln:143-178] !} -!!! note - Ensure that your OpenAI API key is set in the environment, as the agents rely on it to interact using GPT-4o. If the API key is not correctly configured, the application may fail to retrieve LLM-powered responses. ## Chat Example In this scenario, the user instructs the agents to scrape [BBC Sport](https://www.bbc.com/sport) for the latest sports news. diff --git a/docs/docs/en/tutorials/mesop_template.md b/docs/docs/en/tutorials/mesop_template.md index 1f60b40a..3d1f99de 100644 --- a/docs/docs/en/tutorials/mesop_template.md +++ b/docs/docs/en/tutorials/mesop_template.md @@ -96,7 +96,7 @@ You could also use virtual environment managers such as [venv](https://docs.pyth If you used a different `project_slug` than the default `my_fastagency_app` this will be reflected in the project module naming. Keep this in mind when running the commands further in this guide (in [Run Application](#run-application)), you will need to replace `my_fastagency_app` with your `project_slug` name. -=== "Using Virtual Environment" +=== "env + pip" To get started, you need to install FastAgency with OpenAPI submodule. You can do this using `pip`, Python's package installer. diff --git a/docs/docs/en/tutorials/whatsapp/index.md b/docs/docs/en/tutorials/whatsapp/index.md index 9545c85b..d9054fd9 100644 --- a/docs/docs/en/tutorials/whatsapp/index.md +++ b/docs/docs/en/tutorials/whatsapp/index.md @@ -22,7 +22,9 @@ We will walk through setting up each agent, handling API security, and creating Let’s dive into creating a powerful interactive agent system with **FastAgency**! -{! docs/en/tutorials/mesop_template.md[ln:1-105] !} +## Project setup + +{! docs/en/tutorials/mesop_template.md[ln:3-105] !} ### API Key Setup From dd9c59c01cf879a4c7d2d9203187fc1b3a11d8bb Mon Sep 17 00:00:00 2001 From: Robert Jambrecic Date: Mon, 11 Nov 2024 12:57:44 +0000 Subject: [PATCH 09/12] Update secrets.baseline --- .secrets.baseline | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index d5c10725..77d335b1 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -151,7 +151,7 @@ "filename": "docs/docs/en/tutorials/whatsapp/index.md", "hashed_secret": "52e0d11a70cdb70d4c51064d08bd8f179ebb8bb4", "is_verified": false, - "line_number": 85, + "line_number": 75, "is_secret": false }, { @@ -159,7 +159,7 @@ "filename": "docs/docs/en/tutorials/whatsapp/index.md", "hashed_secret": "bc39a40e023f4ffb425b82830f86a464e5ea1072", "is_verified": false, - "line_number": 86, + "line_number": 76, "is_secret": false } ], @@ -262,5 +262,5 @@ } ] }, - "generated_at": "2024-11-06T13:37:43Z" + "generated_at": "2024-11-11T12:57:21Z" } From eccd579d014cae1e15f14f88a1b2c32c77e8dc3e Mon Sep 17 00:00:00 2001 From: Robert Jambrecic Date: Mon, 11 Nov 2024 13:07:36 +0000 Subject: [PATCH 10/12] Update lines --- .secrets.baseline | 6 +++--- docs/docs/en/tutorials/giphy/index.md | 14 +++++++------- docs/docs_src/tutorials/giphy/main.py | 7 +------ 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index 77d335b1..816c898d 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -133,7 +133,7 @@ "filename": "docs/docs/en/tutorials/giphy/index.md", "hashed_secret": "63f8ff37d3848fcf04ef3afe45d0fc830678d1ce", "is_verified": false, - "line_number": 73, + "line_number": 64, "is_secret": false }, { @@ -141,7 +141,7 @@ "filename": "docs/docs/en/tutorials/giphy/index.md", "hashed_secret": "bc39a40e023f4ffb425b82830f86a464e5ea1072", "is_verified": false, - "line_number": 74, + "line_number": 65, "is_secret": false } ], @@ -262,5 +262,5 @@ } ] }, - "generated_at": "2024-11-11T12:57:21Z" + "generated_at": "2024-11-11T13:07:26Z" } diff --git a/docs/docs/en/tutorials/giphy/index.md b/docs/docs/en/tutorials/giphy/index.md index 337af5bb..6c041019 100644 --- a/docs/docs/en/tutorials/giphy/index.md +++ b/docs/docs/en/tutorials/giphy/index.md @@ -96,7 +96,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/tutorials/giphy/main.py [ln:25-29] !} +{! docs_src/tutorials/giphy/main.py [ln:23-27] !} ``` For more information, visit [**API Integration User Guide**](../../user-guide/api/index.md){target="_blank"}. @@ -106,14 +106,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 Giphy agent and WebSurferAgent. ```python -{! docs_src/tutorials/giphy/main.py [ln:58-61] !} +{! docs_src/tutorials/giphy/main.py [ln:56-59] !} ``` ### Interaction with the user This is a core function used by the **Giphy agent** 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/tutorials/giphy/main.py [ln:65-76] !} +{! docs_src/tutorials/giphy/main.py [ln:63-73] !} ``` ### Creating the Giphy and WebSurfer Agents @@ -122,7 +122,7 @@ This is a core function used by the **Giphy agent** to either present the task r - **WebSurferAgent**: The *[**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer/WebSurferAgent.md)* is responsible for scraping web content and passes the retrieved data to the **Giphy agent**. 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.md){target="_blank"}. ```python -{! docs_src/tutorials/giphy/main.py [ln:77-92] !} +{! docs_src/tutorials/giphy/main.py [ln:75-90] !} ``` ### Registering Functions @@ -130,12 +130,12 @@ This is a core function used by the **Giphy agent** to either present the task r The function ***present_completed_task_or_ask_question*** is registered to allow the **Giphy agent** to ask questions or present completed tasks after receiving data from the [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer/WebSurferAgent.md). ```python -{! docs_src/tutorials/giphy/main.py [ln:94-101] !} +{! docs_src/tutorials/giphy/main.py [ln:92-99] !} ``` We specify which Giphy API functions can be used by the **Giphy agent**: *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/tutorials/giphy/main.py [ln:103-109] !} +{! docs_src/tutorials/giphy/main.py [ln:101-107] !} ``` ### Initiating the Chat @@ -145,7 +145,7 @@ We initiate the conversation between the user, [**`WebSurferAgent`**](../../api/ Once the conversation ends, the summary is returned to the user, wrapping up the session. ```python -{! docs_src/tutorials/giphy/main.py [ln:117-124] !} +{! docs_src/tutorials/giphy/main.py [ln:115-122] !} ``` ### Starting the Application diff --git a/docs/docs_src/tutorials/giphy/main.py b/docs/docs_src/tutorials/giphy/main.py index 0ecb7e4e..c9a43327 100644 --- a/docs/docs_src/tutorials/giphy/main.py +++ b/docs/docs_src/tutorials/giphy/main.py @@ -4,13 +4,11 @@ from autogen import register_function from autogen.agentchat import ConversableAgent -from fastagency import UI, FastAgency +from fastagency import UI from fastagency.api.openapi.client import OpenAPI from fastagency.api.openapi.security import APIKeyQuery -from fastagency.messages import TextInput from fastagency.runtimes.autogen.agents.websurfer import WebSurferAgent from fastagency.runtimes.autogen import AutoGenWorkflows -from fastagency.ui.mesop import MesopUI llm_config = { "config_list": [ @@ -122,6 +120,3 @@ def present_completed_task_or_ask_question( ) return chat_result.summary # type: ignore[no-any-return] - - -app = FastAgency(provider=wf, ui=MesopUI(), title="Giphy and Websurfer chat") From e2d93e1816f8a1cbc09a3f98664437764cc4be8b Mon Sep 17 00:00:00 2001 From: Robert Jambrecic Date: Mon, 11 Nov 2024 13:11:43 +0000 Subject: [PATCH 11/12] Fix tests --- tests/docs_src/test_import.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/docs_src/test_import.py b/tests/docs_src/test_import.py index 90fa0adc..6c1bcdcf 100644 --- a/tests/docs_src/test_import.py +++ b/tests/docs_src/test_import.py @@ -69,11 +69,7 @@ def test_submodules(module: str, monkeypatch: pytest.MonkeyPatch) -> None: or module in MESOP_EXCLUDED_MODULES ): pass - elif ( - ("mesop" in module) - or ("tutorials.giphy" in module) - or ("tutorials.whatsapp" in module) - ): + elif "mesop" in module: with pytest.raises( FastAgencyCLIPythonVersionError, match="Mesop requires Python 3.10 or higher", From b5e2eee9a4e048c8135c23df9f22dbbf50ea25c1 Mon Sep 17 00:00:00 2001 From: Robert Jambrecic Date: Mon, 11 Nov 2024 13:18:55 +0000 Subject: [PATCH 12/12] Fix tests --- tests/docs_src/test_import.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/docs_src/test_import.py b/tests/docs_src/test_import.py index 6c1bcdcf..8361bb97 100644 --- a/tests/docs_src/test_import.py +++ b/tests/docs_src/test_import.py @@ -69,7 +69,7 @@ def test_submodules(module: str, monkeypatch: pytest.MonkeyPatch) -> None: or module in MESOP_EXCLUDED_MODULES ): pass - elif "mesop" in module: + elif "mesop" in module or "tutorials.giphy.simple_main" in module: with pytest.raises( FastAgencyCLIPythonVersionError, match="Mesop requires Python 3.10 or higher",