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:
+1
-1
@@ -71,7 +71,7 @@ func ExampleUsage() {
|
||||
"source": "local",
|
||||
"type": "document",
|
||||
}
|
||||
knowledge, err := apiClient.CreateKnowledgeFromFile(context.Background(), createdKB.ID, filePath, metadata, nil, "", "")
|
||||
knowledge, err := apiClient.CreateKnowledgeFromFile(context.Background(), createdKB.ID, filePath, metadata, nil, "", "", nil)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to upload knowledge file: %v\n", err)
|
||||
} else {
|
||||
|
||||
@@ -83,6 +83,19 @@ var ErrDuplicateFile = errors.New("file already exists")
|
||||
// ErrDuplicateURL is returned when attempting to create a knowledge entry with a URL that already exists
|
||||
var ErrDuplicateURL = errors.New("URL already exists")
|
||||
|
||||
// KnowledgeProcessOverrides stores per-upload parse config overrides sent as process_config.
|
||||
// When nil, the server uses the knowledge base defaults only.
|
||||
type KnowledgeProcessOverrides struct {
|
||||
ParserEngineRules []ParserEngineRule `json:"parser_engine_rules,omitempty"`
|
||||
ChunkingConfig *ChunkingConfig `json:"chunking_config,omitempty"`
|
||||
EnableMultimodel *bool `json:"enable_multimodel,omitempty"`
|
||||
VLMConfig *VLMConfig `json:"vlm_config,omitempty"`
|
||||
ASRConfig *ASRConfig `json:"asr_config,omitempty"`
|
||||
QuestionGenerationConfig *QuestionGenerationConfig `json:"question_generation_config,omitempty"`
|
||||
GraphEnabled *bool `json:"graph_enabled,omitempty"`
|
||||
ExtractConfig *ExtractConfig `json:"extract_config,omitempty"`
|
||||
}
|
||||
|
||||
// CreateKnowledgeFromFile creates a knowledge entry from a local file path
|
||||
// Parameters:
|
||||
// - knowledgeBaseID: The ID of the knowledge base
|
||||
@@ -91,8 +104,10 @@ var ErrDuplicateURL = errors.New("URL already exists")
|
||||
// - enableMultimodel: Optional flag to enable multimodal processing
|
||||
// - customFileName: Optional custom file name (useful for folder uploads with path)
|
||||
// - channel: Optional ingestion channel (e.g. "web", "api", "wechat"); empty defaults to "web"
|
||||
// - processConfig: Optional parse config overrides (serialized as process_config form field)
|
||||
func (c *Client) CreateKnowledgeFromFile(ctx context.Context,
|
||||
knowledgeBaseID string, filePath string, metadata map[string]string, enableMultimodel *bool, customFileName string, channel string,
|
||||
processConfig *KnowledgeProcessOverrides,
|
||||
) (*Knowledge, error) {
|
||||
// Open the local file
|
||||
file, err := os.Open(filePath)
|
||||
@@ -159,6 +174,16 @@ func (c *Client) CreateKnowledgeFromFile(ctx context.Context,
|
||||
}
|
||||
}
|
||||
|
||||
if processConfig != nil {
|
||||
processConfigBytes, err := json.Marshal(processConfig)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to serialize process_config: %w", err)
|
||||
}
|
||||
if err := writer.WriteField("process_config", string(processConfigBytes)); err != nil {
|
||||
return nil, fmt.Errorf("failed to write process_config field: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Close the multipart writer
|
||||
err = writer.Close()
|
||||
if err != nil {
|
||||
@@ -209,6 +234,8 @@ type CreateKnowledgeFromURLRequest struct {
|
||||
TagID string `json:"tag_id,omitempty"`
|
||||
// Channel identifies the ingestion channel (e.g. "web", "browser_extension", "api")
|
||||
Channel string `json:"channel,omitempty"`
|
||||
// ProcessConfig is optional per-upload parse config overrides (KnowledgeProcessOverrides).
|
||||
ProcessConfig *KnowledgeProcessOverrides `json:"process_config,omitempty"`
|
||||
}
|
||||
|
||||
// CreateKnowledgeFromURL creates a knowledge entry from a URL.
|
||||
|
||||
@@ -108,6 +108,25 @@ type GraphRelation struct {
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// ParserEngineRule maps a set of file types to a specific parser engine.
|
||||
type ParserEngineRule struct {
|
||||
FileTypes []string `json:"file_types"`
|
||||
Engine string `json:"engine"`
|
||||
}
|
||||
|
||||
// QuestionGenerationConfig controls LLM-generated questions per chunk during parsing.
|
||||
type QuestionGenerationConfig struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
QuestionCount int `json:"question_count"`
|
||||
}
|
||||
|
||||
// ASRConfig represents automatic speech recognition settings for audio files.
|
||||
type ASRConfig struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
ModelID string `json:"model_id"`
|
||||
Language string `json:"language,omitempty"`
|
||||
}
|
||||
|
||||
// UnmarshalJSON keeps backward compatibility for legacy responses that still
|
||||
// use `cos_config` instead of `storage_config`.
|
||||
func (kb *KnowledgeBase) UnmarshalJSON(data []byte) error {
|
||||
|
||||
Reference in New Issue
Block a user