Coverage for e2e/llm-sans/main.py: 46%

37 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-19 12:16 +0000

1import os 

2from typing import Annotated, Any, Optional 

3 

4from autogen import register_function 

5from autogen.agentchat import ConversableAgent 

6 

7from fastagency import UI, FastAgency 

8from fastagency.runtimes.ag2 import Workflow 

9from fastagency.ui.mesop import MesopUI 

10 

11wf = Workflow() 

12 

13@wf.register(name="text_message", description="Text message test") 

14def many_multiple_choice_workflow( 

15 ui: UI, params: dict[str, Any] 

16) -> str: 

17 ui.text_message( 1a

18 sender="Workflow", 

19 recipient="User", 

20 body="text message body" 

21 ) 

22 return "Completed OK" # type: ignore[no-any-return] 1a

23 

24@wf.register(name="text_input_message", description="Text input message test") 

25def multiple_choice_single_workflow( 

26 ui: UI, params: dict[str, Any] 

27) -> str: 

28 answer = ui.text_input( 1a

29 sender="Workflow", 

30 recipient="User", 

31 prompt="Have you run any tests recently?" 

32 ) 

33 return answer # type: ignore[no-any-return] 1a

34 

35 

36@wf.register(name="multiple_choice_message_single", description="Multiple choice - single") 

37def multiple_choice_single_workflow( 

38 ui: UI, params: dict[str, Any] 

39) -> str: 

40 answer = ui.multiple_choice( 1a

41 sender="Workflow", 

42 recipient="User", 

43 prompt="When was the last time you have run automated tests?", 

44 choices=["I am currently running them", "yesterday", "Tests? What tests??"] 

45 ) 

46 return f"you have chosen: {answer}" # type: ignore[no-any-return] 1a

47 

48@wf.register(name="multiple_choice_message_many", description="Multiple choice - many") 

49def multiple_choice_many_workflow( 

50 ui: UI, params: dict[str, Any] 

51) -> str: 

52 answer = ui.multiple_choice( 1a

53 sender="Workflow", 

54 recipient="User", 

55 prompt="When was the last time you have run automated tests?", 

56 choices=["I am currently running them", "yesterday", "Tests? What tests??"], 

57 single=False 

58 ) 

59 return f"you have chosen: {answer}" # type: ignore[no-any-return] 1a

60 

61 

62@wf.register(name="suggested_function_call_message", description="Suggested Function Call Message") 

63def suggested_function_call_workflow( 

64 ui: UI, params: dict[str, Any] 

65) -> str: 

66 ui.suggested_function_call( 1a

67 sender="Workflow", 

68 recipient="User", 

69 function_name="the name of the function" 

70 ) 

71 return "Completed OK" # type: ignore[no-any-return] 1a

72 

73@wf.register(name="function_call_execution_message", description="Function Call Execution Message") 

74def function_call_execution( 

75 ui: UI, params: dict[str, Any] 

76) -> str: 

77 ui.function_call_execution( 1a

78 sender="Workflow", 

79 recipient="User", 

80 function_name="the name of the function" 

81 ) 

82 return "Completed OK" # type: ignore[no-any-return] 1a

83 

84@wf.register(name="error_message", description="Error Message") 

85def error_message( 

86 ui: UI, params: dict[str, Any] 

87) -> str: 

88 ui.error( 1a

89 sender="Workflow", 

90 recipient="User", 

91 short="This is an Error in short form", 

92 long="This is an Error in somewhat longer form" 

93 ) 

94 return "Completed OK" # type: ignore[no-any-return] 1a

95 

96@wf.register(name="workflow_started", description="test_wf_start") 

97def workflow_started( 

98 ui: UI, params: dict[str, Any] 

99) -> str: 

100 ui.workflow_started( 1a

101 sender="Workflow", 

102 recipient="User", 

103 name="_workflow_started_", 

104 description="The beginnings are delicate times...", 

105 ) 

106 return "Completed OK" # type: ignore[no-any-return] 1a

107 

108@wf.register(name="workflow_completed", description="Workflow completed") 

109def workflow_completed( 

110 ui: UI, params: dict[str, Any] 

111) -> str: 

112 ui.workflow_completed( 1a

113 sender="Workflow", 

114 recipient="User", 

115 result="This workflow has completed", 

116 ) 

117 return "Completed OK" # type: ignore[no-any-return] 1a

118 

119 

120app = FastAgency(provider=wf, ui=MesopUI(), title="Learning Chat")