Skip to content

Commit

Permalink
修复日志打印导致的流式失效的问题 (#714)
Browse files Browse the repository at this point in the history
* 修复日志打印导致的流式失效的问题

* update unittest
  • Loading branch information
userpj authored Jan 16, 2025
1 parent e70a371 commit b80bbc9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
3 changes: 0 additions & 3 deletions python/core/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ 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 text is {}".format(
__class__.response_request_id(response), status_code, response.text
))
return
message = "request_id={} , http status code is {}, body is {}".format(
__class__.response_request_id(response), status_code, response.text
Expand Down
11 changes: 6 additions & 5 deletions python/core/console/component_client/data_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from pydantic import BaseModel
from pydantic import Field
from typing import Optional
from typing import Optional, Union
from appbuilder.core.component import ComponentOutput, Content


Expand Down Expand Up @@ -74,7 +74,7 @@ class Event(BaseModel):
description="错误信息",
)

event: Event = Field(..., description="事件信息")
event: Event = Field(None, description="事件信息")


class RunResponse(BaseModel):
Expand All @@ -87,12 +87,13 @@ class RunOutput(ComponentOutput):
user_id: str = Field(..., description="开发者UUID(计费依赖)")
end_user_id: str = Field(None, description="终端用户id")
is_completion: bool = Field(..., description="是否完成")
role: str = Field(..., description="当前消息来源,默认tool")
content: list[ContentWithEvent] = Field(
None,
description="当前组件返回内容的主要payload,List[ContentWithEvent],每个 Content 包括了当前 event 的一个元素",
)

request_id: str = Field(..., description="请求id")
code: str = Field(None, description="响应码")
request_id: str = Field(None, description="请求id")
code: Union[str,int] = Field(None, description="响应码")
message: str = Field(None, description="响应消息")
data: RunOutput = Field(..., description="响应数据")
data: RunOutput = Field(None, description="响应数据")
12 changes: 6 additions & 6 deletions python/tests/test_appbuilder_client_follow_up_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def __init__(self):
self.follow_up_queries = []

def handle_content_type(self, run_context, run_response):
event = run_response.events[-1]
if event.content_type == "json" and event.event_type == "FollowUpQuery":
follow_up_queries = event.detail.get("json").get("follow_up_querys")
self.follow_up_queries.extend(follow_up_queries)

for event in run_response.events:
print(event)
if event.content_type == "json" and event.event_type == "FollowUpQuery":
follow_up_queries = event.detail.get("json").get("follow_up_querys")
self.follow_up_queries.extend(follow_up_queries)

@unittest.skipUnless(os.getenv("TEST_CASE", "UNKNOWN") == "CPU_SERIAL", "")
class TestAppBuilderClientChatflow(unittest.TestCase):
Expand Down Expand Up @@ -84,7 +84,7 @@ def test_appbuilder_run_followupquery_with_event_handler(self):
with builder.run_with_handler(
conversation_id = conversation_id,
query = "你能做什么",
stream=True,
stream=False,
event_handler=event_handler,
) as run:
run.until_done()
Expand Down
4 changes: 2 additions & 2 deletions python/tests/test_component_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
import os


@unittest.skipUnless(os.getenv("TEST_CASE", "UNKNOWN") == "CPU_SERIAL", "")
#unittest.skipUnless(os.getenv("TEST_CASE", "UNKNOWN") == "CPU_SERIAL", "")
class TestComponentCLient(unittest.TestCase):
def test_component_client(self):
appbuilder.logger.setLoglevel("DEBUG")
client = appbuilder.ComponentClient()

res = client.run(component_id="44205c67-3980-41f7-aad4-37357b577fd0",
version="latest", sys_origin_query="北京景点推荐")
print(res.content.content)
print(res.content)

def test_component_client_stream(self):
appbuilder.logger.setLoglevel("DEBUG")
Expand Down
3 changes: 2 additions & 1 deletion python/tests/test_console_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import appbuilder
from appbuilder.core._client import HTTPClient

@unittest.skipUnless(os.getenv("TEST_CASE", "UNKNOWN") == "CPU_PARALLEL", "")

@unittest.skip("暂时跳过")
class TestDataset(unittest.TestCase):
def setUp(self):
self.dataset_id = os.getenv("DATASET_ID", "UNKNOWN")
Expand Down
2 changes: 2 additions & 0 deletions python/tests/test_console_rag.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

from appbuilder.core.console.rag.rag import RAG


@unittest.skip("暂时跳过")
class TestRag(unittest.TestCase):

def setUp(self):
Expand Down

0 comments on commit b80bbc9

Please sign in to comment.