ffreemt commited on
Commit
ffa1ff4
·
1 Parent(s): 931bd01
Files changed (2) hide show
  1. Dockerfile +1 -1
  2. duck2api_fwd.py +51 -0
Dockerfile CHANGED
@@ -37,4 +37,4 @@ RUN pip install --no-cache-dir -r requirements.txt
37
  EXPOSE 5000
38
 
39
  # CMD ["/app/duck2api"]
40
- CMD ["python", "app.py"]
 
37
  EXPOSE 5000
38
 
39
  # CMD ["/app/duck2api"]
40
+ CMD ["python", "duck2api_fwd.py"]
duck2api_fwd.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # https://linux.do/t/topic/120588/5
2
+
3
+ # flask 糊接口
4
+ # curl -sS --location http://127.0.0.1:5000/hf/v1/chat/completions -H "Content-Type: application/json" --data "{\"model\": \"gpt-.5-turbo\", \"messages\": [{\"role\": \"user\", \"content\": \"Say this is a test!\"}], \"stream\": false}"
5
+
6
+ from flask import Flask, request, jsonify
7
+ import requests
8
+ import time
9
+ from ycecream import y
10
+
11
+ y.configure(sln=1)
12
+
13
+ app = Flask(__name__)
14
+
15
+ @app.route('/hf/v1/chat/completions', methods=['POST'])
16
+ def my_endpoint():
17
+ url = "https://api.anakin.ai/v1/apps/1344/chatbot/chat"
18
+ url = "http://127.0.0.1:8080/v1/chat/completions"
19
+ url = "http://acone:8080/v1/chat/completions"
20
+ url = "http://142.171.18.103:8080/v1/chat/completions"
21
+ # y(request)
22
+ # y(request.host)
23
+ # y(request.host_url)
24
+ # y(request.path)
25
+ # y(request.full_path)
26
+ # y(request.json)
27
+ # y(dir(request))
28
+ headers = {
29
+ 'Content-Type': 'application/json',
30
+ # 'Authorization': 'Bearer ANAKINAI_API_ACCESS_TOKEN'
31
+ }
32
+
33
+ url = f"http://142.171.18.103:8080{request.path[3:]}"
34
+
35
+ try:
36
+ response = requests.post(url, headers=headers, json=request.json)
37
+ except Exception as exc:
38
+ y(exc)
39
+ err_msg = str(exc)
40
+ # raise
41
+
42
+ y(response.json())
43
+
44
+ if response.status_code == 200:
45
+ return jsonify(response.json())
46
+
47
+ return jsonify({"error": {"message": f"An error occurred: {err_msg}", "type": "server_error", "code": 500}})
48
+
49
+
50
+ if __name__ == '__main__':
51
+ app.run(port=5000)