From 6b632f8b8a028ab41e9eb27261552df0a19f6cfe Mon Sep 17 00:00:00 2001 From: rjambrecic <32619626+rjambrecic@users.noreply.github.com> Date: Fri, 13 Sep 2024 16:03:26 +0200 Subject: [PATCH] Update docs (#214) * Fix runtime docs * Remove 'cd docs' from documentation * Fix security docs * Add collapsable app code to each docs page * Update security docs --- docs/docs/en/getting-started/index.md | 17 +++++++++++++++ docs/docs/en/user-guide/api/openapi/index.md | 14 +++++++++++-- docs/docs/en/user-guide/api/security.md | 20 +++++++++++++----- .../en/user-guide/runtime/autogen/index.md | 15 ++++++++++--- .../runtime/autogen/interactions.md | 6 ++++-- docs/docs/en/user-guide/ui/console/basics.md | 14 +++++++++++-- docs/docs/en/user-guide/ui/mesop/basics.md | 14 +++++++++++-- .../user_guide/external_rest_apis/main.py | 4 +--- .../user_guide/external_rest_apis/security.py | 21 ++++++++----------- .../user_guide/runtime/autogen/main.py | 2 +- 10 files changed, 95 insertions(+), 32 deletions(-) diff --git a/docs/docs/en/getting-started/index.md b/docs/docs/en/getting-started/index.md index 45b9a0da3..1b33ebf96 100644 --- a/docs/docs/en/getting-started/index.md +++ b/docs/docs/en/getting-started/index.md @@ -160,6 +160,23 @@ Next, define your FastAgency application. This ties together your workflow and t For Mesop applications, use `MesopUI` to enable web-based interactions. + +## Complete Application Code + +
+Console +```python +{! docs_src/getting_started/main_console.py!} +``` +
+ +
+Mesop +```python +{! docs_src/getting_started/main_mesop.py!} +``` +
+ ### Run Application Once everything is set up, you can run your FastAgency application using the following command: diff --git a/docs/docs/en/user-guide/api/openapi/index.md b/docs/docs/en/user-guide/api/openapi/index.md index 15b45134f..2cf7f3504 100644 --- a/docs/docs/en/user-guide/api/openapi/index.md +++ b/docs/docs/en/user-guide/api/openapi/index.md @@ -39,15 +39,25 @@ This code snippet sets up a simple weather agent that calls an external weather Next, define your FastAgency application. ```python -{! docs_src/user_guide/external_rest_apis/main.py [ln:63] !} +{! docs_src/user_guide/external_rest_apis/main.py [ln:61] !} ``` +## Complete Application Code + +
+main.py +```python +{! docs_src/user_guide/external_rest_apis/main.py !} +``` +
+ + ## Run Application You can run this chapter's FastAgency application using the following command: ```console -fastagency run docs/docs_src/user_guide/external_rest_apis/main.py +fastagency run ``` ## Output diff --git a/docs/docs/en/user-guide/api/security.md b/docs/docs/en/user-guide/api/security.md index c46e0ef02..184de6d29 100644 --- a/docs/docs/en/user-guide/api/security.md +++ b/docs/docs/en/user-guide/api/security.md @@ -29,13 +29,13 @@ In this workflow, we create a Python client for the external REST API by passing Additionally, we set the API key for the API using the `set_security_params` method: ```python hl_lines="2" -{! docs_src/user_guide/external_rest_apis/security.py [ln:33.5,34.5] !} +{! docs_src/user_guide/external_rest_apis/security.py [ln:26,27] !} ``` Here's a simple example of a workflow definition: -```python hl_lines="22" -{! docs_src/user_guide/external_rest_apis/security.py [ln:13-68] !} +```python hl_lines="15" +{! docs_src/user_guide/external_rest_apis/security.py [ln:13-66] !} ``` This code snippet sets up a simple weather agent that calls an external weather API with security, using the registered functions generated from the `openapi.json` URL. @@ -45,15 +45,25 @@ This code snippet sets up a simple weather agent that calls an external weather Next, define your FastAgency application. ```python -{! docs_src/user_guide/external_rest_apis/security.py [ln:71] !} +{! docs_src/user_guide/external_rest_apis/security.py [ln:68] !} ``` +## Complete Application Code + +
+main.py +```python +{! docs_src/user_guide/external_rest_apis/security.py !} +``` +
+ + ## Run Application You can run this chapter's FastAgency application using the following command:: ```console -fastagency run docs/docs_src/user_guide/external_rest_apis/security.py +fastagency run ``` ## Output diff --git a/docs/docs/en/user-guide/runtime/autogen/index.md b/docs/docs/en/user-guide/runtime/autogen/index.md index b6e345c40..2a58fd104 100644 --- a/docs/docs/en/user-guide/runtime/autogen/index.md +++ b/docs/docs/en/user-guide/runtime/autogen/index.md @@ -9,7 +9,7 @@ In this example, we will create a simple weather chatbot using **AutoGen** in Fa Before getting started, make sure you have installed FastAgency with support for the AutoGen runtime by running the following command: ```bash -pip install "fastagency[autogen]" +pip install "fastagency[autogen,openapi]" ``` This installation includes the AutoGen runtime, allowing you to build multi-agent workflows and integrate external APIs seamlessly. @@ -73,11 +73,20 @@ Finally, we create the FastAgency application and launch it using the console in {! docs_src/user_guide/runtime/autogen/main.py [ln:71-72] !} ``` +## Complete Application Code + +
+main.py +```python +{! docs_src/user_guide/runtime/autogen/main.py!} +``` +
+ + ### Running the Application ```bash -cd docs/docs_src/user_guide/runtime/autogen -fastagency run main.py +fastagency run ``` Ensure you have set your OpenAI API key in the environment and that the weather API URL is accessible. The command will launch a console interface where users can input their requests and interact with the weather agent. diff --git a/docs/docs/en/user-guide/runtime/autogen/interactions.md b/docs/docs/en/user-guide/runtime/autogen/interactions.md index 701a29666..ac5e42de0 100644 --- a/docs/docs/en/user-guide/runtime/autogen/interactions.md +++ b/docs/docs/en/user-guide/runtime/autogen/interactions.md @@ -53,12 +53,14 @@ We now register these functions with the workflow, linking the `student_agent` a {! docs_src/user_guide/custom_user_interactions/main.py [ln:101.5,102.5,103.5,104.5,105.5,106.5,107.5,108.5,109.5,110.5,111.5,112.5,113.5,114.5,115.5,116.5,117.5,118.5,119.5,120.5,121.5,122.5,123.5] !} ``` -## Define FastAgency Application -Finally, we'll define the entire application: +## Complete Application Code +
+main.py ```python {! docs_src/user_guide/custom_user_interactions/main.py!} ``` +
## Run Application diff --git a/docs/docs/en/user-guide/ui/console/basics.md b/docs/docs/en/user-guide/ui/console/basics.md index 47fc67048..94ef34497 100644 --- a/docs/docs/en/user-guide/ui/console/basics.md +++ b/docs/docs/en/user-guide/ui/console/basics.md @@ -50,13 +50,23 @@ Finally, we instantiate **[ConsoleUI](../../../../api/fastagency/ui/console/Cons - **Explanation**: Here, we set up the **ConsoleUI** as the user interface for the workflow, which will allow the entire agent interaction to take place within the terminal. + +## Complete Application Code + +
+main.py +```python +{! docs_src/getting_started/main_console.py !} +``` +
+ + ### Running the Application Once the workflow is set up, you can run the application using the **FastAgency CLI**. Navigate to the directory where the script is located and run the following command: ```bash -cd docs/docs_src/getting_started -fastagency run main_console.py +fastagency run ``` This will launch the console interface, allowing you to input messages as the student and observe how the teacher agent responds. diff --git a/docs/docs/en/user-guide/ui/mesop/basics.md b/docs/docs/en/user-guide/ui/mesop/basics.md index 0985e1a2a..c12904f1d 100644 --- a/docs/docs/en/user-guide/ui/mesop/basics.md +++ b/docs/docs/en/user-guide/ui/mesop/basics.md @@ -59,13 +59,23 @@ app = FastAgency(wf=wf, ui=MesopUI()) - **Explanation**: Here, we set up the **MesopUI** as the user interface for the workflow, which will allow the entire agent interaction to take place through a web-based platform. + +## Complete Application Code + +
+main.py +```python +{! docs_src/getting_started/main_mesop.py !} +``` +
+ + ### Running the Application Once the workflow is set up, you can run the application using the **FastAgency CLI**. Navigate to the directory where the script is located and run the following command: ```bash -cd docs/docs_src/getting_started -fastagency run main_mesop.py +fastagency run ``` This will launch a local web server, and you will be able to access the MesopUI interface through your browser. The web interface will display the interaction between the student and teacher agents, allowing you to input questions and see the teacher’s responses. diff --git a/docs/docs_src/user_guide/external_rest_apis/main.py b/docs/docs_src/user_guide/external_rest_apis/main.py index 78a9e3b3a..9e3c67d7a 100644 --- a/docs/docs_src/user_guide/external_rest_apis/main.py +++ b/docs/docs_src/user_guide/external_rest_apis/main.py @@ -22,15 +22,13 @@ } WEATHER_OPENAPI_URL = "https://weather.tools.fastagency.ai/openapi.json" +weather_api = OpenAPI.create(openapi_url=WEATHER_OPENAPI_URL) wf = AutoGenWorkflows() @wf.register(name="simple_weather", description="Weather chat") def weather_workflow(wf: Workflows, ui: UI, initial_message: str, session_id: str) -> str: - - weather_api = OpenAPI.create(openapi_url=WEATHER_OPENAPI_URL) - user_agent = UserProxyAgent( name="User_Agent", system_message="You are a user agent", diff --git a/docs/docs_src/user_guide/external_rest_apis/security.py b/docs/docs_src/user_guide/external_rest_apis/security.py index fdfab2981..ee54a19e2 100644 --- a/docs/docs_src/user_guide/external_rest_apis/security.py +++ b/docs/docs_src/user_guide/external_rest_apis/security.py @@ -21,24 +21,21 @@ } WEATHER_OPENAPI_URL = "https://weather.tools.fastagency.ai/openapi.json" +weather_api = OpenAPI.create(openapi_url=WEATHER_OPENAPI_URL) + +# Set global security params for all methods +weather_api.set_security_params(APIKeyHeader.Parameters(value="secure weather key")) +# Set security params for a specific method +# weather_api.set_security_params( +# APIKeyHeader.Parameters(value="secure weather key"), +# "get_daily_weather_daily_get", +# ) wf = AutoGenWorkflows() @wf.register(name="simple_weather_with_security", description="Weather chat with security") def weather_workflow_with_security(wf: Workflows, ui: UI, initial_message: str, session_id: str) -> str: - - weather_api = OpenAPI.create(openapi_url=WEATHER_OPENAPI_URL) - - # Set global security params for all methods - weather_api.set_security_params(APIKeyHeader.Parameters(value="secure weather key")) - - # Set security params for a specific method - # weather_api.set_security_params( - # APIKeyHeader.Parameters(value="secure weather key"), - # "get_daily_weather_daily_get", - # ) - user_agent = UserProxyAgent( name="User_Agent", system_message="You are a user agent", diff --git a/docs/docs_src/user_guide/runtime/autogen/main.py b/docs/docs_src/user_guide/runtime/autogen/main.py index 5567c949f..c83f2325a 100644 --- a/docs/docs_src/user_guide/runtime/autogen/main.py +++ b/docs/docs_src/user_guide/runtime/autogen/main.py @@ -54,7 +54,7 @@ def weather_workflow(wf: AutoGenWorkflows, ui: UI, initial_message: str, session "description": "Get the daily weather", } }, - "get_daily_weather_weekly_get" + "get_hourly_weather_hourly_get" ] )