Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
0xAlec committed Nov 4, 2024
1 parent d23d205 commit 0108cff
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions agent-frontend/api/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
load_dotenv()
app = Flask(__name__)

class InputValidationError(Exception):
"""Custom exception for input validation errors"""
pass

# Event types
EVENT_TYPE_AGENT = "agent"
EVENT_TYPE_COMPLETED = "completed"
Expand Down Expand Up @@ -116,7 +120,7 @@ def chat():
try:
data = request.get_json()
if not data or 'input' not in data:
raise Exception('Input must be provided')
raise InputValidationError('Input must be provided')

return Response(
stream_with_context(run_inference(data['input'])),
Expand All @@ -128,8 +132,11 @@ def chat():
'X-Accel-Buffering': 'no'
}
)
except InputValidationError as e:
return jsonify({'error': 'Invalid request: Missing required input'}), 400
except Exception as e:
return jsonify({'error': f'Invalid request: {str(e)}'}), 400
app.logger.error(f"Unexpected error in chat endpoint: {str(e)}")
return jsonify({'error': 'An unexpected error occurred'}), 500

if __name__ == "__main__":
app.run(port="5328")

0 comments on commit 0108cff

Please sign in to comment.