flashrag-dev 0.1.4.dev20250531__tar.gz → 0.1.4.dev20250610__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/PKG-INFO +1 -1
  2. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/prompt/base_prompt.py +32 -20
  3. flashrag_dev-0.1.4.dev20250610/flashrag/version.py +1 -0
  4. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag_dev.egg-info/PKG-INFO +1 -1
  5. flashrag_dev-0.1.4.dev20250531/flashrag/version.py +0 -1
  6. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/LICENSE +0 -0
  7. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/README.md +0 -0
  8. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/__init__.py +0 -0
  9. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/config/__init__.py +0 -0
  10. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/config/basic_config.yaml +0 -0
  11. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/config/config.py +0 -0
  12. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/dataset/__init__.py +0 -0
  13. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/dataset/dataset.py +0 -0
  14. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/dataset/utils.py +0 -0
  15. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/evaluator/__init__.py +0 -0
  16. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/evaluator/_bleu.py +0 -0
  17. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/evaluator/evaluator.py +0 -0
  18. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/evaluator/metrics.py +0 -0
  19. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/evaluator/utils.py +0 -0
  20. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/generator/__init__.py +0 -0
  21. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/generator/fid.py +0 -0
  22. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/generator/generator.py +0 -0
  23. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/generator/multimodal_generator.py +0 -0
  24. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/generator/openai_generator.py +0 -0
  25. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/generator/stop_word_criteria.py +0 -0
  26. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/generator/utils.py +0 -0
  27. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/judger/__init__.py +0 -0
  28. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/judger/judger.py +0 -0
  29. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/pipeline/__init__.py +0 -0
  30. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/pipeline/active_pipeline.py +0 -0
  31. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/pipeline/branching_pipeline.py +0 -0
  32. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/pipeline/mm_pipeline.py +0 -0
  33. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/pipeline/pipeline.py +0 -0
  34. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/pipeline/reasoning_pipeline.py +0 -0
  35. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/pipeline/replug_utils.py +0 -0
  36. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/prompt/__init__.py +0 -0
  37. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/prompt/mm_prompt.py +0 -0
  38. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/prompt/selfask_examplars.py +0 -0
  39. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/prompt/trace_examplars.py +0 -0
  40. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/refiner/__init__.py +0 -0
  41. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/refiner/kg_refiner.py +0 -0
  42. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/refiner/llmlingua_compressor.py +0 -0
  43. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/refiner/refiner.py +0 -0
  44. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/refiner/selective_context_compressor.py +0 -0
  45. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/retriever/__init__.py +0 -0
  46. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/retriever/__main__.py +0 -0
  47. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/retriever/encoder.py +0 -0
  48. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/retriever/index_builder.py +0 -0
  49. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/retriever/reranker.py +0 -0
  50. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/retriever/retriever.py +0 -0
  51. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/retriever/utils.py +0 -0
  52. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/utils/__init__.py +0 -0
  53. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/utils/constants.py +0 -0
  54. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/utils/pred_parse.py +0 -0
  55. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag/utils/utils.py +0 -0
  56. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag_dev.egg-info/SOURCES.txt +0 -0
  57. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag_dev.egg-info/dependency_links.txt +0 -0
  58. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag_dev.egg-info/requires.txt +0 -0
  59. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/flashrag_dev.egg-info/top_level.txt +0 -0
  60. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/pyproject.toml +0 -0
  61. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/setup.cfg +0 -0
  62. {flashrag_dev-0.1.4.dev20250531 → flashrag_dev-0.1.4.dev20250610}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: flashrag_dev
3
- Version: 0.1.4.dev20250531
3
+ Version: 0.1.4.dev20250610
4
4
  Summary: A library for efficient Retrieval-Augmented Generation research
5
5
  Home-page: https://github.com/RUC-NLPIR/FlashRAG
6
6
  Author: Jiajie Jin, Yutao Zhu, Chenghao Zhang, Xinyu Yang, Zhicheng Dou
@@ -23,16 +23,9 @@ class PromptTemplate:
23
23
  self.is_chat = False
24
24
  if "chat" in model_name or "instruct" in model_name:
25
25
  self.is_chat = True
26
- self.tokenizer = AutoTokenizer.from_pretrained(self.generator_path, trust_remote_code=True)
27
26
  else:
28
27
  self.is_chat = True
29
28
  self.enable_chat = True
30
- try:
31
- self.tokenizer = tiktoken.encoding_for_model(config['generator_model'])
32
- except Exception as e:
33
- print("Error: ", e)
34
- warnings.warn("This model is not supported by tiktoken. Use gpt-3.5-turbo instead.")
35
- self.tokenizer = tiktoken.encoding_for_model('gpt-3.5-turbo')
36
29
 
37
30
  if len(system_prompt) == 0 and len(user_prompt) == 0:
38
31
  system_prompt = self.base_system_prompt
@@ -41,8 +34,22 @@ class PromptTemplate:
41
34
  self.user_prompt = user_prompt
42
35
  self.enable_chat = enable_chat
43
36
  self.reference_template = reference_template
37
+ self.tokenizer = None
44
38
 
45
39
  # self._check_placeholder()
40
+ def _get_tokenizer(self):
41
+ if self.tokenizer is None:
42
+ if self.is_openai:
43
+ try:
44
+ self.tokenizer = tiktoken.encoding_for_model(self.config['generator_model'])
45
+ except Exception as e:
46
+ print("Error: ", e)
47
+ warnings.warn("This model is not supported by tiktoken. Use gpt-3.5-turbo instead.")
48
+ self.tokenizer = tiktoken.encoding_for_model('gpt-3.5-turbo')
49
+ else:
50
+ self.tokenizer = AutoTokenizer.from_pretrained(self.generator_path, trust_remote_code=True)
51
+ return self.tokenizer
52
+
46
53
 
