| 123456789101112131415161718192021 |
- package extractor
- import "context"
- // LLMClientInterface 接口(避免循环依赖)
- type LLMClientInterface interface {
- ParseMerchant(ctx context.Context, message string) (*MerchantInfo, error)
- }
- // LLMExtract 当正则提取无结果时,调用 LLM 提取
- // 如果 LLM 调用失败,返回 nil 不报错
- func LLMExtract(ctx context.Context, llmClient LLMClientInterface, text string) *MerchantInfo {
- if llmClient == nil || text == "" {
- return nil
- }
- info, err := llmClient.ParseMerchant(ctx, text)
- if err != nil {
- return nil
- }
- return info
- }
|