feat: 依据 LLM 参数实例化 client
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user