Skip to content

Commit 3e1d479

Browse files
added support to include IAFeedback and LLMResponse in ReAct runs
1 parent 705eb5e commit 3e1d479

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

aimon/extensions/react.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,17 @@ def react(self, user_query, user_instructions,):
102102
hallucination_score = detect_response.hallucination['score']
103103

104104
failed_instruction_counter = 0
105+
ia_feedback = ""
105106
## Loop to check for failed instructions
106107
for x in detect_response.instruction_adherence['results']:
107108
if x['adherence'] == False:
108109
failed_instruction_counter+=1
109110
adherence = False
110-
break
111+
ia_feedback += f"For the instruction {x['instruction']}, the adherence detector evaluated that {x['detailed_explanation']}."
111112
if failed_instruction_counter == 0:
112113
adherence = True
113-
114+
if ia_feedback=="":
115+
ia_feedback="All the instructions were complied with."
114116
## Baseline
115117
result['adherence'].append(adherence)
116118
result['responses'].append(generated_text)
@@ -122,7 +124,12 @@ def react(self, user_query, user_instructions,):
122124
if self.react_configuration.hallucination_threshold > 0 and \
123125
(hallucination_score > self.react_configuration.hallucination_threshold or failed_instruction_counter>0):
124126

125-
llm_response = self.llm_app(user_query, user_instructions, reprompted_flag=True, hallucination_score=hallucination_score)
127+
llm_response = self.llm_app(user_query,
128+
user_instructions,
129+
reprompted_flag=True,
130+
last_llm_response = generated_text,
131+
hallucination_score=hallucination_score,
132+
ia_feedback = ia_feedback)
126133

127134
context = self.context_extractor(user_query, user_instructions, llm_response)
128135

@@ -138,16 +145,18 @@ def react(self, user_query, user_instructions,):
138145

139146
hallucination_score = detect_response.hallucination['score']
140147

141-
148+
ia_feedback = ""
142149
failed_instruction_counter = 0
143150

144151
for x in detect_response.instruction_adherence['results']:
145152
if x['adherence'] == False:
146153
failed_instruction_counter+=1
147154
adherence = False
148-
break
155+
ia_feedback += f"For the instruction {x['instruction']}, the adherence detector evaluated that {x['detailed_explanation']}."
149156
if failed_instruction_counter == 0:
150157
adherence = True
158+
if ia_feedback=="":
159+
ia_feedback="All the instructions were complied with."
151160

152161
result['adherence'].append(adherence)
153162
result['responses'].append(generated_text)

0 commit comments

Comments
 (0)