tianlong12 commited on
Commit
364bda2
1 Parent(s): c5dd10a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -23,6 +23,7 @@ def format_openai_response(content, finish_reason=None):
23
  }
24
 
25
  @app.route('/hf/v1/chat/completions', methods=['POST'])
 
26
  def chat_completions():
27
  data = request.json
28
  messages = data.get('messages', [])
@@ -38,20 +39,30 @@ def chat_completions():
38
  conversation += "\n请关注并回复user最近的消息并避免总结对话历史的回答"
39
 
40
  model = data.get('model', 'gpt-4o')
 
 
 
 
 
 
 
 
41
 
42
  original_api_url = 'https://chatpro.ai-pro.org/api/ask/openAI'
 
43
  headers = {
44
  'content-type': 'application/json',
45
  'X-Forwarded-For': generate_random_ip(),
46
  'origin': 'https://chatpro.ai-pro.org',
47
  'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36'
48
  }
 
49
  payload = {
50
  "text": conversation,
51
- "endpoint": "openAI",
52
  "model": model
53
  }
54
-
55
  def generate():
56
  last_content = ""
57
  response = requests.post(original_api_url, headers=headers, json=payload, stream=True)
 
23
  }
24
 
25
  @app.route('/hf/v1/chat/completions', methods=['POST'])
26
+
27
  def chat_completions():
28
  data = request.json
29
  messages = data.get('messages', [])
 
39
  conversation += "\n请关注并回复user最近的消息并避免总结对话历史的回答"
40
 
41
  model = data.get('model', 'gpt-4o')
42
+
43
+ # 根据模型名称设置endpoint
44
+ if model.startswith('gpt'):
45
+ endpoint = "openAI"
46
+ elif model.startswith('claude'):
47
+ endpoint = "claude"
48
+ else:
49
+ return {"error": "Unsupported model"}, 400
50
 
51
  original_api_url = 'https://chatpro.ai-pro.org/api/ask/openAI'
52
+
53
  headers = {
54
  'content-type': 'application/json',
55
  'X-Forwarded-For': generate_random_ip(),
56
  'origin': 'https://chatpro.ai-pro.org',
57
  'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36'
58
  }
59
+
60
  payload = {
61
  "text": conversation,
62
+ "endpoint": endpoint,
63
  "model": model
64
  }
65
+
66
  def generate():
67
  last_content = ""
68
  response = requests.post(original_api_url, headers=headers, json=payload, stream=True)