sujalrajpoot commited on
Commit
c338f24
·
verified ·
1 Parent(s): 53ab4bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -1,12 +1,15 @@
1
  from flask import Flask, request, jsonify
2
  import hmac, hashlib, secrets, time
3
- import requests
4
  import os
5
 
6
  app = Flask(__name__)
7
 
8
  # 🔑 Secret key for API authentication (Load from environment in production)
9
  SECRET_KEY = os.getenv("SECRET_KEY")
 
 
 
10
 
11
  # Track API statistics
12
  request_count = 0
@@ -51,16 +54,13 @@ def validate_api_key(api_key):
51
  return expected_signature == received_signature
52
 
53
  def generate_response(query:str) -> str:
54
- json_data = {'model': 'meta-llama/Llama-3.3-70B-Instruct-Turbo', 'messages': [{'role': 'system', 'content': 'You are TrueSyncAI, a pioneering AI startup founded by Sujal Rajpoot and Anuj Rajpoot. As TrueSyncAI, you are designed to be intelligent, engaging, and helpful in conversations. You should provide insightful, accurate, concise 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. Always ensure clarity, relevance, concise 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}
 
 
55
  try:
56
- response = requests.post(
57
- 'https://api.deepinfra.com/v1/openai/chat/completions',
58
- json=json_data, timeout=None
59
- )
60
- response.raise_for_status()
61
- 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.")
62
- except requests.exceptions.RequestException as e:
63
- return f"API Server is under maintenance. Please Try After Some Time Thank You for using TrueSyncAI Chat API. Have a great day."
64
 
65
  # Chat Endpoint
66
  @app.route("/v1/chat/completions", methods=["POST"])
@@ -82,4 +82,4 @@ def chat():
82
  return jsonify({"response": response})
83
 
84
  if __name__ == "__main__":
85
- app.run(host="0.0.0.0", port=7860) # Hugging Face Spaces default port
 
1
  from flask import Flask, request, jsonify
2
  import hmac, hashlib, secrets, time
3
+ from openai import OpenAI
4
  import os
5
 
6
  app = Flask(__name__)
7
 
8
  # 🔑 Secret key for API authentication (Load from environment in production)
9
  SECRET_KEY = os.getenv("SECRET_KEY")
10
+ GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
11
+ endpoint = "https://models.inference.ai.azure.com"
12
+ client = OpenAI(base_url=endpoint,api_key=GITHUB_TOKEN)
13
 
14
  # Track API statistics
15
  request_count = 0
 
54
  return expected_signature == received_signature
55
 
56
  def generate_response(query:str) -> str:
57
+ model_name = "gpt-4o"
58
+ response = client.chat.completions.create(
59
+ messages=[{"role": "system","content": "You are TrueSyncAI, a pioneering AI startup founded by Sujal Rajpoot and Anuj Rajpoot. As TrueSyncAI, you are designed to be intelligent, engaging, and helpful in conversations. You should provide insightful, accurate, concise 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. Always ensure clarity, relevance, concise and accuracy in your responses, and align with TrueSyncAI’s vision of bridging the gap between virtual intelligence and reality."},{"role": "user","content": query}],model=model_name,stream=False)
60
  try:
61
+ return response.choices[0].message.content
62
+ except:
63
+ return "API Server is under maintenance. Please Try After Some Time Thank You for using TrueSyncAI Chat API. Have a great day."
 
 
 
 
 
64
 
65
  # Chat Endpoint
66
  @app.route("/v1/chat/completions", methods=["POST"])
 
82
  return jsonify({"response": response})
83
 
84
  if __name__ == "__main__":
85
+ app.run(host="0.0.0.0", port=7860) # Hugging Face Spaces default port