Skip to content

Commit

Permalink
Add basic auth to getting started (#572)
Browse files Browse the repository at this point in the history
* added noauth subfolder in docs_src

* added basic_auth to getting started

* cleanup
  • Loading branch information
davorrunje authored Nov 13, 2024
1 parent 93232b3 commit 6403b84
Show file tree
Hide file tree
Showing 257 changed files with 3,178 additions and 68 deletions.
9 changes: 6 additions & 3 deletions .semgrepignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
docs/overrides/main.html
docs/docs_src/getting_started/mesop/my_fastagency_app/.devcontainer/docker-compose.yml
docs/docs_src/getting_started/fastapi/my_fastagency_app/.devcontainer/docker-compose.yml
docs/docs_src/getting_started/nats_n_fastapi/my_fastagency_app/.devcontainer/docker-compose.yml
docs/docs_src/getting_started/no_auth/mesop/my_fastagency_app/.devcontainer/docker-compose.yml
docs/docs_src/getting_started/no_auth/fastapi/my_fastagency_app/.devcontainer/docker-compose.yml
docs/docs_src/getting_started/no_auth/nats_n_fastapi/my_fastagency_app/.devcontainer/docker-compose.yml
docs/docs_src/getting_started/basic_auth/mesop/my_fastagency_app/.devcontainer/docker-compose.yml
docs/docs_src/getting_started/basic_auth/fastapi/my_fastagency_app/.devcontainer/docker-compose.yml
docs/docs_src/getting_started/basic_auth/nats_n_fastapi/my_fastagency_app/.devcontainer/docker-compose.yml
6 changes: 3 additions & 3 deletions docs/docs/en/tutorials/mesop_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ You could also use virtual environment managers such as [venv](https://docs.pyth
4. Executing the `cookiecutter` command will create the following file structure:

```console
{!> docs_src/getting_started/mesop/folder_structure.txt !}
{!> docs_src/getting_started/no_auth/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:
Expand Down Expand Up @@ -121,7 +121,7 @@ You need to define the workflow that your application will use. This is where yo
<details>
<summary>main.py</summary>
```python
{! docs_src/getting_started/mesop/my_fastagency_app/my_fastagency_app/deployment/main.py [ln:1-10] !}
{! docs_src/getting_started/no_auth/mesop/my_fastagency_app/my_fastagency_app/deployment/main.py [ln:1-10] !}
```

</details>
Expand All @@ -132,7 +132,7 @@ You need to define the workflow that your application will use. This is where yo
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] !}
{! docs_src/getting_started/no_auth/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"}.
Expand Down
20 changes: 10 additions & 10 deletions docs/docs/en/user-guide/adapters/fastapi/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Alternatively, you can use **pip + venv**.
To get started, 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/fastapi/my_fastagency_app/my_fastagency_app/workflow.py [ln:1-47] !}
{! docs_src/getting_started/no_auth/fastapi/my_fastagency_app/my_fastagency_app/workflow.py [ln:1-47] !}
```

#### 2. **Import Required Modules**
Expand All @@ -233,23 +233,23 @@ To get started, define the workflow that your application will use. This is wher
Next, import the required modules from the **FastAgency**. Import the [**`FastAPIAdapter`**](../../../api/fastagency/adapters/fastapi/FastAPIAdapter.md) class to expose the workflows as a [**REST API**](https://en.wikipedia.org/wiki/REST){target="_blank"}.

```python hl_lines="3"
{!> docs_src/getting_started/fastapi/my_fastagency_app/my_fastagency_app/deployment/main_1_fastapi.py [ln:1-4] !}
{!> docs_src/getting_started/no_auth/fastapi/my_fastagency_app/my_fastagency_app/deployment/main_1_fastapi.py [ln:1-4] !}
```

=== "Custom REST API and Websocket"

Next, import the required modules from the **FastAgency** and **AutoGen**. These imports provide the essential building blocks for creating agents, workflows, and integrating with the custom client. Additionally, import the [**`FastAPIAdapter`**](../../../api/fastagency/adapters/fastapi/FastAPIAdapter.md) and [**`HTMLResponse`**](https://fastapi.tiangolo.com/advanced/custom-response/#html-response){target="_blank"} class to expose the workflows as a [**REST API**](https://en.wikipedia.org/wiki/REST){target="_blank"}.

```python hl_lines="6 9"
{!> docs_src/getting_started/fastapi/main_fastapi_custom_client.py [ln:1-10] !}
{!> docs_src/getting_started/no_auth/fastapi/main_fastapi_custom_client.py [ln:1-10] !}
```

#### 3. **Define FastAgency Application**

Create an instance of the [**`FastAPIAdapter`**](../../../api/fastagency/adapters/fastapi/FastAPIAdapter.md) and pass your workflow to it. Then, include a router to the [**FastAPI**](https://fastapi.tiangolo.com/){target="_blank"} application. The adapter will have all [**REST API**](https://en.wikipedia.org/wiki/REST){target="_blank"} and [**WebSocket**](https://en.wikipedia.org/wiki/WebSocket){target="_blank"} routes for communicating with the client.

```python hl_lines="1 4"
{!> docs_src/getting_started/fastapi/my_fastagency_app/my_fastagency_app/deployment/main_1_fastapi.py [ln:8-11] !}
{!> docs_src/getting_started/no_auth/fastapi/my_fastagency_app/my_fastagency_app/deployment/main_1_fastapi.py [ln:8-11] !}
```

=== "Mesop"
Expand All @@ -260,7 +260,7 @@ Create an instance of the [**`FastAPIAdapter`**](../../../api/fastagency/adapter

!!! note "main_2_mesop.py"
```python
{!> docs_src/getting_started/fastapi/my_fastagency_app/my_fastagency_app/deployment/main_2_mesop.py [ln:1-15] !}
{!> docs_src/getting_started/no_auth/fastapi/my_fastagency_app/my_fastagency_app/deployment/main_2_mesop.py [ln:1-15] !}
```

=== "Custom REST API and Websocket"
Expand All @@ -270,7 +270,7 @@ Create an instance of the [**`FastAPIAdapter`**](../../../api/fastagency/adapter
Finally, use the [**HTML Response**](https://fastapi.tiangolo.com/advanced/custom-response/#html-response){target="_blank"} from FastAPI to serve the custom client code.

```python
{!> docs_src/getting_started/fastapi/main_fastapi_custom_client.py [ln:12-98,146-148] !}
{!> docs_src/getting_started/no_auth/fastapi/main_fastapi_custom_client.py [ln:12-98,146-148] !}
```

### Complete Application Code
Expand All @@ -282,21 +282,21 @@ Please copy and paste the following code into the same folder, using the file na
<details>
<summary>workflow.py</summary>
```python
{!> docs_src/getting_started/fastapi/my_fastagency_app/my_fastagency_app/workflow.py !}
{!> docs_src/getting_started/no_auth/fastapi/my_fastagency_app/my_fastagency_app/workflow.py !}
```
</details>

<details>
<summary>main_1_fastapi.py</summary>
```python
{!> docs_src/getting_started/fastapi/my_fastagency_app/my_fastagency_app/deployment/main_1_fastapi.py !}
{!> docs_src/getting_started/no_auth/fastapi/my_fastagency_app/my_fastagency_app/deployment/main_1_fastapi.py !}
```
</details>

<details>
<summary>main_2_mesop.py</summary>
```python
{!> docs_src/getting_started/fastapi/my_fastagency_app/my_fastagency_app/deployment/main_2_mesop.py !}
{!> docs_src/getting_started/no_auth/fastapi/my_fastagency_app/my_fastagency_app/deployment/main_2_mesop.py !}
```
</details>

Expand All @@ -305,7 +305,7 @@ Please copy and paste the following code into the same folder, using the file na
<details>
<summary>main_fastapi_custom_client.py</summary>
```python
{!> docs_src/getting_started/fastapi/main_fastapi_custom_client.py !}
{!> docs_src/getting_started/no_auth/fastapi/main_fastapi_custom_client.py !}
```
</details>

Expand Down
36 changes: 18 additions & 18 deletions docs/docs/en/user-guide/adapters/fastapi_nats/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,31 +130,31 @@ As shown in the [**architecture overview**](#architecture-overview), this setup
To get started, 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/nats_n_fastapi/my_fastagency_app/my_fastagency_app/workflow.py [ln:1-47] !}
{! docs_src/getting_started/no_auth/nats_n_fastapi/my_fastagency_app/my_fastagency_app/workflow.py [ln:1-47] !}
```

#### 2. **Import Required Modules**

Next, import the required modules from the **FastAgency**. These imports provide the essential building blocks for integrating with the client. Additionally, import the [**`NatsAdapter`**](../../../api/fastagency/adapters/nats/NatsAdapter.md) class for workflow execution.

```python hl_lines="4"
{!> docs_src/getting_started/nats_n_fastapi/my_fastagency_app/my_fastagency_app/deployment/main_1_nats.py [ln:1-7] !}
{!> docs_src/getting_started/no_auth/nats_n_fastapi/my_fastagency_app/my_fastagency_app/deployment/main_1_nats.py [ln:1-7] !}
```

#### 3. **Configure the `NatsAdapter`**

Create an instance of the [**`NatsAdapter`**](../../../api/fastagency/adapters/nats/NatsAdapter.md) and pass your workflow to it. The adapter will handle the communication with the [**`NatsProvider`**](../../../api/fastagency/adapters/nats/NatsProvider.md) and distribute workflow execution to the workers.

```python hl_lines="5"
{!> docs_src/getting_started/nats_n_fastapi/my_fastagency_app/my_fastagency_app/deployment/main_1_nats.py [ln:9-13] !}
{!> docs_src/getting_started/no_auth/nats_n_fastapi/my_fastagency_app/my_fastagency_app/deployment/main_1_nats.py [ln:9-13] !}
```

#### 4. **Define FastAgency Application**

Create a [**`NatsAdapter`**](../../../api/fastagency/adapters/nats/NatsAdapter.md) and then add it to the [**FastAPI**](https://fastapi.tiangolo.com/){target="_blank"} application using the [**lifespan parameter**](https://fastapi.tiangolo.com/advanced/events/){target="_blank"}.

```python
{!> docs_src/getting_started/nats_n_fastapi/my_fastagency_app/my_fastagency_app/deployment/main_1_nats.py [ln:15] !}
{!> docs_src/getting_started/no_auth/nats_n_fastapi/my_fastagency_app/my_fastagency_app/deployment/main_1_nats.py [ln:15] !}
```

#### 5. **Adapter Chaining**
Expand All @@ -167,21 +167,21 @@ Next, we set up a FastAPI service to interact with the NATS.io provider. This in

!!! note "main_2_fastapi.py"
```python hl_lines="15-17 19-20"
{!> docs_src/getting_started/nats_n_fastapi/my_fastagency_app/my_fastagency_app/deployment/main_2_fastapi.py [ln:1-20] !}
{!> docs_src/getting_started/no_auth/nats_n_fastapi/my_fastagency_app/my_fastagency_app/deployment/main_2_fastapi.py [ln:1-20] !}
```

Finally, the last component is the [**Mesop Client App**](#1-mesop-client-app), which uses the [**`MesopUI`**](../../../api/fastagency/ui/mesop/MesopUI.md) to communicate with both the user and the [**`FastAPIProvider`**](../../../api/fastagency/adapters/fastapi/FastAPIProvider.md).

!!! note "main_3_mesop.py"
```python hl_lines="7-9 11-15"
{!> docs_src/getting_started/nats_n_fastapi/my_fastagency_app/my_fastagency_app/deployment/main_3_mesop.py [ln:1-15] !}
{!> docs_src/getting_started/no_auth/nats_n_fastapi/my_fastagency_app/my_fastagency_app/deployment/main_3_mesop.py [ln:1-15] !}
```

=== "Custom REST API and WebSocket"

!!! note "main_fastapi_custom_client.py"
```python hl_lines="17-19 22-23"
{!> docs_src/getting_started/nats_n_fastapi/main_2_fastapi_custom_client.py [ln:1-8,96-110] !}
{!> docs_src/getting_started/no_auth/nats_n_fastapi/main_2_fastapi_custom_client.py [ln:1-8,96-110] !}
```

Finally, for simplicity, we will serve our custom HTML client as part of the same [**FastAPI App**](#2-fastapi-app) using FastAPI's [**HTMLResponse**](https://fastapi.tiangolo.com/advanced/custom-response/#html-response){target="_blank"}.
Expand All @@ -194,7 +194,7 @@ Next, we set up a FastAPI service to interact with the NATS.io provider. This in

!!! note "main_fastapi_custom_client.py"
```python
{!> docs_src/getting_started/nats_n_fastapi/main_2_fastapi_custom_client.py [ln:9-95,113-115] !}
{!> docs_src/getting_started/no_auth/nats_n_fastapi/main_2_fastapi_custom_client.py [ln:9-95,113-115] !}
```


Expand All @@ -203,7 +203,7 @@ Next, we set up a FastAPI service to interact with the NATS.io provider. This in
The [**`NatsAdapter`**](../../../api/fastagency/adapters/nats/NatsAdapter.md) requires a running NATS server. The easiest way to start the NATS server is by using [**Docker**](https://www.docker.com/){target="_blank"}. FastAgency leverages the [**JetStream**](https://docs.nats.io/nats-concepts/jetstream){target="_blank"} feature of NATS and also utilizes authentication.

```python hl_lines="1 3 8 14"
{!> docs_src/getting_started/nats_n_fastapi/my_fastagency_app/.devcontainer/nats_server.conf [ln:1-31]!}
{!> docs_src/getting_started/no_auth/nats_n_fastapi/my_fastagency_app/.devcontainer/nats_server.conf [ln:1-31]!}
```

In the above Nats configuration, we define a user called `fastagency`, and its password is read from the environment variable `FASTAGENCY_NATS_PASSWORD`. We also enable JetStream in Nats and configure Nats to serve via the appropriate ports.
Expand All @@ -217,35 +217,35 @@ Please copy and paste the following code into the same folder, using the file na
<details>
<summary>nats_server.conf</summary>
```python
{!> docs_src/getting_started/nats_n_fastapi/my_fastagency_app/.devcontainer/nats_server.conf !}
{!> docs_src/getting_started/no_auth/nats_n_fastapi/my_fastagency_app/.devcontainer/nats_server.conf !}
```
</details>

<details>
<summary>workflow.py</summary>
```python
{!> docs_src/getting_started/nats_n_fastapi/my_fastagency_app/my_fastagency_app/workflow.py !}
{!> docs_src/getting_started/no_auth/nats_n_fastapi/my_fastagency_app/my_fastagency_app/workflow.py !}
```
</details>

<details>
<summary>main_1_nats.py</summary>
```python
{!> docs_src/getting_started/nats_n_fastapi/my_fastagency_app/my_fastagency_app/deployment/main_1_nats.py !}
{!> docs_src/getting_started/no_auth/nats_n_fastapi/my_fastagency_app/my_fastagency_app/deployment/main_1_nats.py !}
```
</details>

<details>
<summary>main_2_fastapi.py</summary>
```python
{!> docs_src/getting_started/nats_n_fastapi/my_fastagency_app/my_fastagency_app/deployment/main_2_fastapi.py !}
{!> docs_src/getting_started/no_auth/nats_n_fastapi/my_fastagency_app/my_fastagency_app/deployment/main_2_fastapi.py !}
```
</details>

<details>
<summary>main_3_mesop.py</summary>
```python
{!> docs_src/getting_started/nats_n_fastapi/my_fastagency_app/my_fastagency_app/deployment/main_3_mesop.py !}
{!> docs_src/getting_started/no_auth/nats_n_fastapi/my_fastagency_app/my_fastagency_app/deployment/main_3_mesop.py !}
```
</details>

Expand All @@ -254,28 +254,28 @@ Please copy and paste the following code into the same folder, using the file na
<details>
<summary>nats_server.conf</summary>
```python
{!> docs_src/getting_started/nats_n_fastapi/my_fastagency_app/.devcontainer/nats_server.conf !}
{!> docs_src/getting_started/no_auth/nats_n_fastapi/my_fastagency_app/.devcontainer/nats_server.conf !}
```
</details>

<details>
<summary>workflow.py</summary>
```python
{!> docs_src/getting_started/nats_n_fastapi/my_fastagency_app/my_fastagency_app/workflow.py !}
{!> docs_src/getting_started/no_auth/nats_n_fastapi/my_fastagency_app/my_fastagency_app/workflow.py !}
```
</details>

<details>
<summary>main_1_nats.py</summary>
```python
{!> docs_src/getting_started/nats_n_fastapi/my_fastagency_app/my_fastagency_app/deployment/main_1_nats.py !}
{!> docs_src/getting_started/no_auth/nats_n_fastapi/my_fastagency_app/my_fastagency_app/deployment/main_1_nats.py !}
```
</details>

<details>
<summary>main_2_fastapi_custom_client.py</summary>
```python
{!> docs_src/getting_started/nats_n_fastapi/main_2_fastapi_custom_client.py !}
{!> docs_src/getting_started/no_auth/nats_n_fastapi/main_2_fastapi_custom_client.py !}
```
</details>

Expand Down
Loading

0 comments on commit 6403b84

Please sign in to comment.