Go SDK
更新时间:
环境依赖
1.Go 1.18+
安装
go get github.com/tongyi-xingchen/xingchen-sdk-go@v1.1.3
知识库管理
准备
func initClient() (*xingchen.APIClient, context.Context) {
configuration := xingchen.NewConfiguration()
apiClient := xingchen.NewAPIClient(configuration)
brearer := "{API-KEY}"
ctx := context.WithValue(context.Background(), xingchen.ContextAccessToken, brearer)
return apiClient, ctx
}
知识库创建
package test
import (
"context"
"github.com/stretchr/testify/assert"
"github.com/tongyi-xingchen/xingchen-sdk-go/xingchen"
"testing"
)
func initClient() (*xingchen.APIClient, context.Context) {
configuration := xingchen.NewConfiguration()
apiClient := xingchen.NewAPIClient(configuration)
brearer := "{API-KEY}"
ctx := context.WithValue(context.Background(), xingchen.ContextAccessToken, brearer)
return apiClient, ctx
}
func Test_knowledge_base_create(t *testing.T) {
apiClient, ctx := initClient()
createDTO := xingchen.KnowledgeBaseCreateDTO{
Name: xingchen.PtrString("知识库名称"),
Description: xingchen.PtrString("知识库详情"),
}
resp, httpRes, err := apiClient.KnowledgeBaseApiSubService.Create(ctx).CreateDTO(createDTO).Execute()
testAssert := assert.New(t)
testAssert.Nil(err)
testAssert.NotNil(resp)
testAssert.Equal(httpRes.StatusCode, 200)
}
知识库修改
package test
import (
"context"
"github.com/stretchr/testify/assert"
"github.com/tongyi-xingchen/xingchen-sdk-go/xingchen"
"testing"
)
func initClient() (*xingchen.APIClient, context.Context) {
configuration := xingchen.NewConfiguration()
apiClient := xingchen.NewAPIClient(configuration)
brearer := "{API-KEY}"
ctx := context.WithValue(context.Background(), xingchen.ContextAccessToken, brearer)
return apiClient, ctx
}
func Test_knowledge_base_update(t *testing.T) {
apiClient, ctx := initClient()
updateDTO := xingchen.KnowledgeBaseUpdateDTO{
KnowledgeBaseId: xingchen.PtrString("知识库id"),
Name: xingchen.PtrString("知识库名称"),
Description: xingchen.PtrString("知识库描述"),
}
resp, httpRes, err := apiClient.KnowledgeBaseApiSubService.Update(ctx).UpdateDTO(updateDTO).Execute()
testAssert := assert.New(t)
testAssert.Nil(err)
testAssert.NotNil(resp)
testAssert.Equal(httpRes.StatusCode, 200)
}
知识库搜索
package test
import (
"context"
"github.com/stretchr/testify/assert"
"github.com/tongyi-xingchen/xingchen-sdk-go/xingchen"
"testing"
)
func initClient() (*xingchen.APIClient, context.Context) {
configuration := xingchen.NewConfiguration()
apiClient := xingchen.NewAPIClient(configuration)
brearer := "{API-KEY}"
ctx := context.WithValue(context.Background(), xingchen.ContextAccessToken, brearer)
return apiClient, ctx
}
func Test_knowledge_base_search(t *testing.T) {
apiClient, ctx := initClient()
searchDTO := xingchen.KnowledgeBaseQueryDTO{
PageSize: xingchen.PtrInt32(10),
PageNum: xingchen.PtrInt32(1),
}
resp, httpRes, err := apiClient.KnowledgeBaseApiSubService.Search(ctx).SearchDTO(searchDTO).Execute()
testAssert := assert.New(t)
testAssert.Nil(err)
testAssert.NotNil(resp)
testAssert.Equal(httpRes.StatusCode, 200)
}
知识库删除
package test
import (
"context"
"github.com/stretchr/testify/assert"
"github.com/tongyi-xingchen/xingchen-sdk-go/xingchen"
"testing"
)
func initClient() (*xingchen.APIClient, context.Context) {
configuration := xingchen.NewConfiguration()
apiClient := xingchen.NewAPIClient(configuration)
brearer := "{API-KEY}"
ctx := context.WithValue(context.Background(), xingchen.ContextAccessToken, brearer)
return apiClient, ctx
}
func Test_knowledge_base_delete(t *testing.T) {
apiClient, ctx := initClient()
deleteDTO := xingchen.KnowledgeBaseDeleteDTO{
KnowledgeBaseId: xingchen.PtrString("知识库id"),
}
resp, httpRes, err := apiClient.KnowledgeBaseApiSubService.Delete(ctx).DeleteDTO(deleteDTO).Execute()
testAssert := assert.New(t)
testAssert.Nil(err)
testAssert.NotNil(resp)
testAssert.Equal(httpRes.StatusCode, 200)
}
知识库文件详情上传
package test
import (
"context"
"github.com/stretchr/testify/assert"
"github.com/tongyi-xingchen/xingchen-sdk-go/xingchen"
"testing"
)
func initClient() (*xingchen.APIClient, context.Context) {
configuration := xingchen.NewConfiguration()
apiClient := xingchen.NewAPIClient(configuration)
brearer := "{API-KEY}"
ctx := context.WithValue(context.Background(), xingchen.ContextAccessToken, brearer)
return apiClient, ctx
}
func Test_knowledge_base_detail_upload(t *testing.T) {
apiClient, ctx := initClient()
uploadDTO := xingchen.KnowledgeBaseDetailUploadDTO{
KnowledgeBaseId: xingchen.PtrString("知识库id"),
Type: xingchen.PtrString("text"),
FileInfos: []xingchen.FileInfoVO{
{
Filename: xingchen.PtrString("文件名.txt"),
FileUrl: xingchen.PtrString("公网可访问域名"),
},
},
}
resp, httpRes, err := apiClient.KnowledgeBaseApiSubService.DetailUpload(ctx).DetailUploadDTO(uploadDTO).Execute()
testAssert := assert.New(t)
testAssert.Nil(err)
testAssert.NotNil(resp)
testAssert.Equal(httpRes.StatusCode, 200)
}
知识库文件详情修改
package test
import (
"context"
"github.com/stretchr/testify/assert"
"github.com/tongyi-xingchen/xingchen-sdk-go/xingchen"
"testing"
)
func initClient() (*xingchen.APIClient, context.Context) {
configuration := xingchen.NewConfiguration()
apiClient := xingchen.NewAPIClient(configuration)
brearer := "{API-KEY}"
ctx := context.WithValue(context.Background(), xingchen.ContextAccessToken, brearer)
return apiClient, ctx
}
func Test_knowledge_base_detail_update(t *testing.T) {
apiClient, ctx := initClient()
updateDTO := xingchen.KnowledgeBaseDetailUpdateDTO{
KnowledgeBaseId: xingchen.PtrString("知识库id"),
Name: xingchen.PtrString("知识库文件详情名称"),
NewName: xingchen.PtrString("知识库修改文件详情名称"),
}
resp, httpRes, err := apiClient.KnowledgeBaseApiSubService.DetailUpdate(ctx).DetailUpdateDTO(updateDTO).Execute()
testAssert := assert.New(t)
testAssert.Nil(err)
testAssert.NotNil(resp)
testAssert.Equal(httpRes.StatusCode, 200)
}
知识库文件详情搜索
package test
import (
"context"
"github.com/stretchr/testify/assert"
"github.com/tongyi-xingchen/xingchen-sdk-go/xingchen"
"testing"
)
func initClient() (*xingchen.APIClient, context.Context) {
configuration := xingchen.NewConfiguration()
apiClient := xingchen.NewAPIClient(configuration)
brearer := "{API-KEY}"
ctx := context.WithValue(context.Background(), xingchen.ContextAccessToken, brearer)
return apiClient, ctx
}
func Test_knowledge_base_detail_search(t *testing.T) {
apiClient, ctx := initClient()
queryDTO := xingchen.KnowledgeBaseDetailQueryDTO{
KnowledgeBaseId: xingchen.PtrString("xxx"),
}
resp, httpRes, err := apiClient.KnowledgeBaseApiSubService.DetailSearch(ctx).DetailSearchDTO(queryDTO).Execute()
testAssert := assert.New(t)
testAssert.Nil(err)
testAssert.NotNil(resp)
testAssert.Equal(httpRes.StatusCode, 200)
}
知识库文件详情删除
package test
import (
"context"
"github.com/stretchr/testify/assert"
"github.com/tongyi-xingchen/xingchen-sdk-go/xingchen"
"testing"
)
func initClient() (*xingchen.APIClient, context.Context) {
configuration := xingchen.NewConfiguration()
apiClient := xingchen.NewAPIClient(configuration)
brearer := "{API-KEY}"
ctx := context.WithValue(context.Background(), xingchen.ContextAccessToken, brearer)
return apiClient, ctx
}
func Test_knowledge_base_detail_delete(t *testing.T) {
apiClient, ctx := initClient()
deleteDTO := xingchen.KnowledgeBaseDetailDeleteDTO{
KnowledgeBaseId: xingchen.PtrString("知识库id"),
Name: xingchen.PtrString("知识库详情名称"),
}
resp, httpRes, err := apiClient.KnowledgeBaseApiSubService.DetailDelete(ctx).DetailDeleteDTO(deleteDTO).Execute()
testAssert := assert.New(t)
testAssert.Nil(err)
testAssert.NotNil(resp)
testAssert.Equal(httpRes.StatusCode, 200)
}
文档内容是否对您有帮助?