feat: 依据 LLM 参数实例化 client

This commit is contained in:
2026-04-19 15:12:32 +08:00
parent 8cb77d38c1
commit 004a5d685a
4 changed files with 103 additions and 43 deletions
+29
View File
@@ -0,0 +1,29 @@
package llm
import (
"fmt"
"knowledge-graph-backend/internal/config"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/llms/openai"
)
type Client struct {
llm llms.Model
config config.LLMConfig
}
// 创建 LLM 实例
func NewClient(cfg config.LLMConfig) (*Client, error) {
model, err := openai.New(
openai.WithToken(cfg.APIKey),
openai.WithBaseURL(cfg.BaseURL),
openai.WithModel(cfg.Model),
)
if err != nil {
return nil, fmt.Errorf("failed to create llm client: %w", err)
}
return &Client{config: cfg, llm: model}, nil
}