feat(knowledge): add optional channel parameter to CreateKnowledgeFromFile
- Updated the CreateKnowledgeFromFile function to include a new optional `channel` parameter, allowing for better tracking of knowledge entry sources. - Enhanced documentation to reflect the addition of the channel parameter, improving clarity for future developers.
This commit is contained in:
+1
-1
@@ -64,7 +64,7 @@ func ExampleUsage() {
|
|||||||
"source": "local",
|
"source": "local",
|
||||||
"type": "document",
|
"type": "document",
|
||||||
}
|
}
|
||||||
knowledge, err := apiClient.CreateKnowledgeFromFile(context.Background(), createdKB.ID, filePath, metadata, nil, "")
|
knowledge, err := apiClient.CreateKnowledgeFromFile(context.Background(), createdKB.ID, filePath, metadata, nil, "", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to upload knowledge file: %v\n", err)
|
fmt.Printf("Failed to upload knowledge file: %v\n", err)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+8
-1
@@ -89,8 +89,9 @@ var ErrDuplicateURL = errors.New("URL already exists")
|
|||||||
// - metadata: Optional metadata for the knowledge entry
|
// - metadata: Optional metadata for the knowledge entry
|
||||||
// - enableMultimodel: Optional flag to enable multimodal processing
|
// - enableMultimodel: Optional flag to enable multimodal processing
|
||||||
// - customFileName: Optional custom file name (useful for folder uploads with path)
|
// - customFileName: Optional custom file name (useful for folder uploads with path)
|
||||||
|
// - channel: Optional ingestion channel (e.g. "web", "api", "wechat"); empty defaults to "web"
|
||||||
func (c *Client) CreateKnowledgeFromFile(ctx context.Context,
|
func (c *Client) CreateKnowledgeFromFile(ctx context.Context,
|
||||||
knowledgeBaseID string, filePath string, metadata map[string]string, enableMultimodel *bool, customFileName string,
|
knowledgeBaseID string, filePath string, metadata map[string]string, enableMultimodel *bool, customFileName string, channel string,
|
||||||
) (*Knowledge, error) {
|
) (*Knowledge, error) {
|
||||||
// Open the local file
|
// Open the local file
|
||||||
file, err := os.Open(filePath)
|
file, err := os.Open(filePath)
|
||||||
@@ -151,6 +152,12 @@ func (c *Client) CreateKnowledgeFromFile(ctx context.Context,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if channel != "" {
|
||||||
|
if err := writer.WriteField("channel", channel); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to write channel field: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Close the multipart writer
|
// Close the multipart writer
|
||||||
err = writer.Close()
|
err = writer.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user