47
54
  def _check_placeholder(self):
48
55
  # check placeholder in prompt
@@ -64,7 +71,7 @@ class PromptTemplate:
64
71
  assert isinstance(prompt, list)
65
72
  for message in prompt:
66
73
  role_content = message['content']
67
- encoded_message = self.tokenizer.encode(role_content)
74
+ encoded_message = self._get_tokenizer().encode(role_content)
68
75
 
69
76
  if total_tokens + len(encoded_message) <= self.max_input_len:
70
77
  truncated_messages.append(message)
@@ -72,29 +79,30 @@ class PromptTemplate:
72
79
  else:
73
80
  print(f"The input text length is greater than the maximum length ({total_tokens + len(encoded_message)} > {self.max_input_len}) and has been truncated!")
74
81
  remaining_tokens = self.max_input_len - total_tokens
75
- truncated_message = self.encoding.decode(encoded_message[:remaining_tokens])
82
+ truncated_message = self._get_tokenizer().decode(encoded_message[:remaining_tokens])
76
83
  message['content'] = truncated_message
77
84
  truncated_messages.append(message)
78
85
  break
79
86
  else:
80
87
  assert isinstance(prompt, str)
81
- tokenized_prompt = self.tokenizer.encode(prompt,allowed_special={'<|endoftext|>'})
88
+ tokenized_prompt = self._get_tokenizer().encode(prompt,allowed_special={'<|endoftext|>'})
82
89
  half = int(self.max_input_len / 2)
83
- truncated_messages = self.tokenizer.decode(tokenized_prompt[:half]) + self.tokenizer.decode(tokenized_prompt[-half:])
90
+ truncated_messages = self._get_tokenizer().decode(tokenized_prompt[:half]) + self._get_tokenizer().decode(tokenized_prompt[-half:])
84
91
 
85
92
  return truncated_messages
86
93
 
87
94
  else:
88
- if self.tokenizer is None:
89
- self.tokenizer = AutoTokenizer.from_pretrained(self.generator_path, trust_remote_code=True)
90
95
  assert isinstance(prompt, str)
91
- tokenized_prompt = self.tokenizer(prompt, truncation=False, return_tensors="pt").input_ids[0]
96
+ try:
97
+ tokenized_prompt = self._get_tokenizer().encode(prompt, truncation=False, return_tensors="pt").input_ids[0]
98
+ except:
99
+ tokenized_prompt = self._get_tokenizer().encode(prompt, truncation=False, return_tensors="pt")[0]
92
100
 
93
101
  if len(tokenized_prompt) > self.max_input_len:
94
102
  print(f"The input text length is greater than the maximum length ({len(tokenized_prompt)} > {self.max_input_len}) and has been truncated!")
95
- half = int(self.max_input_len / 2)
96
- prompt = self.tokenizer.decode(tokenized_prompt[:half], skip_special_tokens=True) + \
97
- self.tokenizer.decode(tokenized_prompt[-half:], skip_special_tokens=True)
103
+ half = int(self.max_input_len / 2) - 20
104
+ prompt = self._get_tokenizer().decode(tokenized_prompt[:half], skip_special_tokens=True) + \
105
+ self._get_tokenizer().decode(tokenized_prompt[-half:], skip_special_tokens=True)
98
106
  return prompt
99
107
 
100
108
 
@@ -107,7 +115,7 @@ class PromptTemplate:
107
115
  if self.is_openai:
108
116
  self.truncate_prompt(messages)
109
117
  else:
110
- prompt = self.tokenizer.apply_chat_template(
118
+ prompt = self._get_tokenizer().apply_chat_template(
111
119
  messages, tokenize=False, add_generation_prompt=True
112
120
  )
113
121
  return self.truncate_prompt(prompt)
@@ -136,7 +144,11 @@ class PromptTemplate:
136
144
  if user_prompt != "":
137
145
  input.append({"role": "user", "content": user_prompt})
138
146
  if not self.is_openai:
139
- input = self.tokenizer.apply_chat_template(input, tokenize=False, add_generation_prompt=True)
147
+ try:
148
+ input = self._get_tokenizer().apply_chat_template(input, tokenize=False, add_generation_prompt=True)
149
+ except:
150
+ print("Warning: the generator tokenizer not support `apply_chat_template`")
151
+ input = system_prompt + '\n\n' + user_prompt
140
152
  else:
141
153
  input = "\n\n".join([prompt for prompt in [system_prompt, user_prompt] if prompt != ""])
142
154
 
@@ -180,7 +192,7 @@ class PromptTemplate:
180
192
  **params,
181
193
  )
182
194
 
183
- possible_prompt_tokens = tokenizer.encode(possible_prompt)
195
+ possible_prompt_tokens = self._get_tokenizer().encode(possible_prompt)
184
196
  if len(possible_prompt_tokens) <= max_length:
185
197
  final_examplars = examplars[:num]
186
198
  break
@@ -0,0 +1 @@
1
+ __version__ = "0.1.4dev20250610"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: flashrag-dev
3
- Version: 0.1.4.dev20250531
3
+ Version: 0.1.4.dev20250610
4
4
  Summary: A library for efficient Retrieval-Augmented Generation research
5
5
  Home-page: https://github.com/RUC-NLPIR/FlashRAG
6
6
  Author: Jiajie Jin, Yutao Zhu, Chenghao Zhang, Xinyu Yang, Zhicheng Dou
@@ -1 +0,0 @@
1
- __version__ = "0.1.4dev20250531"