ffreemt commited on
Commit
9942045
1 Parent(s): 3f431cf

Update .env PORT=8088

Browse files
Files changed (3) hide show
  1. .env +8 -0
  2. duck2api_fwd.py +19 -10
  3. requirements.txt +1 -0
.env ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ SERVER_HOST=127.0.0.1
2
+ SERVER_PORT=8088
3
+ FREE_ACCOUNTS=true
4
+ FREE_ACCOUNTS_NUM=1024
5
+ Authorization=
6
+ TLS_CERT=
7
+ TLS_KEY=
8
+ PROXY_URL=
duck2api_fwd.py CHANGED
@@ -1,5 +1,5 @@
1
- """
2
- # https://linux.do/t/topic/120588/5
3
 
4
  # flask 糊接口
5
  #
@@ -9,9 +9,12 @@
9
 
10
  curl https://mikeee-duck2api.hf.space/hf/v1/chat/completions -H "Content-Type: application/json" --data "{\"model\": \"gpt-3.5-turbo\", \"messages\": [{\"role\": \"user\", \"content\": \"Say this is a test!\"}], \"stream\": false}"
11
  """
 
 
12
  from threading import Thread
13
 
14
  import requests
 
15
  from flask import Flask, jsonify, request
16
  from python_run_cmd import run_cmd
17
  from ycecream import y
@@ -24,6 +27,13 @@ def run_duck2api():
24
  Thread(target=run_duck2api).start()
25
 
26
  y.configure(sln=1)
 
 
 
 
 
 
 
27
 
28
  app = Flask(__name__)
29
 
@@ -33,9 +43,9 @@ def landing():
33
  y(request.url)
34
  y(request.path)
35
  if request.path.startswith("/hf"):
36
- url = f"http://127.0.0.1:8080{request.path[3:]}"
37
  else:
38
- url = f"http://127.0.0.1:8080{request.path}"
39
 
40
  response = requests.get(url)
41
  return response.text
@@ -43,9 +53,9 @@ def landing():
43
 
44
  @app.route("/hf/v1/chat/completions", methods=["POST"])
45
  def my_endpoint():
46
- url = "https://api.anakin.ai/v1/apps/1344/chatbot/chat"
47
- url = "http://127.0.0.1:8080/v1/chat/completions"
48
- url = "http://acone:8080/v1/chat/completions"
49
 
50
  y(request)
51
  # y(request.host)
@@ -63,13 +73,12 @@ def my_endpoint():
63
  y(request.url)
64
  y(request.path)
65
  if request.path.startswith("/hf"):
66
- url = f"http://127.0.0.1:8080{request.path[3:]}"
67
  else:
68
- url = f"http://127.0.0.1:8080{request.path}"
69
 
70
  y(url)
71
 
72
-
73
  try:
74
  response = requests.post(url, headers=headers, json=request.json)
75
  except Exception as exc:
 
1
+ r"""
2
+ Refer to https://linux.do/t/topic/120588/5.
3
 
4
  # flask 糊接口
5
  #
 
9
 
10
  curl https://mikeee-duck2api.hf.space/hf/v1/chat/completions -H "Content-Type: application/json" --data "{\"model\": \"gpt-3.5-turbo\", \"messages\": [{\"role\": \"user\", \"content\": \"Say this is a test!\"}], \"stream\": false}"
11
  """
12
+
13
+ import os
14
  from threading import Thread
15
 
16
  import requests
17
+ from dotenv import load_dotenv
18
  from flask import Flask, jsonify, request
19
  from python_run_cmd import run_cmd
20
  from ycecream import y
 
27
  Thread(target=run_duck2api).start()
28
 
29
  y.configure(sln=1)
30
+ load_dotenv()
31
+
32
+ PORT = os.getenv("PORT")
33
+ if not PORT:
34
+ PORT = 8088
35
+
36
+ y(PORT)
37
 
38
  app = Flask(__name__)
39
 
 
43
  y(request.url)
44
  y(request.path)
45
  if request.path.startswith("/hf"):
46
+ url = f"http://127.0.0.1:{PORT}{request.path[3:]}"
47
  else:
48
+ url = f"http://127.0.0.1:{PORT}{request.path}"
49
 
50
  response = requests.get(url)
51
  return response.text
 
53
 
54
  @app.route("/hf/v1/chat/completions", methods=["POST"])
55
  def my_endpoint():
56
+ # url = "https://api.anakin.ai/v1/apps/1344/chatbot/chat"
57
+ # url = "http://acone:{PORT}/v1/chat/completions"
58
+ # url = f"http://127.0.0.1:{PORT}/v1/chat/completions"
59
 
60
  y(request)
61
  # y(request.host)
 
73
  y(request.url)
74
  y(request.path)
75
  if request.path.startswith("/hf"):
76
+ url = f"http://127.0.0.1:{PORT}{request.path[3:]}"
77
  else:
78
+ url = f"http://127.0.0.1:{PORT}{request.path}"
79
 
80
  y(url)
81
 
 
82
  try:
83
  response = requests.post(url, headers=headers, json=request.json)
84
  except Exception as exc:
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  flask
2
  ycecream
3
  requests
 
4
  python-run-cmd
 
1
  flask
2
  ycecream
3
  requests
4
+ python-dotenv
5
  python-run-cmd