Coverage for docs/docs_src/user_guide/ui/mesop/main_mesop_firebase_auth.py: 62%
16 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-19 12:16 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-19 12:16 +0000
1import os 1dabc
2from typing import Any 1dabc
4import mesop as me 1dabc
5from autogen import ConversableAgent, LLMConfig 1abc
7from fastagency import UI, FastAgency 1abc
8from fastagency.runtimes.ag2 import Workflow 1abc
9from fastagency.ui.mesop import MesopUI 1abc
10from fastagency.ui.mesop.auth.firebase import FirebaseAuth, FirebaseConfig 1abc
11from fastagency.ui.mesop.styles import ( 1abc
12 MesopHomePageStyles,
13 MesopMessagesStyles,
14 MesopSingleChoiceInnerStyles,
15)
17llm_config = LLMConfig( 1abc
18 model="gpt-4o-mini",
19 api_key=os.getenv("OPENAI_API_KEY"),
20 temperature=0.8,
21)
23wf = Workflow() 1abc
26@wf.register(name="simple_learning", description="Student and teacher learning chat") 1abc
27def simple_workflow( 1abc
28 ui: UI, params: dict[str, Any]
29) -> str:
30 initial_message = ui.text_input(
31 sender="Workflow",
32 recipient="User",
33 prompt="What do you want to learn today?",
34 )
36 with llm_config:
37 student_agent = ConversableAgent(
38 name="Student_Agent",
39 system_message="You are a student willing to learn.",
40 )
41 teacher_agent = ConversableAgent(
42 name="Teacher_Agent",
43 system_message="You are a math teacher.",
44 )
46 response = student_agent.run(
47 teacher_agent,
48 message=initial_message,
49 summary_method="reflection_with_llm",
50 max_turns=5,
51 )
53 return ui.process(response) # type: ignore[no-any-return]
56security_policy=me.SecurityPolicy(allowed_iframe_parents=["https://acme.com"], allowed_script_srcs=["https://cdn.jsdelivr.net"]) 1abc
58styles=MesopHomePageStyles( 1abc
59 stylesheets=[
60 "https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap"
61 ],
62 root=me.Style(
63 background="#e7f2ff",
64 height="100%",
65 font_family="Inter",
66 display="flex",
67 flex_direction="row",
68 ),
69 message=MesopMessagesStyles(
70 single_choice_inner=MesopSingleChoiceInnerStyles(
71 disabled_button=me.Style(
72 margin=me.Margin.symmetric(horizontal=8),
73 padding=me.Padding.all(16),
74 border_radius=8,
75 background="#64b5f6",
76 color="#fff",
77 font_size=16,
78 ),
79 )
80 ),
81)
83# TODO: replace this with your web app's Firebase configuration
84firebase_config = FirebaseConfig( 1abc
85 api_key="<your_firebase_api_key>",
86 auth_domain="<your_firebase_auth_domain>",
87 project_id="<your_firebase_project_id>",
88 storage_bucket="<your_firebase_storage_bucket>",
89 messaging_sender_id="<your_firebase_messaging_sender_id>",
90 app_id="<your_firebase_app_id>"
91)
93# Initialize auth with Google sign-in
94auth = FirebaseAuth( 1abc
95 sign_in_methods=["google"],
96 config=firebase_config,
97 # TODO: Replace the emails in allowed_users with the desired ones
98 allowed_users=["harish@ag2.ai", "davor@ag2.ai"]
99)
101ui = MesopUI(security_policy=security_policy, styles=styles, auth=auth) 1abc
103app = FastAgency(provider=wf, ui=ui, title="Learning Chat") 1abc