Files
knowledge-graph-agent/backend/internal/llm/client.go
T

29 lines
566 B
Go
Raw Normal View History

2026-04-19 15:12:32 +08:00
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
}