Skip to content
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
1 change: 1 addition & 0 deletions go/appbuilder/component_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (t *ComponentClient) Run(component, version, action string, stream bool, pa
request.URL = serviceURL
request.Method = "POST"
header.Set("Content-Type", "application/json")
header.Set("X-Appbuilder-From", "sdk")
request.Header = header

req := ComponentRunRequest{
Expand Down
43 changes: 43 additions & 0 deletions go/appbuilder/component_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,46 @@ func TestComponentClient(t *testing.T) {
t.Logf("%s========== OK: %s ==========%s", "\033[32m", t.Name(), "\033[0m")
}
}

func TestComponentClientHeader(t *testing.T) {
os.Setenv("APPBUILDER_LOGLEVEL", "DEBUG")
config, err := NewSDKConfig("", "")
if err != nil {
t.Logf("%s========== FAIL: %s ==========%s", "\033[31m", t.Name(), "\033[0m")
t.Fatalf("new http client config failed: %v", err)
}

componentID := "c-wf-a39ee06c-808f-4a19-9f5f-544044283749"
parameters := map[string]any{
SysOriginQuery: "梦到巨人,是怎么回事",
}
componentClient, err := NewComponentClient(config)
if err != nil {
t.Error(err)
return
}

ret, err := componentClient.Run(componentID, "latest", "", false, parameters)
if err != nil {
t.Error(err)
return
}

for answer, err := ret.Next(); err == nil; answer, err = ret.Next() {
t.Log(answer.Content[0].Text["info"])
}

ret2, err := componentClient.Run(componentID, "latest", "", true, parameters)
if err != nil {
t.Error(err)
return
}

for answer, err := ret2.Next(); err == nil; answer, err = ret2.Next() {
if len(answer.Content) == 0 {
continue
}
t.Log(answer.Content[0].Text["info"])
}

}
2 changes: 1 addition & 1 deletion java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.baidubce</groupId>
<artifactId>appbuilder</artifactId>
<version>1.1.1</version>
<version>1.1.4</version>
<packaging>jar</packaging>

<name>app-builder</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public ComponentClientIterator run(String componentId, String version, String ac
ClassicHttpRequest postRequest = httpClient.createPostRequestV2(urlSuffix,
new StringEntity(jsonBody, StandardCharsets.UTF_8));
postRequest.setHeader("Content-Type", "application/json");
postRequest.setHeader("X-Appbuilder-From", "sdk");
HttpResponse<StreamIterator<ComponentClientRunResponse>> response =
httpClient.executeSSE(postRequest, ComponentClientRunResponse.class);
return new ComponentClientIterator(response.getBody());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,34 @@ public void TestComponentClientRunStream() throws IOException, AppBuilderServerE
}
assertNotNull(text);
}

@Test
public void TestComponentClientHeaderRun() throws IOException, AppBuilderServerException {
this.componentId = "c-wf-a39ee06c-808f-4a19-9f5f-544044283749";
ComponentClient client = new ComponentClient();
Map<String, Object> parameters = new HashMap<>();
parameters.put(ComponentClientRunRequest.SysOriginQuery, "梦到巨人");
ComponentClientIterator iter = client.run(componentId, "latest", "", false, parameters);
while (iter.hasNext()) {
ComponentClientRunResponse response = iter.next();
System.out.println((response.getContent()[0].getText().get("info")));
}
}

@Test
public void TestComponentClientHeaderRunStream() throws IOException, AppBuilderServerException {
this.componentId = "c-wf-a39ee06c-808f-4a19-9f5f-544044283749";
ComponentClient client = new ComponentClient();
Map<String, Object> parameters = new HashMap<>();
parameters.put(ComponentClientRunRequest.SysOriginQuery, "梦到巨人");
ComponentClientIterator iter = client.run(componentId, "latest", "", true, parameters);

while (iter.hasNext()) {
ComponentClientRunResponse response = iter.next();
if (response.getContent().length > 0) {
System.out.println((response.getContent()[0].getText().get("info")));
}
}

}
}
2 changes: 1 addition & 1 deletion python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


__version__ = '1.1.3'
__version__ = '1.1.4'

import os
import sys
Expand Down
1 change: 1 addition & 0 deletions python/core/console/component_client/component_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def run(
"""
headers = self.http_client.auth_header_v2()
headers["Content-Type"] = "application/json"
headers["X-Appbuilder-From"] = "sdk"

url_suffix = f"/components/{component_id}"
if version is not None:
Expand Down
17 changes: 17 additions & 0 deletions python/tests/test_component_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ def test_component_client_stream(self):
for data in res.content:
print(data)

def test_component_header_client(self):
appbuilder.logger.setLoglevel("DEBUG")
client = appbuilder.ComponentClient()

res = client.run(component_id="c-wf-a39ee06c-808f-4a19-9f5f-544044283749",
version="latest", sys_origin_query="梦到巨人")
print(res.content)

def test_component_header_client_stream(self):
appbuilder.logger.setLoglevel("DEBUG")
client = appbuilder.ComponentClient()

res = client.run(component_id="c-wf-a39ee06c-808f-4a19-9f5f-544044283749",
version="latest", sys_origin_query="梦到巨人", stream=True)
for data in res.content:
print(data)


if __name__ == "__main__":
unittest.main()
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ opentelemetry-api>=1.23.0
pydub>=0.10.0
ffmpeg
aiohttp
urllib3<2.0.0
urllib3<2.0.0
mcp==1.3.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
setup(
name="appbuilder-sdk",
# NOTE(chengmo): 修改此版本号时,请注意同时修改 __init__.py 中的 __version__
version="1.1.3",
version="1.1.4",
author="dongdaxiang",
author_email="[email protected]",
packages=packages,
Expand Down
Loading