Copilot commented on code in PR #1319:
URL: https://github.com/apache/dubbo-admin/pull/1319#discussion_r2314408258


##########
ai/internal/agent/flow.go:
##########
@@ -0,0 +1,182 @@
+package agent
+
+import (
+       "context"
+
+       "dubbo-admin-ai/internal/config"
+       "dubbo-admin-ai/internal/manager"
+       "dubbo-admin-ai/internal/schema"
+       "dubbo-admin-ai/internal/tools"
+       "errors"
+       "fmt"
+       "log"
+       "os"
+
+       "github.com/firebase/genkit/go/core/logger"
+
+       "github.com/firebase/genkit/go/ai"
+       "github.com/firebase/genkit/go/core"
+       "github.com/firebase/genkit/go/genkit"
+)
+
+// 公开的 Flow 变量,以便在编排器中调用
+var (
+       ReActFlow    *core.Flow[schema.ReActIn, schema.ReActOut, struct{}]
+       ThinkingFlow *core.Flow[schema.ThinkIn, *schema.ThinkOut, struct{}]
+       ActFlow      *core.Flow[*schema.ActIn, schema.ActOut, struct{}]
+
+       ThinkPrompt *ai.Prompt
+)

Review Comment:
   Global variables for flows create tight coupling and make testing difficult. 
Consider encapsulating these in a struct or using dependency injection to 
manage flow instances.



##########
ai/internal/config/config.go:
##########
@@ -0,0 +1,25 @@
+package config
+
+import (
+       "dubbo-admin-ai/plugins/siliconflow"
+       "os"
+       "path/filepath"
+       "runtime"
+)
+
+var (
+       // API keys
+       GEMINI_API_KEY      string = os.Getenv("GEMINI_API_KEY")
+       SILICONFLOW_API_KEY string = os.Getenv("SILICONFLOW_API_KEY")
+       DASHSCOPE_API_KEY   string = os.Getenv("DASHSCOPE_API_KEY")
+
+       // Configuration
+       // 自动获取项目根目录
+       _, b, _, _   = runtime.Caller(0)
+       PROJECT_ROOT = filepath.Join(filepath.Dir(b), "..", "..")

Review Comment:
   Using runtime.Caller(0) to determine project root at package level creates 
fragile path dependencies. Consider using go:embed or making PROJECT_ROOT 
configurable via environment variable to improve maintainability and testing.



##########
ai/internal/manager/manager.go:
##########
@@ -0,0 +1,126 @@
+package manager
+
+import (
+       "context"
+
+       "dubbo-admin-ai/internal/config"
+
+       "dubbo-admin-ai/plugins/dashscope"
+       "dubbo-admin-ai/plugins/siliconflow"
+       "dubbo-admin-ai/utils"
+       "fmt"
+       "log/slog"
+       "os"
+       "path/filepath"
+       "strings"
+       "time"
+
+       "github.com/firebase/genkit/go/core/logger"
+       "github.com/firebase/genkit/go/genkit"
+       "github.com/firebase/genkit/go/plugins/googlegenai"
+       "github.com/joho/godotenv"
+       "github.com/lmittmann/tint"
+)
+
+var (
+       globalGenkit *genkit.Genkit
+       rootContext  *context.Context
+       globalLogger *slog.Logger
+)

Review Comment:
   Using global variables for dependency management violates dependency 
injection principles and makes testing difficult. Consider using a struct-based 
approach or dependency injection container to manage these dependencies.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to