feat: 重构客户端结构体,增强块、消息、会话和租户模型,并更新API文档
This commit is contained in:
+23
-17
@@ -14,23 +14,28 @@ import (
|
||||
// Chunk represents the information about a document chunk
|
||||
// Chunks are the basic units of storage and indexing in the knowledge base
|
||||
type Chunk struct {
|
||||
ID string `json:"id"` // Unique identifier of the chunk
|
||||
KnowledgeID string `json:"knowledge_id"` // Identifier of the parent knowledge
|
||||
TenantID uint `json:"tenant_id"` // Tenant ID
|
||||
Content string `json:"content"` // Text content of the chunk
|
||||
Embedding []float32 `json:"embedding"` // Vector embedding representation
|
||||
ChunkIndex int `json:"chunk_index"` // Index position of chunk in the document
|
||||
TotalChunks int `json:"total_chunks"` // Total number of chunks in the document
|
||||
IsEnabled bool `json:"is_enabled"` // Whether this chunk is enabled
|
||||
StartAt int `json:"start_at"` // Starting position in original text
|
||||
EndAt int `json:"end_at"` // Ending position in original text
|
||||
VectorStoreID string `json:"vector_store_id"` // Vector storage ID
|
||||
KeywordStoreID string `json:"keyword_store_id"` // Keyword storage ID
|
||||
EmbeddingStatus int `json:"embedding_status"` // Embedding status: 0-unprocessed, 1-processing, 2-completed
|
||||
ChunkType string `json:"chunk_type"`
|
||||
ImageInfo string `json:"image_info"`
|
||||
CreatedAt string `json:"created_at"` // Creation time
|
||||
UpdatedAt string `json:"updated_at"` // Last update time
|
||||
ID string `json:"id"` // Unique identifier of the chunk
|
||||
KnowledgeID string `json:"knowledge_id"` // Identifier of the parent knowledge
|
||||
KnowledgeBaseID string `json:"knowledge_base_id"` // ID of the knowledge base
|
||||
TenantID uint64 `json:"tenant_id"` // Tenant ID
|
||||
TagID string `json:"tag_id"` // Optional tag ID for categorization
|
||||
Content string `json:"content"` // Text content of the chunk
|
||||
ChunkIndex int `json:"chunk_index"` // Index position of chunk in the document
|
||||
IsEnabled bool `json:"is_enabled"` // Whether this chunk is enabled
|
||||
Status int `json:"status"` // Status of the chunk
|
||||
StartAt int `json:"start_at"` // Starting position in original text
|
||||
EndAt int `json:"end_at"` // Ending position in original text
|
||||
PreChunkID string `json:"pre_chunk_id"` // Previous chunk ID
|
||||
NextChunkID string `json:"next_chunk_id"` // Next chunk ID
|
||||
ChunkType string `json:"chunk_type"` // Chunk type (text, image_ocr, etc.)
|
||||
ParentChunkID string `json:"parent_chunk_id"` // Parent chunk ID
|
||||
RelationChunks any `json:"relation_chunks"` // Relation chunk IDs
|
||||
IndirectRelationChunks any `json:"indirect_relation_chunks"` // Indirect relation chunk IDs
|
||||
Metadata any `json:"metadata"` // Metadata for the chunk
|
||||
ContentHash string `json:"content_hash"` // Content hash for quick matching
|
||||
ImageInfo string `json:"image_info"` // Image information
|
||||
CreatedAt string `json:"created_at"` // Creation time
|
||||
UpdatedAt string `json:"updated_at"` // Last update time
|
||||
}
|
||||
|
||||
// ChunkResponse represents the response for a single chunk
|
||||
@@ -59,6 +64,7 @@ type UpdateChunkRequest struct {
|
||||
IsEnabled bool `json:"is_enabled"` // Whether enabled
|
||||
StartAt int `json:"start_at"` // Start position
|
||||
EndAt int `json:"end_at"` // End position
|
||||
ImageInfo string `json:"image_info"` // Image information
|
||||
}
|
||||
|
||||
// ListKnowledgeChunks lists all chunks under a knowledge document
|
||||
|
||||
@@ -12,6 +12,32 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// ToolResult represents the result of a tool execution
|
||||
type ToolResult struct {
|
||||
Success bool `json:"success"` // Whether the tool executed successfully
|
||||
Output string `json:"output"` // Human-readable output
|
||||
Data map[string]interface{} `json:"data,omitempty"` // Structured data for programmatic use
|
||||
Error string `json:"error,omitempty"` // Error message if execution failed
|
||||
}
|
||||
|
||||
// ToolCall represents a single tool invocation within an agent step
|
||||
type ToolCall struct {
|
||||
ID string `json:"id"` // Function call ID from LLM
|
||||
Name string `json:"name"` // Tool name
|
||||
Args map[string]interface{} `json:"args"` // Tool arguments
|
||||
Result *ToolResult `json:"result"` // Execution result
|
||||
Reflection string `json:"reflection,omitempty"` // Agent's reflection on this tool call result
|
||||
Duration int64 `json:"duration"` // Execution time in milliseconds
|
||||
}
|
||||
|
||||
// AgentStep represents one iteration of the ReAct loop
|
||||
type AgentStep struct {
|
||||
Iteration int `json:"iteration"` // Iteration number (0-indexed)
|
||||
Thought string `json:"thought"` // LLM's reasoning/thinking (Think phase)
|
||||
ToolCalls []ToolCall `json:"tool_calls"` // Tools called in this step (Act phase)
|
||||
Timestamp time.Time `json:"timestamp"` // When this step occurred
|
||||
}
|
||||
|
||||
// Message message information
|
||||
type Message struct {
|
||||
ID string `json:"id"`
|
||||
@@ -20,6 +46,7 @@ type Message struct {
|
||||
Content string `json:"content"`
|
||||
Role string `json:"role"`
|
||||
KnowledgeReferences []*SearchResult `json:"knowledge_references"`
|
||||
AgentSteps []AgentStep `json:"agent_steps,omitempty"` // Agent execution steps (only for assistant messages)
|
||||
IsCompleted bool `json:"is_completed"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
+36
-25
@@ -49,41 +49,52 @@ type SummaryConfig struct {
|
||||
MaxCompletionTokens int `json:"max_completion_tokens"`
|
||||
}
|
||||
|
||||
// AgentConfig defines session-level agent configuration (matches server struct).
|
||||
type AgentConfig struct {
|
||||
// SessionAgentConfig defines session-level agent configuration (matches server struct).
|
||||
// Sessions only store Enabled and KnowledgeBases; other configs are read from Tenant at runtime
|
||||
type SessionAgentConfig struct {
|
||||
AgentModeEnabled bool `json:"agent_mode_enabled"` // Whether agent mode is enabled for this session
|
||||
WebSearchEnabled bool `json:"web_search_enabled"` // Whether web search is enabled for this session
|
||||
KnowledgeBases []string `json:"knowledge_bases"` // Accessible knowledge base IDs
|
||||
KnowledgeBases []string `json:"knowledge_bases"` // Accessible knowledge base IDs for this session
|
||||
}
|
||||
|
||||
// CreateSessionRequest session creation request
|
||||
type CreateSessionRequest struct {
|
||||
KnowledgeBaseID string `json:"knowledge_base_id"` // Associated knowledge base ID (optional in agent mode)
|
||||
SessionStrategy *SessionStrategy `json:"session_strategy"` // Session strategy
|
||||
AgentConfig *AgentConfig `json:"agent_config"` // Agent configuration (optional, for agent mode)
|
||||
KnowledgeBaseID string `json:"knowledge_base_id"` // Associated knowledge base ID (optional in agent mode)
|
||||
SessionStrategy *SessionStrategy `json:"session_strategy"` // Session strategy
|
||||
AgentConfig *SessionAgentConfig `json:"agent_config"` // Agent configuration (optional, for agent mode)
|
||||
}
|
||||
|
||||
// ContextConfig configures LLM context management
|
||||
type ContextConfig struct {
|
||||
MaxTokens int `json:"max_tokens"` // Maximum tokens allowed in LLM context
|
||||
CompressionStrategy string `json:"compression_strategy"` // Compression strategy: "sliding_window" or "smart"
|
||||
RecentMessageCount int `json:"recent_message_count"` // Number of recent messages to keep
|
||||
SummarizeThreshold int `json:"summarize_threshold"` // Number of messages before summarization
|
||||
}
|
||||
|
||||
// Session session information
|
||||
type Session struct {
|
||||
ID string `json:"id"`
|
||||
TenantID uint `json:"tenant_id"`
|
||||
KnowledgeBaseID string `json:"knowledge_base_id"`
|
||||
Title string `json:"title"`
|
||||
MaxRounds int `json:"max_rounds"`
|
||||
EnableRewrite bool `json:"enable_rewrite"`
|
||||
FallbackStrategy string `json:"fallback_strategy"`
|
||||
FallbackResponse string `json:"fallback_response"`
|
||||
EmbeddingTopK int `json:"embedding_top_k"`
|
||||
KeywordThreshold float64 `json:"keyword_threshold"`
|
||||
VectorThreshold float64 `json:"vector_threshold"`
|
||||
RerankModelID string `json:"rerank_model_id"`
|
||||
RerankTopK int `json:"rerank_top_k"`
|
||||
RerankThreshold float64 `json:"reranking_threshold"` // Reranking threshold
|
||||
SummaryModelID string `json:"summary_model_id"`
|
||||
SummaryParameters *SummaryConfig `json:"summary_parameters"`
|
||||
AgentConfig *AgentConfig `json:"agent_config"` // Agent configuration (optional)
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
ID string `json:"id"`
|
||||
TenantID uint64 `json:"tenant_id"`
|
||||
KnowledgeBaseID string `json:"knowledge_base_id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
MaxRounds int `json:"max_rounds"`
|
||||
EnableRewrite bool `json:"enable_rewrite"`
|
||||
FallbackStrategy string `json:"fallback_strategy"`
|
||||
FallbackResponse string `json:"fallback_response"`
|
||||
EmbeddingTopK int `json:"embedding_top_k"`
|
||||
KeywordThreshold float64 `json:"keyword_threshold"`
|
||||
VectorThreshold float64 `json:"vector_threshold"`
|
||||
RerankModelID string `json:"rerank_model_id"`
|
||||
RerankTopK int `json:"rerank_top_k"`
|
||||
RerankThreshold float64 `json:"rerank_threshold"` // Reranking threshold
|
||||
SummaryModelID string `json:"summary_model_id"`
|
||||
SummaryParameters *SummaryConfig `json:"summary_parameters"`
|
||||
AgentConfig *SessionAgentConfig `json:"agent_config"` // Agent configuration (optional)
|
||||
ContextConfig *ContextConfig `json:"context_config"` // Context management configuration (optional)
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}
|
||||
|
||||
// SessionResponse session response
|
||||
|
||||
+5
-1
@@ -24,7 +24,7 @@ type RetrieverEngineParams struct {
|
||||
|
||||
// Tenant represents tenant information in the system
|
||||
type Tenant struct {
|
||||
ID uint `yaml:"id" json:"id" gorm:"primaryKey"`
|
||||
ID uint64 `yaml:"id" json:"id" gorm:"primaryKey"`
|
||||
// Tenant name
|
||||
Name string `yaml:"name" json:"name"`
|
||||
// Tenant description
|
||||
@@ -37,6 +37,10 @@ type Tenant struct {
|
||||
RetrieverEngines RetrieverEngines `yaml:"retriever_engines" json:"retriever_engines" gorm:"type:json"`
|
||||
// Business/department information
|
||||
Business string `yaml:"business" json:"business"`
|
||||
// Storage quota (Bytes), default is 10GB
|
||||
StorageQuota int64 `yaml:"storage_quota" json:"storage_quota" gorm:"default:10737418240"`
|
||||
// Storage used (Bytes)
|
||||
StorageUsed int64 `yaml:"storage_used" json:"storage_used" gorm:"default:0"`
|
||||
// Creation timestamp
|
||||
CreatedAt time.Time `yaml:"created_at" json:"created_at"`
|
||||
// Last update timestamp
|
||||
|
||||
Reference in New Issue
Block a user