sujalrajpoot commited on
Commit
d7f4cf1
·
verified ·
1 Parent(s): 35322fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -1
app.py CHANGED
@@ -1,5 +1,6 @@
1
  from flask import Flask, request, jsonify
2
  import hmac, hashlib, secrets, time
 
3
 
4
  app = Flask(__name__)
5
 
@@ -30,6 +31,14 @@ def validate_api_key(api_key):
30
  expected_signature = hmac.new(SECRET_KEY.encode(), random_part.encode(), hashlib.sha256).hexdigest()[:16]
31
  return expected_signature == received_signature and api_key in API_KEYS
32
 
 
 
 
 
 
 
 
 
33
  # Chat Endpoint
34
  @app.route("/chat", methods=["POST"])
35
  def chat():
@@ -44,7 +53,7 @@ def chat():
44
  return jsonify({"error": "Message cannot be empty"}), 400
45
 
46
  # Basic AI response (Can integrate LLMs here)
47
- response = f"TrueSyncAI: You said '{message}', but I'm still learning!"
48
  return jsonify({"response": response})
49
 
50
  if __name__ == "__main__":
 
1
  from flask import Flask, request, jsonify
2
  import hmac, hashlib, secrets, time
3
+ import requests
4
 
5
  app = Flask(__name__)
6
 
 
31
  expected_signature = hmac.new(SECRET_KEY.encode(), random_part.encode(), hashlib.sha256).hexdigest()[:16]
32
  return expected_signature == received_signature and api_key in API_KEYS
33
 
34
+ def generate_response(query:str) -> str:
35
+ json_data = {'model': 'meta-llama/Llama-3.3-70B-Instruct-Turbo', 'messages': [{'role': 'system', 'content': 'You are TrueSyncAI, an advanced AI assistant developed by TrueSyncAI, a pioneering AI startup founded by Sujal Rajpoot and Anuj Rajpoot. The mission of TrueSyncAI is to bring virtual versions of individuals into the real world, redefining human-AI interaction. \n\nAs TrueSyncAI, you are designed to be intelligent, engaging, and helpful in conversations. You should provide insightful, accurate, and context-aware responses while maintaining a friendly and professional tone. Your goal is to enhance the user’s experience by adapting to their needs, assisting with various tasks, and learning from interactions to improve over time. \n\nAlways ensure clarity, relevance, and accuracy in your responses, and align with TrueSyncAI’s vision of bridging the gap between virtual intelligence and reality.'}, {'role': 'user', 'content': query}], 'stream': False, 'max_tokens': 2048, 'temperature': 0.7, 'top_p': 0.7}
36
+ response = requests.post('https://api.deepinfra.com/v1/openai/chat/completions',
37
+ json=json_data, timeout=None)
38
+ if response.status_code==200:
39
+ return response.json()['choices'][0]['message']['content']
40
+ else:return "API Server is under maintenance. Please Try After Some Time Thank You for using TrueSyncAI Chat API. Have a great day."
41
+
42
  # Chat Endpoint
43
  @app.route("/chat", methods=["POST"])
44
  def chat():
 
53
  return jsonify({"error": "Message cannot be empty"}), 400
54
 
55
  # Basic AI response (Can integrate LLMs here)
56
+ response = generate_response(message)
57
  return jsonify({"response": response})
58
 
59
  if __name__ == "__main__":