llm-dialog-manager 0.4.3__tar.gz → 0.4.4__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (17) hide show
  1. {llm_dialog_manager-0.4.3 → llm_dialog_manager-0.4.4}/PKG-INFO +1 -1
  2. {llm_dialog_manager-0.4.3 → llm_dialog_manager-0.4.4}/llm_dialog_manager/__init__.py +1 -1
  3. {llm_dialog_manager-0.4.3 → llm_dialog_manager-0.4.4}/llm_dialog_manager/agent.py +30 -6
  4. {llm_dialog_manager-0.4.3 → llm_dialog_manager-0.4.4}/llm_dialog_manager.egg-info/PKG-INFO +1 -1
  5. {llm_dialog_manager-0.4.3 → llm_dialog_manager-0.4.4}/pyproject.toml +1 -1
  6. {llm_dialog_manager-0.4.3 → llm_dialog_manager-0.4.4}/LICENSE +0 -0
  7. {llm_dialog_manager-0.4.3 → llm_dialog_manager-0.4.4}/README.md +0 -0
  8. {llm_dialog_manager-0.4.3 → llm_dialog_manager-0.4.4}/llm_dialog_manager/chat_history.py +0 -0
  9. {llm_dialog_manager-0.4.3 → llm_dialog_manager-0.4.4}/llm_dialog_manager/key_manager.py +0 -0
  10. {llm_dialog_manager-0.4.3 → llm_dialog_manager-0.4.4}/llm_dialog_manager.egg-info/SOURCES.txt +0 -0
  11. {llm_dialog_manager-0.4.3 → llm_dialog_manager-0.4.4}/llm_dialog_manager.egg-info/dependency_links.txt +0 -0
  12. {llm_dialog_manager-0.4.3 → llm_dialog_manager-0.4.4}/llm_dialog_manager.egg-info/requires.txt +0 -0
  13. {llm_dialog_manager-0.4.3 → llm_dialog_manager-0.4.4}/llm_dialog_manager.egg-info/top_level.txt +0 -0
  14. {llm_dialog_manager-0.4.3 → llm_dialog_manager-0.4.4}/setup.cfg +0 -0
  15. {llm_dialog_manager-0.4.3 → llm_dialog_manager-0.4.4}/tests/test_agent.py +0 -0
  16. {llm_dialog_manager-0.4.3 → llm_dialog_manager-0.4.4}/tests/test_chat_history.py +0 -0
  17. {llm_dialog_manager-0.4.3 → llm_dialog_manager-0.4.4}/tests/test_key_manager.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: llm_dialog_manager
3
- Version: 0.4.3
3
+ Version: 0.4.4
4
4
  Summary: A Python package for managing LLM chat conversation history
5
5
  Author-email: xihajun <work@2333.fun>
6
6
  License: MIT
@@ -1,4 +1,4 @@
1
1
  from .chat_history import ChatHistory
2
2
  from .agent import Agent
3
3
 
4
- __version__ = "0.4.3"
4
+ __version__ = "0.4.4"
@@ -38,6 +38,10 @@ def load_env_vars():
38
38
 
39
39
  load_env_vars()
40
40
 
41
+ def encode_image(image_path):
42
+ with open(image_path, "rb") as image_file:
43
+ return base64.b64encode(image_file.read()).decode("utf-8")
44
+
41
45
  def format_messages_for_gemini(messages):
42
46
  """
43
47
  将标准化的消息格式转化为 Gemini 格式。
@@ -393,22 +397,42 @@ class Agent:
393
397
  # For Gemini, load as PIL.Image
394
398
  image_pil = Image.open(image_path)
395
399
  image_block = image_pil
396
- else:
400
+ elif "claude" in self.model_name and "openai" not in self.model_name:
397
401
  # For Claude and others, use base64 encoding
398
402
  with open(image_path, "rb") as img_file:
399
403
  image_data = base64.standard_b64encode(img_file.read()).decode("utf-8")
400
404
  image_block = {
401
- "type": "image_base64",
402
- "image_base64": {
405
+ "type": "image",
406
+ "source": {
407
+ "type": "base64",
403
408
  "media_type": media_type,
404
- "data": image_data
405
- }
409
+ "data": image_data,
410
+ },
411
+ }
412
+ else:
413
+ # openai format
414
+ base64_image = encode_image(image_path)
415
+ image_block = {
416
+ "type": "image_url",
417
+ "image_url": {"url": f"data:image/jpeg;base64,{base64_image}"},
406
418
  }
407
419
  else:
408
420
  # If image_url is provided
409
421
  if "gemini" in self.model_name and "openai" not in self.model_name:
410
422
  # For Gemini, you can pass image URLs directly
411
423
  image_block = {"type": "image_url", "image_url": {"url": image_url}}
424
+ elif "claude" in self.model_name and "openai" not in self.model_name:
425
+ import httpx
426
+ media_type = "image/jpeg"
427
+ image_data = base64.standard_b64encode(httpx.get(image_url).content).decode("utf-8")
428
+ image_block = {
429
+ "type": "image",
430
+ "source": {
431
+ "type": "base64",
432
+ "media_type": media_type,
433
+ "data": image_data,
434
+ },
435
+ }
412
436
  else:
413
437
  # For Claude and others, use image URLs
414
438
  image_block = {
@@ -525,7 +549,7 @@ if __name__ == "__main__":
525
549
  agent = Agent("gemini-1.5-flash", "you are Jack101", memory_enabled=True)
526
550
 
527
551
  # Add an image
528
- agent.add_image(image_path="/Users/junfan/Projects/Personal/oneapi/dialog_manager/example.png")
552
+ agent.add_image(image_path="example.png")
529
553
 
530
554
  # Add a user message
531
555
  agent.add_message("user", "Who are you? What's in this image?")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: llm_dialog_manager
3
- Version: 0.4.3
3
+ Version: 0.4.4
4
4
  Summary: A Python package for managing LLM chat conversation history
5
5
  Author-email: xihajun <work@2333.fun>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "llm_dialog_manager"
7
- version = "0.4.3"
7
+ version = "0.4.4"
8
8
  description = "A Python package for managing LLM chat conversation history"
9
9
  readme = "README.md"
10
10
  classifiers = [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Scientific/Engineering :: Artificial Intelligence",]