Spaces:
Sleeping
Sleeping
| """ what it does : | |
| is that Stores different API failure scenarios. | |
| When the agent starts a new episode, | |
| this file picks a random failure for the agent to debug. | |
| """ | |
| import random | |
| INCIDENTS =[ # here we created mutiple incidents and in different episodes different incidents will be checked | |
| { | |
| "type": "auth_error", | |
| "summary": "401 Unnathorized - API key expired", | |
| "logs": ["ERROR : there is inavlid API key", "HINT : your key expired already "], | |
| "fix_action": "refresh_token", | |
| "code":401 | |
| }, | |
| { | |
| "type": "missing_fields", | |
| "summary": "400 bad request - email field is missing please check", | |
| "logs": ["ERROR :Required field 'email' cannot be found" , "HINT : please add email to the request body "], | |
| "fix_action": "add_field", | |
| "code":400 | |
| }, | |
| { | |
| "type": "rate_limit", | |
| "summary": "429 too many requests - slow down ", | |
| "logs": ["ERROR : the rate limit is exceeded " , "HINT : please wait for 1 minute before retrying "], | |
| "fix_action": "wait_retry", | |
| "code":429 | |
| }, | |
| { | |
| "type": "wrong_endpoint", | |
| "summary": "404 Not Found - API endpoint doesn't exist", | |
| "logs": ["ERROR: POST /api/v2/data returned 404", "Hint: Use /api/v3/data instead"], | |
| "fix_action": "change_endpoint", | |
| "code": 404 | |
| }, | |
| { | |
| "type": "server_error", | |
| "summary": "500 Internal Server Error", | |
| "logs": ["ERROR: Database connection failed", "Hint: Cannot fix automatically - escalate"], | |
| "fix_action": "escalate", | |
| "code": 500 | |
| }, | |
| { | |
| "type": "timeout", | |
| "summary": "request took too long", | |
| "logs": ["ERROR : request timed out after 45 seconds", "Hint: server may be overloaded , please try again with backoff"], | |
| "fix_action": "wait_retry", | |
| "code": 408 | |
| }, | |
| ] | |
| def get_random_incident(): | |
| # this function is to return a random choice | |
| return random.choice(INCIDENTS) | |
| def get_incident_by_type(incident_type): | |
| # Returns a specific incident - useful for grading system (score/marks/points) | |
| for incident in INCIDENTS: # here we are having a loop | |
| if incident["type"] == incident_type: # we chechking here if type matches or not | |
| return incident | |
| return None | |