SimpleLLMFunc 0.2.7__tar.gz → 0.2.8__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 (26) hide show
  1. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/PKG-INFO +3 -3
  2. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/README.md +2 -2
  3. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/SimpleLLMFunc/llm_decorator/utils.py +76 -9
  4. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/pyproject.toml +1 -1
  5. simplellmfunc-0.2.7/SimpleLLMFunc/.DS_Store +0 -0
  6. simplellmfunc-0.2.7/SimpleLLMFunc/tool/agent.log +0 -5
  7. simplellmfunc-0.2.7/SimpleLLMFunc/tool/log_indices/trace_index.json +0 -12
  8. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/LICENSE +0 -0
  9. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/SimpleLLMFunc/__init__.py +0 -0
  10. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/SimpleLLMFunc/config.py +0 -0
  11. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/SimpleLLMFunc/interface/__init__.py +0 -0
  12. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/SimpleLLMFunc/interface/key_pool.py +0 -0
  13. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/SimpleLLMFunc/interface/llm_interface.py +0 -0
  14. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/SimpleLLMFunc/interface/openai_compatible.py +0 -0
  15. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/SimpleLLMFunc/interface/token_bucket.py +0 -0
  16. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/SimpleLLMFunc/llm_decorator/__init__.py +0 -0
  17. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/SimpleLLMFunc/llm_decorator/llm_chat_decorator.py +0 -0
  18. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/SimpleLLMFunc/llm_decorator/llm_function_decorator.py +0 -0
  19. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/SimpleLLMFunc/llm_decorator/multimodal_types.py +0 -0
  20. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/SimpleLLMFunc/logger/__init__.py +0 -0
  21. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/SimpleLLMFunc/logger/logger.py +0 -0
  22. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/SimpleLLMFunc/logger/logger_config.py +0 -0
  23. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/SimpleLLMFunc/tool/__init__.py +0 -0
  24. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/SimpleLLMFunc/tool/tool.py +0 -0
  25. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/SimpleLLMFunc/type/__init__.py +0 -0
  26. {simplellmfunc-0.2.7 → simplellmfunc-0.2.8}/SimpleLLMFunc/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: SimpleLLMFunc
3
- Version: 0.2.7
3
+ Version: 0.2.8
4
4
  Summary: 一个轻量但完备的LLM/Agent应用开发框架,提供装饰器实现将函数DocString作为Prompt而无需函数体具体实现但能够享受函数定义和类型标注带来效率提升的开发体验。以最Code的方式,用最少的代码将LLM能力集成到任意Python项目中。
5
5
  Author: Ni Jingzhe
6
6
  Author-email: nijingzhe@zju.edu.cn
@@ -22,7 +22,7 @@ Description-Content-Type: text/markdown
22
22
  ![SimpleLLMFunc](https://github.com/NiJingzhe/SimpleLLMFunc/blob/master/img/repocover_new.png?raw=true)
23
23
 
24
24
  <center>
25
- <h2 style="font-size:2em;">Everything is Function, Prompt is Code</h2>
25
+ <h2 style="font-size:2em;">LLM as Function, Prompt as Code</h2>
26
26
  </center>
27
27
 
28
28
  ----
@@ -36,7 +36,7 @@ Description-Content-Type: text/markdown
36
36
  [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/NiJingzhe/SimpleLLMFunc/graphs/commit-activity)
37
37
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/NiJingzhe/SimpleLLMFunc/pulls)
38
38
 
39
- ### 更新说明
39
+ ### 更新说明 (0.2.8 Latest)
40
40
  ### Look here: [Change Log](https://github.com/NiJingzhe/SimpleLLMFunc/blob/master/CHANGELOG.md)
41
41
 
42
42
  ### 文档(ReadtheDoc)
