You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #
  2. # Copyright 2025 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 re
  17. from api.db import LLMType
  18. from rag.nlp import rag_tokenizer
  19. from api.db.services.llm_service import LLMBundle
  20. from rag.nlp import tokenize
  21. def chunk(filename, binary, tenant_id, lang, callback=None, **kwargs):
  22. doc = {
  23. "docnm_kwd": filename,
  24. "title_tks": rag_tokenizer.tokenize(re.sub(r"\.[a-zA-Z]+$", "", filename))
  25. }
  26. doc["title_sm_tks"] = rag_tokenizer.fine_grained_tokenize(doc["title_tks"])
  27. # is it English
  28. eng = lang.lower() == "english" # is_english(sections)
  29. try:
  30. callback(0.1, "USE Sequence2Txt LLM to transcription the audio")
  31. seq2txt_mdl = LLMBundle(tenant_id, LLMType.SPEECH2TEXT, lang=lang)
  32. ans = seq2txt_mdl.transcription(binary)
  33. callback(0.8, "Sequence2Txt LLM respond: %s ..." % ans[:32])
  34. tokenize(doc, ans, eng)
  35. return [doc]
  36. except Exception as e:
  37. callback(prog=-1, msg=str(e))
  38. return []