Spaces:
Sleeping
Sleeping
Merge pull request #3 from east-and-west-magic/feature-log-username
Browse files- app.py +7 -7
- extract.py +9 -24
app.py
CHANGED
|
@@ -42,9 +42,9 @@ def run(hf_token, service, game, functionality, nlp_command):
|
|
| 42 |
"""
|
| 43 |
|
| 44 |
# reuse hf_token field as json string
|
| 45 |
-
token,
|
| 46 |
-
if
|
| 47 |
-
|
| 48 |
|
| 49 |
# redirect all traffic to the proxy sever
|
| 50 |
global ai
|
|
@@ -74,7 +74,7 @@ def run(hf_token, service, game, functionality, nlp_command):
|
|
| 74 |
else:
|
| 75 |
assert "games" in service_list
|
| 76 |
if service == "games":
|
| 77 |
-
print(f"{beijing()} [{
|
| 78 |
nlp_command = normalize_text(nlp_command)
|
| 79 |
call_pgai.from_cache = True
|
| 80 |
outp = call_pgai.call_pgai(
|
|
@@ -92,10 +92,10 @@ def run(hf_token, service, game, functionality, nlp_command):
|
|
| 92 |
# add proxy version info to the output
|
| 93 |
outp["timestamp"] = beijing().__str__()
|
| 94 |
outp["proxy-version"] = proxy_version
|
| 95 |
-
outp["user"] =
|
|
|
|
| 96 |
outp["game"] = game
|
| 97 |
-
|
| 98 |
-
outp["source"] = source
|
| 99 |
outp["cache"] = call_pgai.from_cache
|
| 100 |
app_util.call_logger(outp, identity, token)
|
| 101 |
service_end = beijing()
|
|
|
|
| 42 |
"""
|
| 43 |
|
| 44 |
# reuse hf_token field as json string
|
| 45 |
+
token, user, redirect, source, username, _ = extract(hf_token)
|
| 46 |
+
if user is None:
|
| 47 |
+
user = "__fake__"
|
| 48 |
|
| 49 |
# redirect all traffic to the proxy sever
|
| 50 |
global ai
|
|
|
|
| 74 |
else:
|
| 75 |
assert "games" in service_list
|
| 76 |
if service == "games":
|
| 77 |
+
print(f"{beijing()} [{user}] [{game}] {nlp_command}")
|
| 78 |
nlp_command = normalize_text(nlp_command)
|
| 79 |
call_pgai.from_cache = True
|
| 80 |
outp = call_pgai.call_pgai(
|
|
|
|
| 92 |
# add proxy version info to the output
|
| 93 |
outp["timestamp"] = beijing().__str__()
|
| 94 |
outp["proxy-version"] = proxy_version
|
| 95 |
+
outp["user"] = user
|
| 96 |
+
outp["username"] = username
|
| 97 |
outp["game"] = game
|
| 98 |
+
outp["source"] = source
|
|
|
|
| 99 |
outp["cache"] = call_pgai.from_cache
|
| 100 |
app_util.call_logger(outp, identity, token)
|
| 101 |
service_end = beijing()
|
extract.py
CHANGED
|
@@ -3,33 +3,18 @@ import json
|
|
| 3 |
|
| 4 |
def extract(hf_token):
|
| 5 |
"""
|
| 6 |
-
Extract token, user, redirect, source, and info from input hf_token.
|
| 7 |
If hf_token is simple, it is the token itself.
|
| 8 |
"""
|
| 9 |
info = {} # a copy of hf_token in json format
|
| 10 |
try:
|
| 11 |
-
info = json.loads(hf_token)
|
| 12 |
except json.decoder.JSONDecodeError:
|
| 13 |
-
return hf_token, None, None, None, None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
token = info["token"]
|
| 17 |
-
except KeyError:
|
| 18 |
-
token = None
|
| 19 |
-
|
| 20 |
-
try:
|
| 21 |
-
user = info["user"]
|
| 22 |
-
except KeyError:
|
| 23 |
-
user = None
|
| 24 |
-
|
| 25 |
-
try:
|
| 26 |
-
redirect = info["redirect"]
|
| 27 |
-
except KeyError:
|
| 28 |
-
redirect = None
|
| 29 |
-
|
| 30 |
-
try:
|
| 31 |
-
source = info["source"]
|
| 32 |
-
except KeyError:
|
| 33 |
-
source = None
|
| 34 |
-
|
| 35 |
-
return token, user, redirect, source, info
|
|
|
|
| 3 |
|
| 4 |
def extract(hf_token):
|
| 5 |
"""
|
| 6 |
+
Extract token, user, redirect, source, username and info from input hf_token.
|
| 7 |
If hf_token is simple, it is the token itself.
|
| 8 |
"""
|
| 9 |
info = {} # a copy of hf_token in json format
|
| 10 |
try:
|
| 11 |
+
info = dict(json.loads(hf_token))
|
| 12 |
except json.decoder.JSONDecodeError:
|
| 13 |
+
return hf_token, None, None, None, None,None
|
| 14 |
+
token = info.get("token", None)
|
| 15 |
+
user = info.get("user", None)
|
| 16 |
+
redirect = info.get("redirect", None)
|
| 17 |
+
source = info.get("source", None)
|
| 18 |
+
username = info.get("username", None)
|
| 19 |
|
| 20 |
+
return token, user, redirect, source, username, info
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|