@@ -1,7 +1,7 @@
1
1
  ![SimpleLLMFunc](https://github.com/NiJingzhe/SimpleLLMFunc/blob/master/img/repocover_new.png?raw=true)
2
2
 
3
3
  <center>
4
- <h2 style="font-size:2em;">Everything is Function, Prompt is Code</h2>
4
+ <h2 style="font-size:2em;">LLM as Function, Prompt as Code</h2>
5
5
  </center>
6
6
 
7
7
  ----
@@ -15,7 +15,7 @@
15
15
  [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/NiJingzhe/SimpleLLMFunc/graphs/commit-activity)
16
16
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/NiJingzhe/SimpleLLMFunc/pulls)
17
17
 
18
- ### 更新说明
18
+ ### 更新说明 (0.2.8 Latest)
19
19
  ### Look here: [Change Log](https://github.com/NiJingzhe/SimpleLLMFunc/blob/master/CHANGELOG.md)
20
20
 
21
21
  ### 文档(ReadtheDoc)
@@ -21,6 +21,11 @@ from SimpleLLMFunc.logger import (
21
21
  push_debug,
22
22
  )
23
23
  from SimpleLLMFunc.logger.logger import get_current_context_attribute, get_location
24
+ from SimpleLLMFunc.llm_decorator.multimodal_types import (
25
+ Text,
26
+ ImgUrl,
27
+ ImgPath,
28
+ )
24
29
 
25
30
  # 定义一个类型变量,用于函数的返回类型
26
31
  T = TypeVar("T")
@@ -437,7 +442,6 @@ def extract_content_from_stream_response(chunk: Any, func_name: str) -> str:
437
442
  push_error(f"提取流响应内容时出错: {str(e)}")
438
443
  content = ""
439
444
 
440
- push_debug(f"LLM 函数 '{func_name}' 提取的流内容:\n{content}")
441
445
  return content
442
446
 
443
447
 
