sujalrajpoot commited on
Commit
030b814
·
verified ·
1 Parent(s): 12b443d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -32,12 +32,16 @@ def validate_api_key(api_key):
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"])
@@ -57,4 +61,4 @@ def chat():
57
  return jsonify({"response": response})
58
 
59
  if __name__ == "__main__":
60
- app.run(host="0.0.0.0", port=7860) # Hugging Face Spaces default port
 
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.2, 'top_p': 1}
36
+ try:
37
+ response = requests.post(
38
+ 'https://api.deepinfra.com/v1/openai/chat/completions',
39
+ json=json_data, timeout=None
40
+ )
41
+ response.raise_for_status()
42
+ return response.json().get('choices', [{}])[0].get('message', {}).get('content', "API Server is under maintenance. Please Try After Some Time Thank You for using TrueSyncAI Chat API. Have a great day.")
43
+ except requests.exceptions.RequestException as e:
44
+ return f"API Error: {str(e)}"
45
 
46
  # Chat Endpoint
47
  @app.route("/chat", methods=["POST"])
 
61
  return jsonify({"response": response})
62
 
63
  if __name__ == "__main__":
64
+ app.run(host="0.0.0.0", port=7860) # Hugging Face Spaces default port