llm_extractor.go 562 B

123456789101112131415161718192021
  1. package extractor
  2. import "context"
  3. // LLMClientInterface 接口(避免循环依赖)
  4. type LLMClientInterface interface {
  5. ParseMerchant(ctx context.Context, message string) (*MerchantInfo, error)
  6. }
  7. // LLMExtract 当正则提取无结果时,调用 LLM 提取
  8. // 如果 LLM 调用失败,返回 nil 不报错
  9. func LLMExtract(ctx context.Context, llmClient LLMClientInterface, text string) *MerchantInfo {
  10. if llmClient == nil || text == "" {
  11. return nil
  12. }
  13. info, err := llmClient.ParseMerchant(ctx, text)
  14. if err != nil {
  15. return nil
  16. }
  17. return info
  18. }