MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / get_option

Method get_option

camel/agents/critic_agent.py:104–149  ·  view source on GitHub ↗

r"""Gets the option selected by the critic. Args: input_message (BaseMessage): A `BaseMessage` object representing the input message. Returns: str: The option selected by the critic.

(self, input_message: BaseMessage)

Source from the content-addressed store, hash-verified

102 return flatten_options + format
103
104 def get_option(self, input_message: BaseMessage) -> str:
105 r"""Gets the option selected by the critic.
106
107 Args:
108 input_message (BaseMessage): A `BaseMessage` object representing
109 the input message.
110
111 Returns:
112 str: The option selected by the critic.
113 """
114 # TODO: Add support for editing options by the critic.
115 msg_content = input_message.content
116 i = 0
117 while i < self.retry_attempts:
118 critic_response = self.step(input_message)
119
120 if critic_response.msgs is None or len(critic_response.msgs) == 0:
121 raise RuntimeError("Got None critic messages.")
122 if critic_response.terminated:
123 raise RuntimeError("Critic step failed.")
124
125 critic_msg = critic_response.msg
126 if self.verbose:
127 print_text_animated(
128 self.logger_color + "\n> Critic response: "
129 f"\x1b[3m{critic_msg.content}\x1b[0m\n"
130 )
131 choice = self.parse_critic(critic_msg)
132
133 if choice in self.options_dict:
134 return self.options_dict[choice]
135 else:
136 input_message = BaseMessage(
137 role_name=input_message.role_name,
138 role_type=input_message.role_type,
139 meta_dict=input_message.meta_dict,
140 content="> Invalid choice. Please choose again.\n"
141 + msg_content,
142 )
143 i += 1
144 warnings.warn(
145 "Critic failed to get a valid option. "
146 f"After {self.retry_attempts} attempts. "
147 "Returning a random option."
148 )
149 return random.choice(list(self.options_dict.values()))
150
151 def parse_critic(self, critic_msg: BaseMessage) -> Optional[str]:
152 r"""Parses the critic&#x27;s message and extracts the choice.

Callers 1

reduce_stepMethod · 0.95

Calls 4

parse_criticMethod · 0.95
print_text_animatedFunction · 0.90
BaseMessageClass · 0.90
stepMethod · 0.45

Tested by

no test coverage detected