Spaces:
Sleeping
Sleeping
File size: 1,648 Bytes
ffa1ff4 6ec79ba ffa1ff4 6ec79ba ffa1ff4 6ec79ba ffa1ff4 6ec79ba ffa1ff4 6ec79ba ffa1ff4 6ec79ba ffa1ff4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# https://linux.do/t/topic/120588/5
# flask 糊接口
# 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}"
from threading import Thread
import requests
from flask import Flask, jsonify, request
from ycecream import y
from python_run_cmd import run_cmd
def run_duck2api():
run-cmd("./duck2api")
Thread(target=run_duck2api).start()
y.configure(sln=1)
app = Flask(__name__)
@app.route("/hf/v1/chat/completions", methods=["POST"])
def my_endpoint():
url = "https://api.anakin.ai/v1/apps/1344/chatbot/chat"
url = "http://127.0.0.1:8080/v1/chat/completions"
url = "http://acone:8080/v1/chat/completions"
url = "http://142.171.18.103:8080/v1/chat/completions"
# y(request)
# y(request.host)
# y(request.host_url)
# y(request.path)
# y(request.full_path)
# y(request.json)
# y(dir(request))
headers = {
"Content-Type": "application/json",
# 'Authorization': 'Bearer ANAKINAI_API_ACCESS_TOKEN'
}
url = f"http://142.171.18.103:8080{request.path[3:]}"
try:
response = requests.post(url, headers=headers, json=request.json)
except Exception as exc:
y(exc)
err_msg = str(exc)
# raise
y(response.json())
if response.status_code == 200:
return jsonify(response.json())
return jsonify({"error": {"message": f"An error occurred: {err_msg}", "type": "server_error", "code": 500}})
if __name__ == "__main__":
app.run(port=5000)
|