ai_scheduler/internal/domain/workflow/provider_set.go

23 lines
1021 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package workflow
import (
"ai_scheduler/internal/config"
"ai_scheduler/internal/domain/workflow/runtime"
"ai_scheduler/internal/pkg/utils_ollama"
"github.com/google/wire"
)
var ProviderSetWorkflow = wire.NewSet(NewRegistry)
// NewRegistry 注入共享依赖并注册默认 Registry确保自注册工作流可被发现
func NewRegistry(conf *config.Config, llm *utils_ollama.Client) *runtime.Registry {
// 步骤1设置运行时依赖配置与LLM客户端供工作流工厂在首次实例化时使用必须在任何调用 Invoke 之前完成,否则会触发 "deps not set"
runtime.SetDeps(&runtime.Deps{Conf: conf, LLM: llm})
// 步骤2创建新的工作流注册表注册表负责按工作流ID惰性实例化并缓存单例实例保障并发访问下的安全
r := runtime.NewRegistry()
// 步骤3将该注册表设置为全局默认便于通过 runtime.Default() 获取;自注册的工作流可通过默认注册表被发现并调用
runtime.SetDefault(r)
return r
}