refactor: Update function signatures across multiple files to improve readability by adding context parameters and enhancing code structure
This commit is contained in:
+71
-71
@@ -14,16 +14,16 @@ import (
|
||||
|
||||
// Config 应用程序总配置
|
||||
type Config struct {
|
||||
Conversation *ConversationConfig `yaml:"conversation" json:"conversation"`
|
||||
Server *ServerConfig `yaml:"server" json:"server"`
|
||||
KnowledgeBase *KnowledgeBaseConfig `yaml:"knowledge_base" json:"knowledge_base"`
|
||||
Tenant *TenantConfig `yaml:"tenant" json:"tenant"`
|
||||
Models []ModelConfig `yaml:"models" json:"models"`
|
||||
Conversation *ConversationConfig `yaml:"conversation" json:"conversation"`
|
||||
Server *ServerConfig `yaml:"server" json:"server"`
|
||||
KnowledgeBase *KnowledgeBaseConfig `yaml:"knowledge_base" json:"knowledge_base"`
|
||||
Tenant *TenantConfig `yaml:"tenant" json:"tenant"`
|
||||
Models []ModelConfig `yaml:"models" json:"models"`
|
||||
VectorDatabase *VectorDatabaseConfig `yaml:"vector_database" json:"vector_database"`
|
||||
DocReader *DocReaderConfig `yaml:"docreader" json:"docreader"`
|
||||
StreamManager *StreamManagerConfig `yaml:"stream_manager" json:"stream_manager"`
|
||||
ExtractManager *ExtractManagerConfig `yaml:"extract" json:"extract"`
|
||||
WebSearch *WebSearchConfig `yaml:"web_search" json:"web_search"`
|
||||
DocReader *DocReaderConfig `yaml:"docreader" json:"docreader"`
|
||||
StreamManager *StreamManagerConfig `yaml:"stream_manager" json:"stream_manager"`
|
||||
ExtractManager *ExtractManagerConfig `yaml:"extract" json:"extract"`
|
||||
WebSearch *WebSearchConfig `yaml:"web_search" json:"web_search"`
|
||||
}
|
||||
|
||||
type DocReaderConfig struct {
|
||||
@@ -36,59 +36,59 @@ type VectorDatabaseConfig struct {
|
||||
|
||||
// ConversationConfig 对话服务配置
|
||||
type ConversationConfig struct {
|
||||
MaxRounds int `yaml:"max_rounds" json:"max_rounds"`
|
||||
KeywordThreshold float64 `yaml:"keyword_threshold" json:"keyword_threshold"`
|
||||
EmbeddingTopK int `yaml:"embedding_top_k" json:"embedding_top_k"`
|
||||
VectorThreshold float64 `yaml:"vector_threshold" json:"vector_threshold"`
|
||||
RerankTopK int `yaml:"rerank_top_k" json:"rerank_top_k"`
|
||||
RerankThreshold float64 `yaml:"rerank_threshold" json:"rerank_threshold"`
|
||||
FallbackStrategy string `yaml:"fallback_strategy" json:"fallback_strategy"`
|
||||
FallbackResponse string `yaml:"fallback_response" json:"fallback_response"`
|
||||
FallbackPrompt string `yaml:"fallback_prompt" json:"fallback_prompt"`
|
||||
EnableRewrite bool `yaml:"enable_rewrite" json:"enable_rewrite"`
|
||||
EnableQueryExpansion bool `yaml:"enable_query_expansion" json:"enable_query_expansion"`
|
||||
EnableRerank bool `yaml:"enable_rerank" json:"enable_rerank"`
|
||||
Summary *SummaryConfig `yaml:"summary" json:"summary"`
|
||||
MaxRounds int `yaml:"max_rounds" json:"max_rounds"`
|
||||
KeywordThreshold float64 `yaml:"keyword_threshold" json:"keyword_threshold"`
|
||||
EmbeddingTopK int `yaml:"embedding_top_k" json:"embedding_top_k"`
|
||||
VectorThreshold float64 `yaml:"vector_threshold" json:"vector_threshold"`
|
||||
RerankTopK int `yaml:"rerank_top_k" json:"rerank_top_k"`
|
||||
RerankThreshold float64 `yaml:"rerank_threshold" json:"rerank_threshold"`
|
||||
FallbackStrategy string `yaml:"fallback_strategy" json:"fallback_strategy"`
|
||||
FallbackResponse string `yaml:"fallback_response" json:"fallback_response"`
|
||||
FallbackPrompt string `yaml:"fallback_prompt" json:"fallback_prompt"`
|
||||
EnableRewrite bool `yaml:"enable_rewrite" json:"enable_rewrite"`
|
||||
EnableQueryExpansion bool `yaml:"enable_query_expansion" json:"enable_query_expansion"`
|
||||
EnableRerank bool `yaml:"enable_rerank" json:"enable_rerank"`
|
||||
Summary *SummaryConfig `yaml:"summary" json:"summary"`
|
||||
GenerateSessionTitlePrompt string `yaml:"generate_session_title_prompt" json:"generate_session_title_prompt"`
|
||||
GenerateSummaryPrompt string `yaml:"generate_summary_prompt" json:"generate_summary_prompt"`
|
||||
RewritePromptSystem string `yaml:"rewrite_prompt_system" json:"rewrite_prompt_system"`
|
||||
RewritePromptUser string `yaml:"rewrite_prompt_user" json:"rewrite_prompt_user"`
|
||||
SimplifyQueryPrompt string `yaml:"simplify_query_prompt" json:"simplify_query_prompt"`
|
||||
SimplifyQueryPromptUser string `yaml:"simplify_query_prompt_user" json:"simplify_query_prompt_user"`
|
||||
ExtractEntitiesPrompt string `yaml:"extract_entities_prompt" json:"extract_entities_prompt"`
|
||||
ExtractRelationshipsPrompt string `yaml:"extract_relationships_prompt" json:"extract_relationships_prompt"`
|
||||
GenerateSummaryPrompt string `yaml:"generate_summary_prompt" json:"generate_summary_prompt"`
|
||||
RewritePromptSystem string `yaml:"rewrite_prompt_system" json:"rewrite_prompt_system"`
|
||||
RewritePromptUser string `yaml:"rewrite_prompt_user" json:"rewrite_prompt_user"`
|
||||
SimplifyQueryPrompt string `yaml:"simplify_query_prompt" json:"simplify_query_prompt"`
|
||||
SimplifyQueryPromptUser string `yaml:"simplify_query_prompt_user" json:"simplify_query_prompt_user"`
|
||||
ExtractEntitiesPrompt string `yaml:"extract_entities_prompt" json:"extract_entities_prompt"`
|
||||
ExtractRelationshipsPrompt string `yaml:"extract_relationships_prompt" json:"extract_relationships_prompt"`
|
||||
}
|
||||
|
||||
// SummaryConfig 摘要配置
|
||||
type SummaryConfig struct {
|
||||
MaxTokens int `yaml:"max_tokens" json:"max_tokens"`
|
||||
RepeatPenalty float64 `yaml:"repeat_penalty" json:"repeat_penalty"`
|
||||
TopK int `yaml:"top_k" json:"top_k"`
|
||||
TopP float64 `yaml:"top_p" json:"top_p"`
|
||||
FrequencyPenalty float64 `yaml:"frequency_penalty" json:"frequency_penalty"`
|
||||
PresencePenalty float64 `yaml:"presence_penalty" json:"presence_penalty"`
|
||||
Prompt string `yaml:"prompt" json:"prompt"`
|
||||
ContextTemplate string `yaml:"context_template" json:"context_template"`
|
||||
Temperature float64 `yaml:"temperature" json:"temperature"`
|
||||
Seed int `yaml:"seed" json:"seed"`
|
||||
MaxTokens int `yaml:"max_tokens" json:"max_tokens"`
|
||||
RepeatPenalty float64 `yaml:"repeat_penalty" json:"repeat_penalty"`
|
||||
TopK int `yaml:"top_k" json:"top_k"`
|
||||
TopP float64 `yaml:"top_p" json:"top_p"`
|
||||
FrequencyPenalty float64 `yaml:"frequency_penalty" json:"frequency_penalty"`
|
||||
PresencePenalty float64 `yaml:"presence_penalty" json:"presence_penalty"`
|
||||
Prompt string `yaml:"prompt" json:"prompt"`
|
||||
ContextTemplate string `yaml:"context_template" json:"context_template"`
|
||||
Temperature float64 `yaml:"temperature" json:"temperature"`
|
||||
Seed int `yaml:"seed" json:"seed"`
|
||||
MaxCompletionTokens int `yaml:"max_completion_tokens" json:"max_completion_tokens"`
|
||||
NoMatchPrefix string `yaml:"no_match_prefix" json:"no_match_prefix"`
|
||||
NoMatchPrefix string `yaml:"no_match_prefix" json:"no_match_prefix"`
|
||||
}
|
||||
|
||||
// ServerConfig 服务器配置
|
||||
type ServerConfig struct {
|
||||
Port int `yaml:"port" json:"port"`
|
||||
Host string `yaml:"host" json:"host"`
|
||||
LogPath string `yaml:"log_path" json:"log_path"`
|
||||
Port int `yaml:"port" json:"port"`
|
||||
Host string `yaml:"host" json:"host"`
|
||||
LogPath string `yaml:"log_path" json:"log_path"`
|
||||
ShutdownTimeout time.Duration `yaml:"shutdown_timeout" json:"shutdown_timeout" default:"30s"`
|
||||
}
|
||||
|
||||
// KnowledgeBaseConfig 知识库配置
|
||||
type KnowledgeBaseConfig struct {
|
||||
ChunkSize int `yaml:"chunk_size" json:"chunk_size"`
|
||||
ChunkOverlap int `yaml:"chunk_overlap" json:"chunk_overlap"`
|
||||
SplitMarkers []string `yaml:"split_markers" json:"split_markers"`
|
||||
KeepSeparator bool `yaml:"keep_separator" json:"keep_separator"`
|
||||
ChunkSize int `yaml:"chunk_size" json:"chunk_size"`
|
||||
ChunkOverlap int `yaml:"chunk_overlap" json:"chunk_overlap"`
|
||||
SplitMarkers []string `yaml:"split_markers" json:"split_markers"`
|
||||
KeepSeparator bool `yaml:"keep_separator" json:"keep_separator"`
|
||||
ImageProcessing *ImageProcessingConfig `yaml:"image_processing" json:"image_processing"`
|
||||
}
|
||||
|
||||
@@ -99,44 +99,44 @@ type ImageProcessingConfig struct {
|
||||
|
||||
// TenantConfig 租户配置
|
||||
type TenantConfig struct {
|
||||
DefaultSessionName string `yaml:"default_session_name" json:"default_session_name"`
|
||||
DefaultSessionTitle string `yaml:"default_session_title" json:"default_session_title"`
|
||||
DefaultSessionName string `yaml:"default_session_name" json:"default_session_name"`
|
||||
DefaultSessionTitle string `yaml:"default_session_title" json:"default_session_title"`
|
||||
DefaultSessionDescription string `yaml:"default_session_description" json:"default_session_description"`
|
||||
}
|
||||
|
||||
// ModelConfig 模型配置
|
||||
type ModelConfig struct {
|
||||
Type string `yaml:"type" json:"type"`
|
||||
Source string `yaml:"source" json:"source"`
|
||||
Type string `yaml:"type" json:"type"`
|
||||
Source string `yaml:"source" json:"source"`
|
||||
ModelName string `yaml:"model_name" json:"model_name"`
|
||||
Parameters map[string]interface{} `yaml:"parameters" json:"parameters"`
|
||||
}
|
||||
|
||||
// StreamManagerConfig 流管理器配置
|
||||
type StreamManagerConfig struct {
|
||||
Type string `yaml:"type" json:"type"` // 类型: "memory" 或 "redis"
|
||||
Redis RedisConfig `yaml:"redis" json:"redis"` // Redis配置
|
||||
Type string `yaml:"type" json:"type"` // 类型: "memory" 或 "redis"
|
||||
Redis RedisConfig `yaml:"redis" json:"redis"` // Redis配置
|
||||
CleanupTimeout time.Duration `yaml:"cleanup_timeout" json:"cleanup_timeout"` // 清理超时,单位秒
|
||||
}
|
||||
|
||||
// RedisConfig Redis配置
|
||||
type RedisConfig struct {
|
||||
Address string `yaml:"address" json:"address"` // Redis地址
|
||||
Address string `yaml:"address" json:"address"` // Redis地址
|
||||
Password string `yaml:"password" json:"password"` // Redis密码
|
||||
DB int `yaml:"db" json:"db"` // Redis数据库
|
||||
Prefix string `yaml:"prefix" json:"prefix"` // 键前缀
|
||||
TTL time.Duration `yaml:"ttl" json:"ttl"` // 过期时间(小时)
|
||||
DB int `yaml:"db" json:"db"` // Redis数据库
|
||||
Prefix string `yaml:"prefix" json:"prefix"` // 键前缀
|
||||
TTL time.Duration `yaml:"ttl" json:"ttl"` // 过期时间(小时)
|
||||
}
|
||||
|
||||
// ExtractManagerConfig 抽取管理器配置
|
||||
type ExtractManagerConfig struct {
|
||||
ExtractGraph *types.PromptTemplateStructured `yaml:"extract_graph" json:"extract_graph"`
|
||||
ExtractGraph *types.PromptTemplateStructured `yaml:"extract_graph" json:"extract_graph"`
|
||||
ExtractEntity *types.PromptTemplateStructured `yaml:"extract_entity" json:"extract_entity"`
|
||||
FabriText *FebriText `yaml:"fabri_text" json:"fabri_text"`
|
||||
FabriText *FebriText `yaml:"fabri_text" json:"fabri_text"`
|
||||
}
|
||||
|
||||
type FebriText struct {
|
||||
WithTag string `yaml:"with_tag" json:"with_tag"`
|
||||
WithTag string `yaml:"with_tag" json:"with_tag"`
|
||||
WithNoTag string `yaml:"with_no_tag" json:"with_no_tag"`
|
||||
}
|
||||
|
||||
@@ -194,25 +194,25 @@ func LoadConfig() (*Config, error) {
|
||||
// WebSearchConfig represents the web search configuration
|
||||
type WebSearchConfig struct {
|
||||
Providers []WebSearchProviderConfig `yaml:"providers" json:"providers"`
|
||||
Default WebSearchDefaultConfig `yaml:"default" json:"default"`
|
||||
Timeout int `yaml:"timeout" json:"timeout"` // 超时时间(秒)
|
||||
Default WebSearchDefaultConfig `yaml:"default" json:"default"`
|
||||
Timeout int `yaml:"timeout" json:"timeout"` // 超时时间(秒)
|
||||
}
|
||||
|
||||
// WebSearchProviderConfig represents configuration for a web search provider
|
||||
type WebSearchProviderConfig struct {
|
||||
ID string `yaml:"id" json:"id"`
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Free bool `yaml:"free" json:"free"`
|
||||
RequiresAPIKey bool `yaml:"requires_api_key" json:"requires_api_key"`
|
||||
ID string `yaml:"id" json:"id"`
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Free bool `yaml:"free" json:"free"`
|
||||
RequiresAPIKey bool `yaml:"requires_api_key" json:"requires_api_key"`
|
||||
Description string `yaml:"description,omitempty" json:"description,omitempty"`
|
||||
APIURL string `yaml:"api_url,omitempty" json:"api_url,omitempty"`
|
||||
APIURL string `yaml:"api_url,omitempty" json:"api_url,omitempty"`
|
||||
}
|
||||
|
||||
// WebSearchDefaultConfig represents the default web search configuration
|
||||
type WebSearchDefaultConfig struct {
|
||||
Provider string `yaml:"provider" json:"provider"`
|
||||
MaxResults int `yaml:"max_results" json:"max_results"`
|
||||
IncludeDate bool `yaml:"include_date" json:"include_date"`
|
||||
Provider string `yaml:"provider" json:"provider"`
|
||||
MaxResults int `yaml:"max_results" json:"max_results"`
|
||||
IncludeDate bool `yaml:"include_date" json:"include_date"`
|
||||
CompressionMethod string `yaml:"compression_method" json:"compression_method"`
|
||||
Blacklist []string `yaml:"blacklist" json:"blacklist"`
|
||||
Blacklist []string `yaml:"blacklist" json:"blacklist"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user