Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
userpj committed Dec 31, 2024
1 parent b961c2d commit 1d222c7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 24 deletions.
4 changes: 1 addition & 3 deletions go/appbuilder/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,8 @@ func TestDataset(t *testing.T) {
dataset, _ := NewDataset(config)
datasetID, err := dataset.Create("测试集合")
if err != nil {
t.Logf("%s========== FAIL: %s ==========%s", "\033[31m", t.Name(), "\033[0m")
t.Fatalf("create dataset failed: %v", err)
datasetID = os.Getenv(SecretKeyV3)
}
log("Dataset created with ID: %s", datasetID)

_, err = dataset.BatchUploadLocaleFile("datasetID", []string{"./files/test.pdf", "./files/test2.pdf"})
if err != nil {
Expand Down
37 changes: 24 additions & 13 deletions go/appbuilder/knowledge_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ func TestCreateKnowledgeBaseError(t *testing.T) {
}

client.client = clientT
var knowledgeBaseID string
needDeleteKnowledgeBase := false
// 成功 创建知识库
createKnowledgeBaseRes, err := client.CreateKnowledgeBase(KnowledgeBaseDetail{
Name: "test-go",
Expand All @@ -362,10 +364,13 @@ func TestCreateKnowledgeBaseError(t *testing.T) {
},
},
})
if err != nil {
if err == nil {
needDeleteKnowledgeBase = true
knowledgeBaseID = createKnowledgeBaseRes.ID
} else {
knowledgeBaseID = os.Getenv(SecretKeyV3)
}

knowledgeBaseID := createKnowledgeBaseRes.ID
client.client = clientT
// GetKnowledgeBaseDetail 测试1 ServiceURLV2 错误
client.sdkConfig.GatewayURLV2 = "://invalid-url"
Expand Down Expand Up @@ -812,10 +817,11 @@ func TestCreateKnowledgeBaseError(t *testing.T) {

client.client = clientT
// 删除知识库
err = client.DeleteKnowledgeBase(knowledgeBaseID)
if err != nil {
if needDeleteKnowledgeBase {
err = client.DeleteKnowledgeBase(knowledgeBaseID)
if err != nil {
}
}

}

func TestChunkError(t *testing.T) {
Expand Down Expand Up @@ -1186,6 +1192,8 @@ func TestCreateKnowledgeBase(t *testing.T) {
}

// 创建知识库
var knowledgeBaseID string
needDeleteKnowledgeBase := false
createKnowledgeBaseRes, err := client.CreateKnowledgeBase(KnowledgeBaseDetail{
Name: "test-go",
Description: "test-go",
Expand All @@ -1199,10 +1207,11 @@ func TestCreateKnowledgeBase(t *testing.T) {
},
})
if err != nil {
t.Logf("%s========== FAIL: %s ==========%s", "\033[31m", t.Name(), "\033[0m")
t.Fatalf("create knowledge base failed: %v", err)
knowledgeBaseID = os.Getenv(DatasetIDV3)
} else {
needDeleteKnowledgeBase = true
knowledgeBaseID = createKnowledgeBaseRes.ID
}
knowledgeBaseID := createKnowledgeBaseRes.ID
log("Knowledge base created with ID: %s", knowledgeBaseID)

// 获取知识库详情
Expand Down Expand Up @@ -1379,12 +1388,14 @@ func TestCreateKnowledgeBase(t *testing.T) {
log("Knowledge base modified with new name: %s", name)

// 删除知识库
err = client.DeleteKnowledgeBase(knowledgeBaseID)
if err != nil {
t.Logf("%s========== FAIL: %s ==========%s", "\033[31m", t.Name(), "\033[0m")
t.Fatalf("delete knowledge base failed: %v", err)
if needDeleteKnowledgeBase {
err = client.DeleteKnowledgeBase(knowledgeBaseID)
if err != nil {
t.Logf("%s========== FAIL: %s ==========%s", "\033[31m", t.Name(), "\033[0m")
t.Fatalf("delete knowledge base failed: %v", err)
}
log("Knowledge base deleted with ID: %s", knowledgeBaseID)
}
log("Knowledge base deleted with ID: %s", knowledgeBaseID)

// 测试通过,打印文件名和测试函数名
t.Logf("%s========== OK: %s ==========%s", "\033[32m", t.Name(), "\033[0m")
Expand Down
12 changes: 9 additions & 3 deletions java/src/test/java/com/baidubce/appbuilder/DatasetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@ public class DatasetTest {
@Before
public void setUp() {
System.setProperty("APPBUILDER_TOKEN", System.getenv("APPBUILDER_TOKEN_V3"));

}

@Test
public void testCreateDataset() throws IOException, AppBuilderServerException {
Dataset dataset = new Dataset();
String datasetId = dataset.createDataset("dataset_name");
assertNotNull(datasetId);

String datasetId = "";
try {
datasetId = dataset.createDataset("dataset_name");
assertNotNull(datasetId);
} catch (Exception e) {
datasetId = System.getenv("DATASET_ID_V3");
}

String filePath = "src/test/java/com/baidubce/appbuilder/files/test.pdf";

String[] documentIds = dataset.addDocuments(new ArrayList<>(Collections.singletonList(filePath)), false, null, false);
Expand Down
19 changes: 14 additions & 5 deletions java/src/test/java/com/baidubce/appbuilder/KnowledgebaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,17 @@ public void testCreateKnowledgebase() throws IOException, AppBuilderServerExcept
"http://localhost:9200", "elastic", "changeme");
KnowledgeBaseConfig config = new KnowledgeBaseConfig(index);
request.setConfig(config);
KnowledgeBaseDetail response = knowledgebase.createKnowledgeBase(request);
String knowledgeBaseId = response.getId();
System.out.println(knowledgeBaseId);
assertNotNull(response.getId());

String knowledgeBaseId = "";
boolean needDeleteKnowledgebase = false;
try {
KnowledgeBaseDetail response = knowledgebase.createKnowledgeBase(request);
knowledgeBaseId = response.getId();
assertNotNull(response.getId());
needDeleteKnowledgebase = true;
} catch (Exception e) {
knowledgeBaseId = System.getenv("DATASET_ID_V3");
}

// 获取知识库详情
KnowledgeBaseDetail detail = knowledgebase.getKnowledgeBaseDetail(knowledgeBaseId);
Expand Down Expand Up @@ -134,7 +141,9 @@ public void testCreateKnowledgebase() throws IOException, AppBuilderServerExcept
assertNotNull(documentsUploadResponse.getDocumentId());

// 删除知识库
knowledgebase.deleteKnowledgeBase(knowledgeBaseId);
if(needDeleteKnowledgebase) {
knowledgebase.deleteKnowledgeBase(knowledgeBaseId);
}
}

@Test
Expand Down

0 comments on commit 1d222c7

Please sign in to comment.