@@ -102,15 +102,17 @@ def react(self, user_query, user_instructions,):
102
102
hallucination_score = detect_response .hallucination ['score' ]
103
103
104
104
failed_instruction_counter = 0
105
+ ia_feedback = ""
105
106
## Loop to check for failed instructions
106
107
for x in detect_response .instruction_adherence ['results' ]:
107
108
if x ['adherence' ] == False :
108
109
failed_instruction_counter += 1
109
110
adherence = False
110
- break
111
+ ia_feedback += f"For the instruction { x [ 'instruction' ] } , the adherence detector evaluated that { x [ 'detailed_explanation' ] } ."
111
112
if failed_instruction_counter == 0 :
112
113
adherence = True
113
-
114
+ if ia_feedback == "" :
115
+ ia_feedback = "All the instructions were complied with."
114
116
## Baseline
115
117
result ['adherence' ].append (adherence )
116
118
result ['responses' ].append (generated_text )
@@ -122,7 +124,12 @@ def react(self, user_query, user_instructions,):
122
124
if self .react_configuration .hallucination_threshold > 0 and \
123
125
(hallucination_score > self .react_configuration .hallucination_threshold or failed_instruction_counter > 0 ):
124
126
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 )
126
133
127
134
context = self .context_extractor (user_query , user_instructions , llm_response )
128
135
@@ -138,16 +145,18 @@ def react(self, user_query, user_instructions,):
138
145
139
146
hallucination_score = detect_response .hallucination ['score' ]
140
147
141
-
148
+ ia_feedback = ""
142
149
failed_instruction_counter = 0
143
150
144
151
for x in detect_response .instruction_adherence ['results' ]:
145
152
if x ['adherence' ] == False :
146
153
failed_instruction_counter += 1
147
154
adherence = False
148
- break
155
+ ia_feedback += f"For the instruction { x [ 'instruction' ] } , the adherence detector evaluated that { x [ 'detailed_explanation' ] } ."
149
156
if failed_instruction_counter == 0 :
150
157
adherence = True
158
+ if ia_feedback == "" :
159
+ ia_feedback = "All the instructions were complied with."
151
160
152
161
result ['adherence' ].append (adherence )
153
162
result ['responses' ].append (generated_text )
0 commit comments