feat(client): enhance knowledge file upload with process configuration support
- Updated the `CreateKnowledgeFromFile` function to accept an optional `processConfig` parameter for per-upload parse configuration overrides. - Introduced the `KnowledgeProcessOverrides` type to define various parsing settings, including parser engine rules and chunking configurations. - Modified the API client and related components to handle the new process configuration, improving flexibility in knowledge file uploads. - Updated documentation and API specifications to reflect the new `process_config` parameter in the upload process. - Added a new `UploadConfirmHost` component to facilitate user confirmation for uploads, integrating with the updated upload logic. - Enhanced user experience by providing detailed configuration options during the upload process.
This commit is contained in:
@@ -138,6 +138,7 @@ func TestCreateKnowledgeFromFileDoesNotPersistWhenStorageSaveFails(t *testing.T)
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
nil,
|
||||
)
|
||||
|
||||
require.Error(t, err)
|
||||
@@ -168,6 +169,7 @@ func TestCreateKnowledgeFromFilePersistsStoredFilePathOnCreate(t *testing.T) {
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
nil,
|
||||
)
|
||||
|
||||
require.NoError(t, err)
|
||||
@@ -201,6 +203,7 @@ func TestCreateKnowledgeFromFileDeletesStoredFileWhenCreateFails(t *testing.T) {
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
nil,
|
||||
)
|
||||
|
||||
require.EqualError(t, err, "database unavailable")
|
||||
@@ -211,6 +214,52 @@ func TestCreateKnowledgeFromFileDeletesStoredFileWhenCreateFails(t *testing.T) {
|
||||
require.Equal(t, "stored/"+fileSvc.savedWithKnowledgeID, fileSvc.deletedPath)
|
||||
}
|
||||
|
||||
func TestCreateKnowledgeFromFile_PersistsProcessOverrides(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
repo := &createKnowledgeFileRepoStub{}
|
||||
fileSvc := &createKnowledgeFileServiceStub{}
|
||||
task := &createKnowledgeTaskEnqueuerStub{}
|
||||
svc := &knowledgeService{
|
||||
repo: repo,
|
||||
kbService: &createKnowledgeFileKBServiceStub{kb: &types.KnowledgeBase{ID: "kb-1"}},
|
||||
fileSvc: fileSvc,
|
||||
task: task,
|
||||
}
|
||||
|
||||
chunkSize := 512
|
||||
overrides := &types.KnowledgeProcessOverrides{
|
||||
ChunkingConfig: &types.ChunkingConfig{ChunkSize: chunkSize},
|
||||
}
|
||||
|
||||
knowledge, err := svc.CreateKnowledgeFromFile(
|
||||
newCreateKnowledgeFileContext(),
|
||||
"kb-1",
|
||||
newMultipartFileHeader(t, "doc.txt", "hello"),
|
||||
map[string]string{"source": "test"},
|
||||
nil,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
overrides,
|
||||
)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, knowledge)
|
||||
require.Equal(t, 1, repo.createCalls)
|
||||
require.NotNil(t, repo.createdKnowledge)
|
||||
|
||||
parsed, err := repo.createdKnowledge.ProcessOverrides()
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, parsed)
|
||||
require.NotNil(t, parsed.ChunkingConfig)
|
||||
require.Equal(t, chunkSize, parsed.ChunkingConfig.ChunkSize)
|
||||
|
||||
metadataMap, err := repo.createdKnowledge.Metadata.Map()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "test", metadataMap["source"])
|
||||
}
|
||||
|
||||
func newCreateKnowledgeFileContext() context.Context {
|
||||
ctx := context.WithValue(context.Background(), types.TenantIDContextKey, uint64(1))
|
||||
ctx = context.WithValue(ctx, types.TenantInfoContextKey, &types.Tenant{})
|
||||
|
||||
Reference in New Issue
Block a user