Skip to content

Commit

Permalink
Merge branch '573-whatsapp-docs-is-broken---user-guideruntimesautogen…
Browse files Browse the repository at this point in the history
…whatsapp' of https://github.com/airtai/fastagency into 573-whatsapp-docs-is-broken---user-guideruntimesautogenwhatsapp
  • Loading branch information
sternakt committed Nov 13, 2024
2 parents 9dd0bcf + 8f13f3e commit 2f86c92
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 30 deletions.
39 changes: 21 additions & 18 deletions docs/docs/en/user-guide/cookiecutter/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,66 +18,69 @@ Cookiecutter creates projects from cookiecutters (project templates), e.g. Pytho

=== "Mesop"
```console
[1/4] project_name (My FastAgency App):
[2/4] project_slug (my_fastagency_app):
[3/4] Select app_type
[1/5] project_name (My FastAgency App):
[2/5] project_slug (my_fastagency_app):
[3/5] Select app_type
1 - fastapi+mesop
2 - mesop
3 - nats+fastapi+mesop
Choose from [1/2/3] (1): 2
[4/4] Select python_version
[4/5] Select python_version
1 - 3.12
2 - 3.11
3 - 3.10
Choose from [1/2/3] (1):
[5/5] Select authentication
1 - none
1 - basic
2 - google
Choose from [1/2] (1):
3 - none
Choose from [1/2/3] (1):
```

This command installs FastAgency with support for both the Console and Mesop interfaces for AutoGen workflows.

=== "FastAPI + Mesop"
```console
[1/4] project_name (My FastAgency App):
[2/4] project_slug (my_fastagency_app):
[3/4] Select app_type
[1/5] project_name (My FastAgency App):
[2/5] project_slug (my_fastagency_app):
[3/5] Select app_type
1 - fastapi+mesop
2 - mesop
3 - nats+fastapi+mesop
Choose from [1/2/3] (1): 1
[4/4] Select python_version
[4/5] Select python_version
1 - 3.12
2 - 3.11
3 - 3.10
Choose from [1/2/3] (1):
[5/5] Select authentication
1 - none
1 - basic
2 - google
Choose from [1/2] (1):
3 - none
Choose from [1/2/3] (1):
```

This command installs FastAgency with support for both the Console and Mesop interfaces for AutoGen workflows, with FastAPI handling input requests and workflow execution.

=== "NATS + FastAPI + Mesop"
```console
[1/4] project_name (My FastAgency App):
[2/4] project_slug (my_fastagency_app):
[3/4] Select app_type
[1/5] project_name (My FastAgency App):
[2/5] project_slug (my_fastagency_app):
[3/5] Select app_type
1 - fastapi+mesop
2 - mesop
3 - nats+fastapi+mesop
Choose from [1/2/3] (1): 3
[4/4] Select python_version
[4/5] Select python_version
1 - 3.12
2 - 3.11
3 - 3.10
Choose from [1/2/3] (1):
[5/5] Select authentication
1 - none
1 - basic
2 - google
Choose from [1/2] (1):
3 - none
Choose from [1/2/3] (1):
```

