Skip to content

Commit df8c1d7

Browse files
step detect_result
1 parent ff0ab6f commit df8c1d7

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

aimon/extensions/react.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ def create_payload(self, context, user_query, user_instructions, generated_text)
4242

4343
return aimon_payload
4444

45+
def detect_aimon_response(self,aimon_payload):
46+
47+
try:
48+
detect_response = self.client.inference.detect(body=[aimon_payload])
49+
# Check if the response is a list
50+
if isinstance(detect_response, list) and len(detect_response) > 0:
51+
detect_result = detect_response[0]
52+
elif isinstance(detect_response, dict):
53+
detect_result = detect_response # Single dict response
54+
else:
55+
raise ValueError("Unexpected response format from detect API: {}".format(detect_response))
56+
except Exception as e:
57+
# Log the error and raise it
58+
print(f"Error during detection: {e}")
59+
raise
60+
61+
return detect_result
4562

4663
## ReAct -> Reason and Act
4764
def react(self, user_query, user_instructions,):
@@ -58,9 +75,9 @@ def react(self, user_query, user_instructions,):
5875

5976
aimon_payload = self.create_payload(context, user_query, user_instructions, generated_text)
6077

61-
detect_response = self.client.inference.detect(body=[aimon_payload])
78+
detect_result = self.detect_aimon_response(aimon_payload)
6279

63-
return detect_response
80+
return detect_result
6481

6582
# for _ in range(self.react_configuration.max_attempts):
6683

0 commit comments

Comments
 (0)