Beracles commited on
Commit
f950953
·
1 Parent(s): 9a51839

mark from cache or not

Browse files
Files changed (2) hide show
  1. app.py +4 -2
  2. call_ai.py +4 -0
app.py CHANGED
@@ -8,7 +8,7 @@ from extract import extract
8
  import app_util
9
  from pgsoft.pgconst.const import service_list, functionality_list, game_list
10
  from pgsoft.pgdate.date_utils import beijing
11
- from call_ai import call_ai
12
 
13
  #######################
14
  # proxy version
@@ -88,7 +88,8 @@ def run(hf_token, service, game, functionality, nlp_command):
88
  assert "games" in service_list
89
  if service == "games":
90
  print(f"{beijing()} [{user_name}] [{game}] {nlp_command}")
91
- outp = call_ai(
 
92
  service,
93
  game,
94
  functionality,
@@ -105,6 +106,7 @@ def run(hf_token, service, game, functionality, nlp_command):
105
  outp["game"] = game
106
  if source:
107
  outp["source"] = source
 
108
  app_util.call_logger(outp, identity, token)
109
  service_end = beijing()
110
  timecost = service_end.timestamp() - service_start.timestamp()
 
8
  import app_util
9
  from pgsoft.pgconst.const import service_list, functionality_list, game_list
10
  from pgsoft.pgdate.date_utils import beijing
11
+ import call_ai
12
 
13
  #######################
14
  # proxy version
 
88
  assert "games" in service_list
89
  if service == "games":
90
  print(f"{beijing()} [{user_name}] [{game}] {nlp_command}")
91
+ call_ai.from_cache = True
92
+ outp = call_ai.call_ai(
93
  service,
94
  game,
95
  functionality,
 
106
  outp["game"] = game
107
  if source:
108
  outp["source"] = source
109
+ outp["cache"] = call_ai.from_cache
110
  app_util.call_logger(outp, identity, token)
111
  service_end = beijing()
112
  timecost = service_end.timestamp() - service_start.timestamp()
call_ai.py CHANGED
@@ -3,6 +3,8 @@ from gradio_client import Client
3
  from pgsoft.pgdate.date_utils import beijing
4
  import json
5
 
 
 
6
 
7
  @cache
8
  def call_ai(service, game, functionality, nlp_command, url, hf_token):
@@ -30,4 +32,6 @@ def call_ai(service, game, functionality, nlp_command, url, hf_token):
30
  timecost = calling_end.timestamp() - calling_start.timestamp()
31
  print(f"calling ai ends at {calling_end}, costs {timecost:.2f}s")
32
  outp = json.loads(res)
 
 
33
  return outp
 
3
  from pgsoft.pgdate.date_utils import beijing
4
  import json
5
 
6
+ from_cache = True
7
+
8
 
9
  @cache
10
  def call_ai(service, game, functionality, nlp_command, url, hf_token):
 
32
  timecost = calling_end.timestamp() - calling_start.timestamp()
33
  print(f"calling ai ends at {calling_end}, costs {timecost:.2f}s")
34
  outp = json.loads(res)
35
+ global from_cache
36
+ from_cache = False
37
  return outp