sujalrajpoot commited on
Commit
47aab37
·
verified ·
1 Parent(s): 69847f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -23
app.py CHANGED
@@ -2,7 +2,6 @@ from flask import Flask, request, jsonify
2
  import hmac, hashlib, secrets, time, os
3
  from openai import OpenAI
4
  import logging
5
- import datetime
6
 
7
  logging.basicConfig(level=logging.INFO)
8
  app = Flask(__name__)
@@ -16,13 +15,6 @@ client = OpenAI(base_url=endpoint,api_key=GITHUB_TOKEN)
16
  # Track API statistics
17
  request_count = 0
18
  start_time = time.time()
19
- # Store request counts and last reset time
20
- request_limits = {} # Tracks request count per API key
21
- last_reset_time = datetime.datetime.now() # Stores the last reset time
22
-
23
- # Set a request limit for a specific API key
24
- SPECIFIC_API_KEY = "TrueSyncAI-888d3e23fa5801834aa385118e05bd72-394215579bc4e6ac"
25
- MAX_REQUESTS = 10
26
 
27
  @app.route('/')
28
  def home():
@@ -97,21 +89,6 @@ def chat():
97
  if not api_key or not validate_api_key(api_key):
98
  return jsonify({"error": "Invalid API Key"}), 401
99
 
100
- # Check if 24 hours have passed, reset the limit
101
- current_time = datetime.datetime.now()
102
- if (current_time - last_reset_time).total_seconds() >= 86400: # 24 hours
103
- request_limits.clear() # Reset request count
104
- last_reset_time = current_time # Update last reset time
105
-
106
- # Check request limit for the specific API key
107
- if api_key == SPECIFIC_API_KEY:
108
- request_limits.setdefault(api_key, 0)
109
- if request_limits[api_key] >= MAX_REQUESTS:
110
- return jsonify({
111
- "error": "This is a test API key for developers to check the API status and functionality. It has a rate limit of 10 requests per day."
112
- }), 429
113
- request_limits[api_key] += 1 # Increment request count
114
-
115
  if not message:
116
  return jsonify({"error": "Message cannot be empty"}), 400
117
 
 
2
  import hmac, hashlib, secrets, time, os
3
  from openai import OpenAI
4
  import logging
 
5
 
6
  logging.basicConfig(level=logging.INFO)
7
  app = Flask(__name__)
 
15
  # Track API statistics
16
  request_count = 0
17
  start_time = time.time()
 
 
 
 
 
 
 
18
 
19
  @app.route('/')
20
  def home():
 
89
  if not api_key or not validate_api_key(api_key):
90
  return jsonify({"error": "Invalid API Key"}), 401
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  if not message:
93
  return jsonify({"error": "Message cannot be empty"}), 400
94