@@ -615,15 +619,79 @@ def _process_tool_calls(
615
619
  tool_result = tool_func(**arguments)
616
620
 
617
621
  # 创建工具响应消息
618
- tool_result_str = json.dumps(tool_result, ensure_ascii=False, indent=2)
619
- tool_message = {
620
- "role": "tool",
621
- "tool_call_id": tool_call_id,
622
- "content": tool_result_str,
623
- }
622
+ # 如果是多模态消息,构建对应的content
623
+ if isinstance(tool_result, ImgUrl):
624
+ # 将工具返回的图片URL转换为用户消息
625
+ tool_result_packet = {
626
+ "type": "image_url",
627
+ "image_url": {"url": tool_result.url, "detail": tool_result.detail}
628
+ }
629
+
630
+ # 移除最后一条tool call消息,替换为assistant消息
631
+ if current_messages and current_messages[-1].get("role") == "assistant" and current_messages[-1].get("tool_calls"):
632
+ current_messages[-1] = {
633
+ "role": "assistant",
634
+ "content": f"我将会通过工具 '{tool_name}' 获取目标的图像"
635
+ }
636
+
637
+ # 添加包含多模态内容的用户消息
638
+ user_multimodal_message = {
639
+ "role": "user",
640
+ "content": [
641
+ {
642
+ "type": "text",
643
+ "text": f"这是工具 '{tool_name}' 返回的图像:"
644
+ },
645
+ tool_result_packet
646
+ ]
647
+ }
648
+ current_messages.append(user_multimodal_message)
649
+ continue # 跳过默认的tool消息处理
650
+
651
+ elif isinstance(tool_result, ImgPath):
652
+ # 转换本地图片为base64格式
653
+ base64_img = tool_result.to_base64()
654
+ mime_type = tool_result.get_mime_type()
655
+ data_url = f"data:{mime_type};base64,{base64_img}"
656
+
657
+ tool_result_packet = {
658
+ "type": "image_url",
659
+ "image_url": {"url": data_url, "detail": tool_result.detail}
660
+ }
661
+
662
+ # 移除最后一条tool call消息,替换为assistant消息
663
+ if current_messages and current_messages[-1].get("role") == "assistant" and current_messages[-1].get("tool_calls"):
664
+ current_messages[-1] = {
665
+ "role": "assistant",
666
+ "content": f"我将要调用工具 '{tool_name}' 获取图像文件"
667
+ }
668
+
669
+ # 添加包含多模态内容的用户消息
670
+ user_multimodal_message = {
671
+ "role": "user",
672
+ "content": [
673
+ {
674
+ "type": "text",
675
+ "text": f"这是工具 '{tool_name}' 返回的图像文件:"
676
+ },
677
+ tool_result_packet
678
+ ]
679
+ }
680
+ current_messages.append(user_multimodal_message)
681
+ continue # 跳过默认的tool消息处理
682
+
683
+ elif isinstance(tool_result, (Text, str)):
684
+ tool_result_packet = json.dumps(tool_result, ensure_ascii=False, indent=2)
685
+
686
+ tool_message = {
687
+ "role": "tool",
688
+ "tool_call_id": tool_call_id,
689
+ "content": tool_result_packet,
690
+ }
691
+
624
692
  current_messages.append(tool_message)
625
693
 
626
- push_debug(f"工具 '{tool_name}' 执行完成: {tool_result_str}")
694
+ push_debug(f"工具 '{tool_name}' 执行完成: {tool_result_packet}")
627
695
 
628
696
  except Exception as e:
629
697
  # 处理工具执行错误
@@ -838,7 +906,6 @@ def has_multimodal_content(
838
906
  Returns:
839
907
  是否包含多模态内容
840
908
  """
841
- from SimpleLLMFunc.llm_decorator.multimodal_types import Text, ImgUrl, ImgPath
842
909
 
843
910
  exclude_params = exclude_params or []
844
911
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "SimpleLLMFunc"
3
- version = "0.2.7"
3
+ version = "0.2.8"
4
4
  description = "一个轻量但完备的LLM/Agent应用开发框架,提供装饰器实现将函数DocString作为Prompt而无需函数体具体实现但能够享受函数定义和类型标注带来效率提升的开发体验。以最Code的方式,用最少的代码将LLM能力集成到任意Python项目中。"
5
5
  authors = ["Ni Jingzhe <nijingzhe@zju.edu.cn>"]
6
6
  readme = "README.md"
Binary file
@@ -1,5 +0,0 @@
1
- {"timestamp": "2025-06-20T18:41:11.176039", "level": "INFO", "logger": "SimpleLLMFunc", "message": "Logger initialized (dir=./, file=agent.log)", "module": "logger", "function": "setup_logger", "line": 635, "thread": "MainThread", "process": 5149}
2
- {"timestamp": "2025-06-20T18:41:11.176523", "level": "INFO", "logger": "SimpleLLMFunc", "message": "全局日志系统初始化完成, 日志文件路径: .//agent.log, 日志级别: DEBUG", "module": "logger", "function": "push_info", "line": 825, "thread": "MainThread", "process": 5149}
3
- {"timestamp": "2025-06-20T18:41:11.176675", "level": "DEBUG", "logger": "SimpleLLMFunc", "message": "测试DEBUG级别日志", "module": "logger", "function": "push_debug", "line": 796, "thread": "MainThread", "process": 5149}
4
- {"timestamp": "2025-06-20T18:41:11.176773", "level": "INFO", "logger": "SimpleLLMFunc", "message": "测试INFO级别日志(app_log)", "module": "logger", "function": "app_log", "line": 767, "thread": "MainThread", "process": 5149}
5
- {"timestamp": "2025-06-20T18:41:11.176859", "level": "INFO", "logger": "SimpleLLMFunc", "message": "测试INFO级别日志(push_info)", "module": "logger", "function": "push_info", "line": 825, "thread": "MainThread", "process": 5149}
@@ -1,12 +0,0 @@
1
- {
2
- "init": [
3
- {
4
- "timestamp": "2025-06-20T18:41:11.176039+08:00",
5
- "level": "INFO",
6
- "location": "__init__.py:<module>:45",
7
- "message": "Logger initialized (dir=./, file=agent.log)",
8
- "input_tokens": 0,
9
- "output_tokens": 0
10
- }
11
- ]
12
- }
File without changes