Alanxtl commented on code in PR #847:
URL: https://github.com/apache/dubbo-go-samples/pull/847#discussion_r2108234768
##########
llm/go-server/cmd/server.go:
##########
@@ -43,30 +46,24 @@ import (
var cfg *config.Config
type ChatServer struct {
- llms map[string]*ollama.LLM
+ llm *ollama.LLM
}
func NewChatServer() (*ChatServer, error) {
+ if cfg.ModelName == "" {
+ return nil, fmt.Errorf("MODEL_NAME environment variable is not
set")
+ }
- llmMap := make(map[string]*ollama.LLM)
-
- for _, model := range cfg.OllamaModels {
- if model == "" {
- continue
- }
-
- llm, err := ollama.New(
- ollama.WithModel(model),
- ollama.WithServerURL(cfg.OllamaURL),
- )
- if err != nil {
- return nil, fmt.Errorf("failed to initialize model %s:
%v", model, err)
- }
- llmMap[model] = llm
- log.Printf("Initialized model: %s", model)
+ llm, err := ollama.New(
+ ollama.WithModel(cfg.ModelName),
+ ollama.WithServerURL(cfg.OllamaURL),
+ )
+ if err != nil {
+ return nil, fmt.Errorf("failed to initialize model %s: %v",
cfg.ModelName, err)
}
+ log.Printf("Initialized model: %s", cfg.ModelName)
Review Comment:
here
##########
llm/go-server/cmd/server.go:
##########
@@ -77,33 +74,15 @@ func (s *ChatServer) Chat(ctx context.Context, req
*chat.ChatRequest, stream cha
}
}()
- if len(s.llms) == 0 {
- return fmt.Errorf("no LLM models are initialized")
+ if s.llm == nil {
+ return fmt.Errorf("LLM model is not initialized")
}
if len(req.Messages) == 0 {
log.Println("Request contains no messages")
Review Comment:
here
##########
llm/go-server/cmd/server.go:
##########
@@ -145,43 +124,51 @@ func (s *ChatServer) Chat(ctx context.Context, req
*chat.ChatRequest, stream cha
}
return stream.Send(&chat.ChatResponse{
Content: string(chunk),
- Model: modelName,
+ Model: cfg.ModelName,
})
}),
)
if err != nil {
- log.Printf("GenerateContent failed with model %s: %v\n",
modelName, err)
- return fmt.Errorf("GenerateContent failed with model %s: %v",
modelName, err)
+ log.Printf("GenerateContent failed with model %s: %v\n",
cfg.ModelName, err)
Review Comment:
It is recommended to standardize the use of `log` by changing all uses of
the `log` library to use the `logger` library
--
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]