Refactor Worker Initialization to Integrate GLM SDK
- Updated the worker initialization process to include the new GLM SDK, enhancing the worker's capabilities for translation tasks. - Modified the InitWorker function and NewNoticeWorker constructor to accept the GLM service, ensuring a cohesive integration. - Implemented the GLM service initialization and logging for successful setup, improving maintainability and usability. - Updated the NoticeWorker to utilize the GLM SDK for translating notice titles and descriptions, enhancing functionality and user experience.
This commit is contained in:
+68
-4
@@ -15,11 +15,75 @@ type SDK struct {
|
||||
|
||||
// New creates a new GLM SDK with the provided configuration and logger
|
||||
func New(config *Config, logger logger.Logger) (*SDK, error) {
|
||||
if config == nil {
|
||||
config = DefaultConfig()
|
||||
cfg := DefaultConfig()
|
||||
if config.BaseURL != "" {
|
||||
cfg.BaseURL = config.BaseURL
|
||||
}
|
||||
if config.APIKey != "" {
|
||||
cfg.APIKey = config.APIKey
|
||||
}
|
||||
if config.Timeout != 0 {
|
||||
cfg.Timeout = config.Timeout
|
||||
}
|
||||
if config.RetryAttempts != 0 {
|
||||
cfg.RetryAttempts = config.RetryAttempts
|
||||
}
|
||||
if config.RetryDelay != 0 {
|
||||
cfg.RetryDelay = config.RetryDelay
|
||||
}
|
||||
if config.EnableLogging {
|
||||
cfg.EnableLogging = config.EnableLogging
|
||||
}
|
||||
if config.UserAgent != "" {
|
||||
cfg.UserAgent = config.UserAgent
|
||||
}
|
||||
if config.DefaultModel != "" {
|
||||
cfg.DefaultModel = config.DefaultModel
|
||||
}
|
||||
if config.DefaultMaxTokens != 0 {
|
||||
cfg.DefaultMaxTokens = config.DefaultMaxTokens
|
||||
}
|
||||
if config.DefaultTopP != 0 {
|
||||
cfg.DefaultTopP = config.DefaultTopP
|
||||
}
|
||||
if config.DefaultTemperature != 0 {
|
||||
cfg.DefaultTemperature = config.DefaultTemperature
|
||||
}
|
||||
if config.DefaultFrequencyPenalty != 0 {
|
||||
cfg.DefaultFrequencyPenalty = config.DefaultFrequencyPenalty
|
||||
}
|
||||
if config.DefaultPresencePenalty != 0 {
|
||||
cfg.DefaultPresencePenalty = config.DefaultPresencePenalty
|
||||
}
|
||||
if config.EnableStreaming {
|
||||
cfg.EnableStreaming = config.EnableStreaming
|
||||
}
|
||||
if config.EnableThinking {
|
||||
cfg.EnableThinking = config.EnableThinking
|
||||
}
|
||||
if config.TranslationOptions.Model != "" {
|
||||
cfg.TranslationOptions.Model = config.TranslationOptions.Model
|
||||
}
|
||||
if config.TranslationOptions.MaxTokens != 0 {
|
||||
cfg.TranslationOptions.MaxTokens = config.TranslationOptions.MaxTokens
|
||||
}
|
||||
if config.TranslationOptions.Temperature != 0 {
|
||||
cfg.TranslationOptions.Temperature = config.TranslationOptions.Temperature
|
||||
}
|
||||
if config.TranslationOptions.FrequencyPenalty != 0 {
|
||||
cfg.TranslationOptions.FrequencyPenalty = config.TranslationOptions.FrequencyPenalty
|
||||
}
|
||||
if config.TranslationOptions.PresencePenalty != 0 {
|
||||
cfg.TranslationOptions.PresencePenalty = config.TranslationOptions.PresencePenalty
|
||||
}
|
||||
if config.TranslationOptions.TopP != 0 {
|
||||
cfg.TranslationOptions.TopP = config.TranslationOptions.TopP
|
||||
}
|
||||
if config.TranslationOptions.EnableThinking {
|
||||
cfg.TranslationOptions.EnableThinking = config.TranslationOptions.EnableThinking
|
||||
}
|
||||
|
||||
client, err := NewClient(config, logger)
|
||||
client, err := NewClient(cfg, logger)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -29,7 +93,7 @@ func New(config *Config, logger logger.Logger) (*SDK, error) {
|
||||
return &SDK{
|
||||
service: service,
|
||||
client: client,
|
||||
config: config,
|
||||
config: cfg,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user