2828from setting .models_provider .tools import get_model_instance_by_model_user_id
2929
3030
31- def add_access_num (client_id = None , client_type = None ):
32- if client_type == AuthenticationType .APPLICATION_ACCESS_TOKEN .value :
33- application_public_access_client = QuerySet (ApplicationPublicAccessClient ).filter (id = client_id ).first ()
31+ def add_access_num (client_id = None , client_type = None , application_id = None ):
32+ if client_type == AuthenticationType .APPLICATION_ACCESS_TOKEN .value and application_id is not None :
33+ application_public_access_client = (QuerySet (ApplicationPublicAccessClient ).filter (client_id = client_id ,
34+ application_id = application_id )
35+ .first ())
3436 if application_public_access_client is not None :
3537 application_public_access_client .access_num = application_public_access_client .access_num + 1
3638 application_public_access_client .intraday_access_num = application_public_access_client .intraday_access_num + 1
@@ -90,14 +92,14 @@ def event_content(response,
9092 request_token , response_token ,
9193 {'node_is_end' : True , 'view_type' : 'many_view' ,
9294 'node_type' : 'ai-chat-node' })
93- add_access_num (client_id , client_type )
95+ add_access_num (client_id , client_type , manage . context . get ( 'application_id' ) )
9496 except Exception as e :
9597 logging .getLogger ("max_kb_error" ).error (f'{ str (e )} :{ traceback .format_exc ()} ' )
9698 all_text = '异常' + str (e )
9799 write_context (step , manage , 0 , 0 , all_text )
98100 post_response_handler .handler (chat_id , chat_record_id , paragraph_list , problem_text ,
99101 all_text , manage , step , padding_problem_text , client_id )
100- add_access_num (client_id , client_type )
102+ add_access_num (client_id , client_type , manage . context . get ( 'application_id' ) )
101103 yield manage .get_base_to_response ().to_stream_chunk_response (chat_id , str (chat_record_id ), all_text ,
102104 'ai-chat-node' ,
103105 [], True , 0 , 0 ,
@@ -241,7 +243,7 @@ def execute_block(self, message_list: List[BaseMessage],
241243 write_context (self , manage , request_token , response_token , chat_result .content )
242244 post_response_handler .handler (chat_id , chat_record_id , paragraph_list , problem_text ,
243245 chat_result .content , manage , self , padding_problem_text , client_id )
244- add_access_num (client_id , client_type )
246+ add_access_num (client_id , client_type , manage . context . get ( 'application_id' ) )
245247 return manage .get_base_to_response ().to_block_response (str (chat_id ), str (chat_record_id ),
246248 chat_result .content , True ,
247249 request_token , response_token )
@@ -250,6 +252,6 @@ def execute_block(self, message_list: List[BaseMessage],
250252 write_context (self , manage , 0 , 0 , all_text )
251253 post_response_handler .handler (chat_id , chat_record_id , paragraph_list , problem_text ,
252254 all_text , manage , self , padding_problem_text , client_id )
253- add_access_num (client_id , client_type )
255+ add_access_num (client_id , client_type , manage . context . get ( 'application_id' ) )
254256 return manage .get_base_to_response ().to_block_response (str (chat_id ), str (chat_record_id ), all_text , True , 0 ,
255257 0 , _status = status .HTTP_500_INTERNAL_SERVER_ERROR )
0 commit comments