Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

smoke.py 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #
  2. # Copyright 2024 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import argparse
  17. import json
  18. from api import settings
  19. import networkx as nx
  20. from api.db import LLMType
  21. from api.db.services.document_service import DocumentService
  22. from api.db.services.knowledgebase_service import KnowledgebaseService
  23. from api.db.services.llm_service import LLMBundle
  24. from api.db.services.user_service import TenantService
  25. from graphrag.general.index import Dealer
  26. from graphrag.light.graph_extractor import GraphExtractor
  27. from rag.utils.redis_conn import RedisDistributedLock
  28. settings.init_settings()
  29. if __name__ == "__main__":
  30. parser = argparse.ArgumentParser()
  31. parser.add_argument('-t', '--tenant_id', default=False, help="Tenant ID", action='store', required=True)
  32. parser.add_argument('-d', '--doc_id', default=False, help="Document ID", action='store', required=True)
  33. args = parser.parse_args()
  34. e, doc = DocumentService.get_by_id(args.doc_id)
  35. if not e:
  36. raise LookupError("Document not found.")
  37. kb_id = doc.kb_id
  38. chunks = [d["content_with_weight"] for d in
  39. settings.retrievaler.chunk_list(args.doc_id, args.tenant_id, [kb_id], max_count=6,
  40. fields=["content_with_weight"])]
  41. chunks = [("x", c) for c in chunks]
  42. RedisDistributedLock.clean_lock(kb_id)
  43. _, tenant = TenantService.get_by_id(args.tenant_id)
  44. llm_bdl = LLMBundle(args.tenant_id, LLMType.CHAT, tenant.llm_id)
  45. _, kb = KnowledgebaseService.get_by_id(kb_id)
  46. embed_bdl = LLMBundle(args.tenant_id, LLMType.EMBEDDING, kb.embd_id)
  47. dealer = Dealer(GraphExtractor, args.tenant_id, kb_id, llm_bdl, chunks, "English", embed_bdl=embed_bdl)
  48. print(json.dumps(nx.node_link_data(dealer.graph), ensure_ascii=False, indent=2))