Skip to content

Commit

Permalink
更新SDK log记录规则
Browse files Browse the repository at this point in the history
  • Loading branch information
yinjiaqi authored and yinjiaqi committed Dec 27, 2024
1 parent 7c0ffaf commit 4b2588f
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 177 deletions.
19 changes: 19 additions & 0 deletions python/core/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from requests.adapters import HTTPAdapter, Retry
from aiohttp import ClientResponse

from appbuilder.utils.logger_util import logger
from appbuilder import get_default_header

from appbuilder.core._exception import *
Expand Down Expand Up @@ -114,21 +115,30 @@ def check_response_header(response: requests.Response):
"""
status_code = response.status_code
if status_code == requests.codes.ok:
logger.debug("request_id={} , http status code is {} , response data is {}".format(
__class__.response_request_id(response), status_code, response.json()
))
return
message = "request_id={} , http status code is {}, body is {}".format(
__class__.response_request_id(response), status_code, response.text
)
if status_code == requests.codes.bad_request:
logger.error(message)
raise BadRequestException(message)
elif status_code == requests.codes.forbidden:
logger.error(message)
raise ForbiddenException(message)
elif status_code == requests.codes.not_found:
logger.error(message)
raise NotFoundException(message)
elif status_code == requests.codes.precondition_required:
logger.error(message)
raise PreconditionFailedException(message)
elif status_code == requests.codes.internal_server_error:
logger.error(message)
raise InternalServerErrorException(message)
else:
logger.error(message)
raise BaseRPCException(message)

def service_url(self, sub_path: str, prefix: str = None):
Expand Down Expand Up @@ -250,21 +260,30 @@ async def check_response_header(response: ClientResponse):
"""
status_code = response.status
if status_code == requests.codes.ok:
logger.debug("request_id={} , http status code is {} , response data is {}".format(
await __class__.response_request_id(response), status_code, await response.json()
))
return
message = "request_id={} , http status code is {}, body is {}".format(
await __class__.response_request_id(response), status_code, await response.text()
)
if status_code == requests.codes.bad_request:
logger.error(message)
raise BadRequestException(message)
elif status_code == requests.codes.forbidden:
logger.error(message)
raise ForbiddenException(message)
elif status_code == requests.codes.not_found:
logger.error(message)
raise NotFoundException(message)
elif status_code == requests.codes.precondition_required:
logger.error(message)
raise PreconditionFailedException(message)
elif status_code == requests.codes.internal_server_error:
logger.error(message)
raise InternalServerErrorException(message)
else:
logger.error(message)
raise BaseRPCException(message)

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion python/core/assistant/threads/runs/stream_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def __stream__(self) -> Iterator[Union[
process_res = self.__stream_event_process__(event)
yield process_res
except Exception as e:
logger.info(e)
logger.error(e)

def __stream_event_process__(self, event) -> Union[
thread_type.StreamRunStatus, thread_type.StreamRunMessage, dict]:
Expand Down
1 change: 0 additions & 1 deletion python/core/components/doc_format_converter/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

from appbuilder.core._exception import AppBuilderServerException, InvalidRequestArgumentError
from appbuilder.core.component import Component, Message
from appbuilder.utils.logger_util import logger
from appbuilder.core._client import HTTPClient
from appbuilder.core.components.doc_format_converter.model import DocFormatConverterInMessage, \
DocFormatConverterOutMessage, \
Expand Down
1 change: 0 additions & 1 deletion python/core/components/doc_splitter/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from appbuilder.core._exception import AppBuilderServerException
from appbuilder.core.components.doc_parser.base import ParseResult
from appbuilder.core.component import Component, Message, ComponentArguments
from appbuilder.utils.logger_util import logger
from appbuilder.core.components.doc_parser.base import DocSegment
from appbuilder.utils.trace.tracer_wrapper import components_run_trace, components_run_stream_trace

Expand Down
2 changes: 0 additions & 2 deletions python/core/components/extract_table/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import json

from appbuilder.core.component import Component, Message, ComponentArguments
from appbuilder.utils.logger_util import logger
from appbuilder.utils.trace.tracer_wrapper import components_run_trace, components_run_stream_trace


Expand Down Expand Up @@ -125,7 +124,6 @@ def run(self, message: Message, table_max_size: int = 800, doc_node_num_before_t
"field_before_table_cnt": doc_node_num_before_table
}
url = self.http_client.service_url(sub_path="", prefix=self.base_url)
# logger.info("request url: {}, headers: {}".format(url, headers))
headers = self.http_client.auth_header()
headers["Content-Type"] = "application/json"
resp = self.http_client.session.post(url=url, data=json.dumps(params), headers=headers)
Expand Down
12 changes: 0 additions & 12 deletions python/core/components/llms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,21 +430,9 @@ def completion(

stream = True if request.response_mode == "streaming" else False
url = self.http_client.service_url(completion_url, self.base_url)
logger.debug(
"request url: {}, method: {}, json: {}, headers: {}".format(url,
"POST",
request.params,
headers))
response = self.http_client.session.post(url, json=request.params, headers=headers, timeout=timeout,
stream=stream)

logger.debug(
"request url: {}, method: {}, json: {}, headers: {}, response: {}".format(url, "POST",
request.params,
headers,
response))
return self.gene_response(response, stream)

@staticmethod
def check_service_error(data: dict):
r"""check service internal error.
Expand Down
12 changes: 0 additions & 12 deletions python/core/components/llms/hallucination_detection/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from appbuilder.core.components.llms.base import CompletionBaseComponent, ModelArgsConfig
from appbuilder.core.message import Message
from appbuilder.core._exception import AppBuilderServerException
from appbuilder.utils.logger_util import logger
from appbuilder.utils.trace.tracer_wrapper import components_run_trace, components_run_stream_trace
from .base import HallucinationDetectionArgs

Expand Down Expand Up @@ -140,19 +139,8 @@ def completion(self, version, base_url, request, timeout: float = None,
stream = True if request.response_mode == "streaming" else False

url = self.http_client.service_url("/app/hallucination_detection", self.base_url)
logger.debug(
"request url: {}, method: {}, json: {}, headers: {}".format(url,
"POST",
request.params,
headers))
response = self.http_client.session.post(url, json=request.params, headers=headers, timeout=timeout,
stream=stream)

logger.debug(
"request url: {}, method: {}, json: {}, headers: {}, response: {}".format(url, "POST",
request.params,
headers,
response))
return self.gene_response(response, stream)

@components_run_trace
Expand Down
13 changes: 0 additions & 13 deletions python/core/components/llms/oral_query_generation/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from appbuilder.core.components.llms.base import CompletionBaseComponent, ModelArgsConfig
from appbuilder.core.message import Message
from appbuilder.core._exception import AppBuilderServerException
from appbuilder.utils.logger_util import logger
from appbuilder.utils.trace.tracer_wrapper import components_run_trace, components_run_stream_trace
from .base import OralQueryGenerationArgs

Expand Down Expand Up @@ -139,20 +138,8 @@ def completion(self, version, base_url, request, timeout: float = None,
stream = True if request.response_mode == "streaming" else False

url = self.http_client.service_url("/app/query_generation", self.base_url)

logger.debug(
"request url: {}, method: {}, json: {}, headers: {}".format(url,
"POST",
request.params,
headers))
response = self.http_client.session.post(url, json=request.params, headers=headers, timeout=timeout,
stream=stream)

logger.debug(
"request url: {}, method: {}, json: {}, headers: {}, response: {}".format(url, "POST",
request.params,
headers,
response))
return self.gene_response(response, stream)

@components_run_trace
Expand Down
36 changes: 0 additions & 36 deletions python/core/components/ppt_generation_from_file/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,10 @@ def ppt_generation(self,
url = self.http_client.service_url(self.ppt_generation_url, self.uniform_prefix)
headers = self.http_client.auth_header()
headers['Content-Type'] = 'application/json'

logger.debug('[ppt_generation] request url: {}, method: {}, json: {}, headers: {}'.format(
url,
'POST',
post_data,
headers
))
response = self.http_client.session.post(url,
json=post_data,
headers=headers,
timeout=timeout)
logger.debug('[ppt_generation] request url: {}, method: {}, json: {}, headers: {}, response: {}'.format(
url,
'POST',
post_data,
headers,
response
))
self.http_client.check_response_header(response)
resp_data = response.json()
if resp_data.get('code', None) != 200 or resp_data.get('msg', None) != 'success':
Expand Down Expand Up @@ -166,22 +152,11 @@ def get_ppt_generation_status(self,
headers = self.http_client.auth_header()
headers['Content-Type'] = 'application/json'

logger.debug('[get_ppt_generation_status] request url: {}, method: {}, headers: {}'.format(
url,
'GET',
headers
))
status = -1
for _ in range(request_times):
response = self.http_client.session.get(url,
headers=headers,
timeout=timeout)
logger.debug('[get_ppt_generation_status] request url: {}, method: {}, headers: {}, response: {}'.format(
url,
'GET',
headers,
response
))
try:
self.http_client.check_response_header(response)
except:
Expand Down Expand Up @@ -239,20 +214,9 @@ def get_ppt_download_link(self,
url = self.http_client.service_url(self.get_ppt_download_link_url, self.uniform_prefix) + f'?id={job_id}'
headers = self.http_client.auth_header()
headers['Content-Type'] = 'application/json'
logger.debug('[get_ppt_download_link] request url: {}, method: {}, headers: {}'.format(
url,
'GET',
headers
))
response = self.http_client.session.get(url,
headers=headers,
timeout=timeout)
logger.debug('[get_ppt_download_link] request url: {}, method: {}, headers: {}, response: {}'.format(
url,
'GET',
headers,
response
))
self.http_client.check_response_header(response)
resp_data = response.json()
if resp_data.get('code', None) != 200 or resp_data.get('msg', None) != 'success':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,10 @@ def ppt_generation(self,
url = self.http_client.service_url(self.ppt_generation_url, self.uniform_prefix)
headers = self.http_client.auth_header()
headers['Content-Type'] = 'application/json'

logger.debug('[ppt_generation] request url: {}, method: {}, json: {}, headers: {}'.format(
url,
'POST',
post_data,
headers
))
response = self.http_client.session.post(url,
json=post_data,
headers=headers,
timeout=timeout)
logger.debug('[ppt_generation] request url: {}, method: {}, json: {}, headers: {}, response: {}'.format(
url,
'POST',
post_data,
headers,
response
))
self.http_client.check_response_header(response)
resp_data = response.json()
if resp_data.get('code', None) != 200 or resp_data.get('msg', None) != 'success':
Expand Down Expand Up @@ -174,22 +160,11 @@ def get_ppt_generation_status(self,
headers = self.http_client.auth_header()
headers['Content-Type'] = 'application/json'

logger.debug('[get_ppt_generation_status] request url: {}, method: {}, headers: {}'.format(
url,
'GET',
headers
))
status = -1
for _ in range(request_times):
response = self.http_client.session.get(url,
headers=headers,
timeout=timeout)
logger.debug('[get_ppt_generation_status] request url: {}, method: {}, headers: {}, response: {}'.format(
url,
'GET',
headers,
response
))
try:
self.http_client.check_response_header(response)
except:
Expand Down Expand Up @@ -246,20 +221,9 @@ def get_ppt_download_link(self,
url = self.http_client.service_url(self.get_ppt_download_link_url, self.uniform_prefix) + f'?id={job_id}'
headers = self.http_client.auth_header()
headers['Content-Type'] = 'application/json'
logger.debug('[get_ppt_download_link] request url: {}, method: {}, headers: {}'.format(
url,
'GET',
headers
))
response = self.http_client.session.get(url,
headers=headers,
timeout=timeout)
logger.debug('[get_ppt_download_link] request url: {}, method: {}, headers: {}, response: {}'.format(
url,
'GET',
headers,
response
))
self.http_client.check_response_header(response)
resp_data = response.json()
if resp_data.get('code', None) != 200 or resp_data.get('msg', None) != 'success':
Expand Down
36 changes: 0 additions & 36 deletions python/core/components/ppt_generation_from_paper/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,10 @@ def ppt_generation(self,
url = self.http_client.service_url(self.ppt_generation_url, self.uniform_prefix)
headers = self.http_client.auth_header()
headers['Content-Type'] = 'application/json'

logger.debug('[ppt_generation] request url: {}, method: {}, json: {}, headers: {}'.format(
url,
'POST',
post_data,
headers
))
response = self.http_client.session.post(url,
json=post_data,
headers=headers,
timeout=timeout)
logger.debug('[ppt_generation] request url: {}, method: {}, json: {}, headers: {}, response: {}'.format(
url,
'POST',
post_data,
headers,
response
))
self.http_client.check_response_header(response)
resp_data = response.json()
if resp_data.get('code', None) != 200 or resp_data.get('msg', None) != 'success':
Expand Down Expand Up @@ -169,22 +155,11 @@ def get_ppt_generation_status(self,
headers = self.http_client.auth_header()
headers['Content-Type'] = 'application/json'

logger.debug('[get_ppt_generation_status] request url: {}, method: {}, headers: {}'.format(
url,
'GET',
headers
))
status = -1
for _ in range(request_times):
response = self.http_client.session.get(url,
headers=headers,
timeout=timeout)
logger.debug('[get_ppt_generation_status] request url: {}, method: {}, headers: {}, response: {}'.format(
url,
'GET',
headers,
response
))
try:
self.http_client.check_response_header(response)
except:
Expand Down Expand Up @@ -242,20 +217,9 @@ def get_ppt_download_link(self,
url = self.http_client.service_url(self.get_ppt_download_link_url, self.uniform_prefix) + f'?id={job_id}'
headers = self.http_client.auth_header()
headers['Content-Type'] = 'application/json'
logger.debug('[get_ppt_download_link] request url: {}, method: {}, headers: {}'.format(
url,
'GET',
headers
))
response = self.http_client.session.get(url,
headers=headers,
timeout=timeout)
logger.debug('[get_ppt_download_link] request url: {}, method: {}, headers: {}, response: {}'.format(
url,
'GET',
headers,
response
))
self.http_client.check_response_header(response)
resp_data = response.json()
if resp_data.get('code', None) != 200 or resp_data.get('msg', None) != 'success':
Expand Down
Loading

0 comments on commit 4b2588f

Please sign in to comment.