Skip to content

Commit

Permalink
add base code (#691)
Browse files Browse the repository at this point in the history
Co-authored-by: chengmo <[email protected]>
  • Loading branch information
MrChengmo and chengmo authored Dec 28, 2024
1 parent 7c0ffaf commit 8f45a5d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
7 changes: 7 additions & 0 deletions python/core/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,13 @@ def set_secret_key_and_gateway(self, secret_key: Optional[str] = None, gateway:
"""
self.secret_key = secret_key
self.gateway = gateway
# 因为子类可能重载init方法,导致没有is_async属性,所以此处需要判断一下
try:
self.is_async
except AttributeError:
# 目前async仅在AppBuilderClient中使用,所以没有async属性的组件都可以设置为False
self.is_async = False

if self.is_async:
self._http_client = AsyncHTTPClient(self.secret_key, self.gateway)
else:
Expand Down
37 changes: 37 additions & 0 deletions python/tests/test_component_is_async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) 2024 Baidu, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import os
import unittest
from appbuilder.core.component import Component

class MockComponent(Component):

def __init__(self, *args, **kwargs):
pass

def tool_eval(self, *args, **kwargs):
print("Success")


class TestComponentInit(unittest.TestCase):
def test_component_init(self):
component = MockComponent()
os.environ["APPBUILDER_TOKEN"] = "abc"
component.set_secret_key_and_gateway()
component.tool_eval()

if __name__ == '__main__':
unittest.main()

0 comments on commit 8f45a5d

Please sign in to comment.