ffreemt
commited on
Commit
·
33c1ed4
1
Parent(s):
2493442
Update
Browse files
app.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
# pylint: disable=line-too-long, missing-module-docstring, missing-function-docstring,broad-exception-caught, too-many-statements
|
| 2 |
|
| 3 |
import json
|
| 4 |
-
|
| 5 |
import os
|
| 6 |
import re
|
| 7 |
import time
|
| 8 |
from datetime import datetime, timedelta
|
|
|
|
| 9 |
|
| 10 |
import requests
|
| 11 |
|
|
@@ -73,7 +73,7 @@ def fetch_tokens():
|
|
| 73 |
},
|
| 74 |
)
|
| 75 |
cache["app_session"] = session.cookies.get("appSession")
|
| 76 |
-
cache["app_session_time"] = datetime.now()
|
| 77 |
|
| 78 |
# 检查并获取 accessToken
|
| 79 |
if (
|
|
@@ -89,7 +89,7 @@ def fetch_tokens():
|
|
| 89 |
logger.error("Failed to get access token")
|
| 90 |
return None
|
| 91 |
cache["access_token"] = response.json().get("accessToken")
|
| 92 |
-
cache["access_token_time"] = datetime.now()
|
| 93 |
|
| 94 |
y(cache)
|
| 95 |
|
|
@@ -98,13 +98,14 @@ def fetch_tokens():
|
|
| 98 |
|
| 99 |
@app.route("/")
|
| 100 |
def landing():
|
| 101 |
-
return
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
or
|
| 105 |
-
curl -XPOST [127.0.0.1:7860|hf space url]/hf/v1/chat/completions -H "Authorization: Bearer Your_AUTHKEY" -H "Content-Type: application/json" --data "{\"model\": \"gpt-3.5-turbo\", \"messages\": [{\"role\": \"user\", \"content\": \"Say this is a test!\"}]}"
|
| 106 |
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
|
| 110 |
@app.route("/hf/v1/chat/completions", methods=["POST", "OPTIONS"])
|
|
@@ -138,8 +139,8 @@ def chat_completions():
|
|
| 138 |
logger.error(f"Error parsing JSON body: {e}")
|
| 139 |
return Response("Error parsing JSON body", status=400)
|
| 140 |
|
| 141 |
-
messages = request_body.get("messages", [])
|
| 142 |
-
model = request_body.get("model", "reka-core")
|
| 143 |
|
| 144 |
conversation_history = [
|
| 145 |
{
|
|
|
|
| 1 |
# pylint: disable=line-too-long, missing-module-docstring, missing-function-docstring,broad-exception-caught, too-many-statements
|
| 2 |
|
| 3 |
import json
|
|
|
|
| 4 |
import os
|
| 5 |
import re
|
| 6 |
import time
|
| 7 |
from datetime import datetime, timedelta
|
| 8 |
+
from textwrap import dedent
|
| 9 |
|
| 10 |
import requests
|
| 11 |
|
|
|
|
| 73 |
},
|
| 74 |
)
|
| 75 |
cache["app_session"] = session.cookies.get("appSession")
|
| 76 |
+
cache["app_session_time"] = datetime.now() # type: ignore
|
| 77 |
|
| 78 |
# 检查并获取 accessToken
|
| 79 |
if (
|
|
|
|
| 89 |
logger.error("Failed to get access token")
|
| 90 |
return None
|
| 91 |
cache["access_token"] = response.json().get("accessToken")
|
| 92 |
+
cache["access_token_time"] = datetime.now() # type: ignore
|
| 93 |
|
| 94 |
y(cache)
|
| 95 |
|
|
|
|
| 98 |
|
| 99 |
@app.route("/")
|
| 100 |
def landing():
|
| 101 |
+
return dedent(
|
| 102 |
+
"""
|
| 103 |
+
query /hf/v1/chat/completions for a spin, e.g. curl -XPOST 127.0.0.1:7860/hf/v1/chat/completions -H "Authorization: Bearer Your_AUTHKEY"
|
|
|
|
|
|
|
| 104 |
|
| 105 |
+
or
|
| 106 |
+
curl -XPOST [127.0.0.1:7860 | hf-space-url(e.g. https://mikeee-reka.hf.space)]/hf/v1/chat/completions -H "Authorization: Bearer Your_AUTHKEY" -H "Content-Type: application/json" --data "{\"model\": \"gpt-3.5-turbo\", \"messages\": [{\"role\": \"user\", \"content\": \"Say this is a test!\"}]}"
|
| 107 |
+
"""
|
| 108 |
+
)
|
| 109 |
|
| 110 |
|
| 111 |
@app.route("/hf/v1/chat/completions", methods=["POST", "OPTIONS"])
|
|
|
|
| 139 |
logger.error(f"Error parsing JSON body: {e}")
|
| 140 |
return Response("Error parsing JSON body", status=400)
|
| 141 |
|
| 142 |
+
messages = request_body.get("messages", []) # type: ignore
|
| 143 |
+
model = request_body.get("model", "reka-core") # type: ignore
|
| 144 |
|
| 145 |
conversation_history = [
|
| 146 |
{
|