@@ -119,20 +119,18 @@ def invoke(self,agent,query: Union[str, List[Dict[str, str]]]) -> str:
119
119
"""Evaluate and refine model responses based on entropy and coherence."""
120
120
best_score , best_response = float ('-inf' ), None
121
121
plateau_count = 0
122
- res = ""
123
- start_time = time .time ()
122
+
124
123
for i in tqdm (range (agent .max_iterations ), desc = "Iterations" ):
125
124
126
125
initial_response = self .generate (agent ,agent .generator_llm ,query )
127
- res += f"Initial Response: \n { initial_response } \n \n "
126
+
128
127
critique_comments = self .critique (agent ,agent .critique_llm ,initial_response , query )
129
- res += f"Critique_comments: \n { critique_comments } \n \n "
128
+
130
129
revised_response = self .refine_response (agent ,agent .generator_llm ,initial_response , critique_comments )
131
- res += f"Revised Response: \n { critique_comments } \n \n "
130
+
132
131
metrics = self .calculate_metrics (revised_response )
133
132
current_score = self ._calculate_composite_score (agent ,metrics )
134
- res += f"Metrics:\n \n { metrics } \n \n "
135
- res += f"Score:\n \n { current_score } \n \n "
133
+
136
134
logger .info (f"Epoch { i + 1 } - Metrics: { metrics } " )
137
135
138
136
if current_score > best_score + agent .entropy_threshold :
@@ -161,11 +159,11 @@ def update_chat_history(self,agent,query:Union[str, List[Dict[str, str]]]):
161
159
user_msg = UserMessage (content = agent .system_prompt .format (query = query [- 1 ]["content" ]))
162
160
query [- 1 ]= user_msg
163
161
agent .messages .extend (query )
164
- # return agent.messages
162
+
165
163
166
164
def generate (self , agent ,llm ,query : Union [str , List [Dict [str , str ]]]) -> str :
167
165
"""Generate response for a given query using the provided LLM"""
168
- # agent.messages=self.update_chat_history(agent,query)
166
+
169
167
self .update_chat_history (agent ,query )
170
168
messages = [{"role" : msg .role , "content" : msg .content } for msg in agent .messages ]
171
169
res = llm .invoke (messages )
@@ -179,7 +177,7 @@ def critique(self, agent,llm,response: str, original_query: Union[str, List[Dict
179
177
# mathematical critique and prompt critique are two different
180
178
"""Generate critique comments for the response balancing completeness and conciseness."""
181
179
if isinstance (original_query ,UserMessage ):
182
- print ( "user msg" )
180
+
183
181
original_query = original_query [- 1 ].content
184
182
elif isinstance (original_query , list ) and all (isinstance (msg , dict ) for msg in original_query ):
185
183
original_query = original_query [- 1 ]["content" ]
0 commit comments