This command installs FastAgency with support for both the Console and Mesop interfaces for AutoGen workflows, with FastAPI serving input and independent workers communicating over the NATS.io protocol workflows. This is the most scable setup, recommended for large production workloads.
Expand Down
26 changes: 26 additions & 0 deletions docs/docs/en/user-guide/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,32 @@ In case we used network adapters in the step above, we can chain additional netw
{!> docs_src/getting_started/basic_auth/nats_n_fastapi/my_fastagency_app/my_fastagency_app/deployment/main_3_mesop.py !}
```

### Authentication

FastAgency provides three types of authentication mechanisms: [**Basic Authentication**](../../api/fastagency/ui/mesop/auth/basic_auth/BasicAuth.md), [**Firebase Authentication**](../../api/fastagency/ui/mesop/auth/firebase/FirebaseAuth.md) and no authentication (more will be added soon). The default authentication mechanism is [**Basic Authentication**](../../api/fastagency/ui/mesop/auth/basic_auth/BasicAuth.md). You can choose the type of authentication while setting up the project with Cookiecutter.

To use Basic Authentication, configure the desired usernames and their bcrypt hashed passwords in the BasicAuth class and apply the authentication object to the MesopUI object.

=== "Mesop"

!!! note "main.py"
```python
{!> docs_src/getting_started/basic_auth/mesop/my_fastagency_app/my_fastagency_app/deployment/main.py !}
```

=== "FastAPI + Mesop"

!!! note "main_2_mesop.py"
```python
{!> docs_src/getting_started/basic_auth/fastapi/my_fastagency_app/my_fastagency_app/deployment/main_2_mesop.py !}
```

=== "NATS + FastAPI + Mesop"

!!! note "main_3_mesop.py"
```python
{!> docs_src/getting_started/basic_auth/nats_n_fastapi/my_fastagency_app/my_fastagency_app/deployment/main_3_mesop.py !}
```

## Run Application Locally

Expand Down
21 changes: 12 additions & 9 deletions fastagency/ui/mesop/auth/firebase/firebase_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@


class FirebaseAuth: # implements AuthProtocol
SIGN_IN_MESSAGE = "Sign in to your account"
UN_AUTHORIZED_ERROR_MESSAGE = """You are not authorized to access this application. Please contact the application administrators for access."""

def __init__(
self,
sign_in_methods: list[Literal["google"]],
Expand Down Expand Up @@ -147,17 +150,16 @@ def on_auth_changed(self, e: mel.WebEvent) -> None:

if not firebase_auth_token:
state.authenticated_user = ""
state.auth_error = None
return

decoded_token = auth.verify_id_token(firebase_auth_token)

if not self.is_authorized(decoded_token):
raise me.MesopUserException(
"You are not authorized to access this application. "
"Please contact the application administrators for access."
)

state.authenticated_user = decoded_token["email"]
if self.is_authorized(decoded_token):
state.authenticated_user = decoded_token["email"]
state.auth_error = None
else:
state.authenticated_user = ""
state.auth_error = FirebaseAuth.UN_AUTHORIZED_ERROR_MESSAGE

# maybe me.Component is wrong
def auth_component(self) -> me.component:
Expand All @@ -171,7 +173,8 @@ def auth_component(self) -> me.component:
else:
with me.box(style=styles.login_box): # noqa: SIM117
with me.box(style=styles.login_btn_container):
me.text("Sign in to your account", style=styles.header_text)
message = state.auth_error or FirebaseAuth.SIGN_IN_MESSAGE
me.text(message, style=styles.header_text)
firebase_auth_component(
on_auth_changed=self.on_auth_changed, config=self.config
)
1 change: 1 addition & 0 deletions fastagency/ui/mesop/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ class State:
available_workflows_initialized = False
available_workflows_exception = False
authenticated_user: Optional[str] = None
auth_error: Optional[str] = None
6 changes: 3 additions & 3 deletions javascript/firebase_auth_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ class FirebaseAuthComponent extends LitElement {
></div>
<div
class="firebaseui-container firebaseui-page-provider-sign-in firebaseui-id-page-provider-sign-in firebaseui-use-spinner"
style="${this.isSignedIn ? "" : "display: none"}"
style="${this.isSignedIn ? "" : "display: none"} ; text-align:center"
>
<button
style="background-color:#ffffff"
class="firebaseui-idp-button mdl-button mdl-js-button mdl-button--raised firebaseui-idp-google firebaseui-id-idp-button"
style="background-color:#ffffff;margin-top:10px;"
class=" mdl-button mdl-js-button mdl-button--raised firebaseui-idp-google firebaseui-id-idp-button"
@click="${this.signOut}"
>
<span
Expand Down

0 comments on commit 2f86c92

Please sign in to comment.