Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持输入dict创建json输出 #725

Merged
merged 6 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions python/core/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ def create_output(cls, type, text, role="tool", name="", visible_scope="all", ra
key_list = ["detail", "steps"]
elif type == "function_call":
key_list = ["thought", "name", "arguments"]
elif type == "json":
key_list = ["data"]
else:
raise ValueError("Unknown type: {}".format(type))
assert all(key in text for key in key_list), "all keys:{} must be included in the text field".format(key_list)
Expand Down
2 changes: 2 additions & 0 deletions python/tests/test_base_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def test_valid_output_with_dict(self):
output9 = self.component.create_output(type="plan", text={"detail": "hello", "steps":[{"name": "1", "arguments": {"query": "a", "chat_history": "world"}}]})
output10 = self.component.create_output(type="function_call", text={"thought": "hello", "name": "AppBuilder", "arguments": {"query": "a", "chat_history": "world"}})
output11 = self.component.create_output(type="references", text={"type": "engine", "doc_id": "1", "content": "hello, world", "title": "Have a nice day", "source": "bing", "extra": {"key": "value"}})
output12 = self.component.create_output(type="json", text={"data": "value"})
self.assertIsInstance(output1, ComponentOutput)
self.assertIsInstance(output2, ComponentOutput)
self.assertIsInstance(output3, ComponentOutput)
Expand All @@ -44,6 +45,7 @@ def test_valid_output_with_dict(self):
self.assertIsInstance(output9, ComponentOutput)
self.assertIsInstance(output10, ComponentOutput)
self.assertIsInstance(output11, ComponentOutput)
self.assertIsInstance(output12, ComponentOutput)
self.assertEqual(output11.content[0].text.extra["key"], "value")

def test_valid_output_type_with_same_key(self):
Expand Down
2 changes: 1 addition & 1 deletion python/tests/test_core_components_baidu_vdb_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from appbuilder import BaiduVDBVectorStoreIndex,TableParams
from appbuilder.core.component import Message

@unittest.skipUnless(os.getenv("TEST_CASE", "UNKNOWN") == "CPU_PARALLEL", "")
@unittest.skip(reason="vdb欠费了,跳过")
class TestBaiduVbdRetriever(unittest.TestCase):
def setUp(self):
self.instance_id=os.getenv("INSTANCE_ID", "UNKNOWN")
Expand Down
Loading