Spaces:
Sleeping
Sleeping
ffreemt
commited on
Commit
·
6f8b8b6
1
Parent(s):
69ddcdf
Fix
Browse files- duck2api_fwd.py +20 -1
duck2api_fwd.py
CHANGED
@@ -1,8 +1,11 @@
|
|
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 threading import Thread
|
7 |
|
8 |
import requests
|
@@ -22,6 +25,19 @@ y.configure(sln=1)
|
|
22 |
app = Flask(__name__)
|
23 |
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
@app.route("/hf/v1/chat/completions", methods=["POST"])
|
26 |
def my_endpoint():
|
27 |
url = "https://api.anakin.ai/v1/apps/1344/chatbot/chat"
|
@@ -41,7 +57,10 @@ def my_endpoint():
|
|
41 |
}
|
42 |
|
43 |
# remove prefix /hf
|
44 |
-
|
|
|
|
|
|
|
45 |
|
46 |
try:
|
47 |
response = requests.post(url, headers=headers, json=request.json)
|
|
|
1 |
# https://linux.do/t/topic/120588/5
|
2 |
|
3 |
# flask 糊接口
|
4 |
+
#
|
5 |
# 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}"
|
6 |
|
7 |
+
# --data '{"model": "gpt-.5-turbo", "messages": [{"role": "user", "content": "Say this is a test!"}], "stream": false}'
|
8 |
+
|
9 |
from threading import Thread
|
10 |
|
11 |
import requests
|
|
|
25 |
app = Flask(__name__)
|
26 |
|
27 |
|
28 |
+
@app.route("/", methods=["GET", "POST"])
|
29 |
+
def landing():
|
30 |
+
y(request.url)
|
31 |
+
y(request.path)
|
32 |
+
if request.path.startswith("/hf"):
|
33 |
+
url = f"http://127.0.0.1:8080{request.path[3:]}"
|
34 |
+
else:
|
35 |
+
url = f"http://127.0.0.1:8080{request.path}"
|
36 |
+
|
37 |
+
response = requests.get(url)
|
38 |
+
return response.text
|
39 |
+
|
40 |
+
|
41 |
@app.route("/hf/v1/chat/completions", methods=["POST"])
|
42 |
def my_endpoint():
|
43 |
url = "https://api.anakin.ai/v1/apps/1344/chatbot/chat"
|
|
|
57 |
}
|
58 |
|
59 |
# remove prefix /hf
|
60 |
+
if request.path.startswith("/hf"):
|
61 |
+
url = f"http://127.0.0.1:8080{request.path[3:]}"
|
62 |
+
else:
|
63 |
+
url = f"http://127.0.0.1:8080{request.path}"
|
64 |
|
65 |
try:
|
66 |
response = requests.post(url, headers=headers, json=request.json)
|