feat: standardize storage configuration and enhance backward compatibility
- Updated the `KnowledgeBase` struct to rename `cos_config` to `storage_config` for consistency across the application. - Implemented a custom `UnmarshalJSON` method to maintain backward compatibility with legacy responses that still use `cos_config`. - Modified various frontend components to reflect the new `storage_config` naming, ensuring seamless integration with the updated backend structure. - Enhanced Dockerfiles and service configurations to support the new storage engine setup. This update improves the clarity of storage configurations and ensures compatibility with existing data structures.
This commit is contained in:
+21
-1
@@ -6,6 +6,7 @@ package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
@@ -25,7 +26,7 @@ type KnowledgeBase struct {
|
||||
EmbeddingModelID string `json:"embedding_model_id"`
|
||||
SummaryModelID string `json:"summary_model_id"`
|
||||
VLMConfig VLMConfig `json:"vlm_config"`
|
||||
StorageConfig StorageConfig `json:"cos_config"`
|
||||
StorageConfig StorageConfig `json:"storage_config"`
|
||||
ExtractConfig *ExtractConfig `json:"extract_config"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
@@ -99,6 +100,25 @@ type GraphRelation struct {
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// UnmarshalJSON keeps backward compatibility for legacy responses that still
|
||||
// use `cos_config` instead of `storage_config`.
|
||||
func (kb *KnowledgeBase) UnmarshalJSON(data []byte) error {
|
||||
type alias KnowledgeBase
|
||||
aux := struct {
|
||||
*alias
|
||||
LegacyStorageConfig *StorageConfig `json:"cos_config"`
|
||||
}{
|
||||
alias: (*alias)(kb),
|
||||
}
|
||||
if err := json.Unmarshal(data, &aux); err != nil {
|
||||
return err
|
||||
}
|
||||
if aux.LegacyStorageConfig != nil && kb.StorageConfig == (StorageConfig{}) {
|
||||
kb.StorageConfig = *aux.LegacyStorageConfig
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// KnowledgeBaseResponse knowledge base response
|
||||
type KnowledgeBaseResponse struct {
|
||||
Success bool `json:"success"`
|
||||
|
||||
Reference in New Issue
Block a user