Coverage for docs/docs_src/user_guide/ui/mesop/main_mesop.py: 57%
14 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.styles import ( 1abc
11 MesopHomePageStyles,
12 MesopMessagesStyles,
13 MesopSingleChoiceInnerStyles,
14)
16llm_config = LLMConfig( 1abc
17 model="gpt-4o-mini",
18 api_key=os.getenv("OPENAI_API_KEY"),
19 temperature=0.8,
20)
22wf = Workflow() 1abc
25@wf.register(name="simple_learning", description="Student and teacher learning chat") 1abc
26def simple_workflow( 1abc
27 ui: UI, params: dict[str, Any]
28) -> str:
29 initial_message = ui.text_input(
30 sender="Workflow",
31 recipient="User",
32 prompt="What do you want to learn today?",
33 )
35 with llm_config:
36 student_agent = ConversableAgent(
37 name="Student_Agent",
38 system_message="You are a student willing to learn.",
39 )
40 teacher_agent = ConversableAgent(
41 name="Teacher_Agent",
42 system_message="You are a math teacher.",
43 )
45 response = student_agent.run(
46 teacher_agent,
47 message=initial_message,
48 summary_method="reflection_with_llm",
49 max_turns=5,
50 )
52 return ui.process(response) # type: ignore[no-any-return]
55security_policy=me.SecurityPolicy(allowed_iframe_parents=["https://acme.com"], allowed_script_srcs=["https://cdn.jsdelivr.net"]) 1abc
57styles=MesopHomePageStyles( 1abc
58 stylesheets=[
59 "https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap"
60 ],
61 root=me.Style(
62 background="#e7f2ff",
63 height="100%",
64 font_family="Inter",
65 display="flex",
66 flex_direction="row",
67 ),
68 message=MesopMessagesStyles(
69 single_choice_inner=MesopSingleChoiceInnerStyles(
70 disabled_button=me.Style(
71 margin=me.Margin.symmetric(horizontal=8),
72 padding=me.Padding.all(16),
73 border_radius=8,
74 background="#64b5f6",
75 color="#fff",
76 font_size=16,
77 ),
78 )
79 ),
80)
82ui = MesopUI(security_policy=security_policy, styles=styles) 1abc
84app = FastAgency(provider=wf, ui=MesopUI(), title="Learning Chat") 1abc