universal-function-zsd 1.8.0__tar.gz → 1.8.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: universal_function_zsd
3
- Version: 1.8.0
3
+ Version: 1.8.2
4
4
  Summary: 可用于大部分项目的通用型函数库
5
5
  Author-email: Colin Zhang <zsd0830@163.com>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "universal_function_zsd"
3
- version = "1.8.0"
3
+ version = "1.8.2"
4
4
  authors = [
5
5
  { name = "Colin Zhang", email = "zsd0830@163.com" },
6
6
  ]
@@ -833,8 +833,7 @@ def get_llm_response(
833
833
  sys_prompt: str,
834
834
  base_prompt: str,
835
835
  max_tokens: int,
836
- platform_name: str = 'qwen',
837
- enable_thinking: bool = False,
836
+ extra_body: dict = None,
838
837
  if_stream: bool = False,
839
838
  temperature: float = 0.1,
840
839
  top_p: float = 0.95,
@@ -845,10 +844,8 @@ def get_llm_response(
845
844
  if sys_prompt:
846
845
  messages_input.append({"role": "system", "content": sys_prompt})
847
846
  messages_input.append({"role": "user", "content": base_prompt})
848
- extra_body = {}
849
- if platform_name == "qwen":
850
- # 百炼支持enable_thinking;qianfan千帆不支持该参数
851
- extra_body["enable_thinking"] = enable_thinking
847
+ if extra_body is None:
848
+ extra_body = {}
852
849
  for attempt_idx in range(retry_times + 1):
853
850
  try:
854
851
  response = llm_client.chat.completions.create(
@@ -871,4 +868,27 @@ def get_llm_response(
871
868
  continue
872
869
  else:
873
870
  return ''
874
- return ''
871
+ return ''
872
+
873
+ def extract_dict(text):
874
+ code_block_pattern = re.compile(r"```(?:json)?\s*\n?([\s\S]*?)\n?```")
875
+ match = code_block_pattern.search(text)
876
+ if match:
877
+ raw = match.group(1)
878
+ else:
879
+ # Step2:兜底,提取从第一个 { / [ 到最后一个 } / ]
880
+ start_idx = min(
881
+ idx for idx in [text.find("{"), text.find("[")] if idx != -1
882
+ )
883
+ end_idx = max(
884
+ idx for idx in [text.rfind("}"), text.rfind("]")] if idx != -1
885
+ )
886
+ raw = text[start_idx:end_idx + 1]
887
+
888
+ # Step3:清洗非法控制字符(保留 \t \r \n)
889
+ clean_json = re.sub(r'[\x00-\x08\x0b\x0c\x0e-\x1f]', '', raw)
890
+ try:
891
+ return json.loads(clean_json)
892
+ except json.JSONDecodeError as e:
893
+ logger.warning(f"JSON解析失败:{e}, 原始的清洗后文本:{clean_json}")
894
+ return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: universal_function_zsd
3
- Version: 1.8.0
3
+ Version: 1.8.2
4
4
  Summary: 可用于大部分项目的通用型函数库
5
5
  Author-email: Colin Zhang <zsd0830@163.com>
6
6
  Classifier: Programming Language :: Python :: 3