universal-function-zsd 1.8.2__tar.gz → 1.8.3__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.2
3
+ Version: 1.8.3
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.2"
3
+ version = "1.8.3"
4
4
  authors = [
5
5
  { name = "Colin Zhang", email = "zsd0830@163.com" },
6
6
  ]
@@ -20,6 +20,7 @@ import sys
20
20
  from openpyxl import load_workbook
21
21
  import xlwings as xw
22
22
  from openai import OpenAI
23
+ from loguru import logger
23
24
 
24
25
  # 通用参数
25
26
  #########################################################################
@@ -841,9 +842,14 @@ def get_llm_response(
841
842
  timeout: int = 3000):
842
843
  llm_client = OpenAI(api_key=api_key, base_url=base_url, timeout=timeout)
843
844
  messages_input = []
845
+ print(f'-'*50)
846
+ print(f'*** 大模型【{llm_model}】解析中...')
844
847
  if sys_prompt:
848
+ print(f'*** SYSTEM输入 ***\n{sys_prompt[:1000]}......')
845
849
  messages_input.append({"role": "system", "content": sys_prompt})
846
850
  messages_input.append({"role": "user", "content": base_prompt})
851
+ print(f'*** USER输入 ***\n{base_prompt[:1000]}......')
852
+ print(f'-'*50)
847
853
  if extra_body is None:
848
854
  extra_body = {}
849
855
  for attempt_idx in range(retry_times + 1):
@@ -858,17 +864,22 @@ def get_llm_response(
858
864
  extra_body=extra_body
859
865
  )
860
866
  if not if_stream:
867
+ print(f'*** 输出结果 ***')
868
+ print(response.choices[0].message.content)
869
+ print(f'-' * 50)
861
870
  return response.choices[0].message.content
862
871
  else:
863
872
  return response # 流式输出需要做特殊处理(增量片段解析)
864
873
  except Exception as e:
865
- print('调用失败,重新尝试...')
866
874
  if attempt_idx < retry_times:
875
+ print(f'调用失败,开始第【{attempt_idx}】次尝试...')
867
876
  time.sleep(1)
868
877
  continue
869
878
  else:
870
- return ''
871
- return ''
879
+ print(f'调用失败,尝试次数达上限,返回None...')
880
+ return None
881
+ print(f'调用失败,返回None...')
882
+ return None
872
883
 
873
884
  def extract_dict(text):
874
885
  code_block_pattern = re.compile(r"```(?:json)?\s*\n?([\s\S]*?)\n?```")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: universal_function_zsd
3
- Version: 1.8.2
3
+ Version: 1.8.3
4
4
  Summary: 可用于大部分项目的通用型函数库
5
5
  Author-email: Colin Zhang <zsd0830@163.com>
6
6
  Classifier: Programming Language :: Python :: 3