llm-dialog-manager 0.4.2__py3-none-any.whl → 0.4.4__py3-none-any.whl
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.
- llm_dialog_manager/__init__.py +1 -1
- llm_dialog_manager/agent.py +32 -8
- {llm_dialog_manager-0.4.2.dist-info → llm_dialog_manager-0.4.4.dist-info}/METADATA +1 -1
- llm_dialog_manager-0.4.4.dist-info/RECORD +9 -0
- llm_dialog_manager-0.4.2.dist-info/RECORD +0 -9
- {llm_dialog_manager-0.4.2.dist-info → llm_dialog_manager-0.4.4.dist-info}/LICENSE +0 -0
- {llm_dialog_manager-0.4.2.dist-info → llm_dialog_manager-0.4.4.dist-info}/WHEEL +0 -0
- {llm_dialog_manager-0.4.2.dist-info → llm_dialog_manager-0.4.4.dist-info}/top_level.txt +0 -0
llm_dialog_manager/__init__.py
CHANGED
llm_dialog_manager/agent.py
CHANGED
@@ -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 格式。
|
@@ -389,26 +393,46 @@ class Agent:
|
|
389
393
|
if image_path:
|
390
394
|
if not os.path.exists(image_path):
|
391
395
|
raise FileNotFoundError(f"Image file {image_path} does not exist.")
|
392
|
-
if "gemini" in self.model_name:
|
396
|
+
if "gemini" in self.model_name and "openai" not in self.model_name:
|
393
397
|
# For Gemini, load as PIL.Image
|
394
398
|
image_pil = Image.open(image_path)
|
395
399
|
image_block = image_pil
|
396
|
-
|
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": "
|
402
|
-
"
|
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
|
-
if "gemini" in self.model_name:
|
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="
|
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?")
|
@@ -0,0 +1,9 @@
|
|
1
|
+
llm_dialog_manager/__init__.py,sha256=J7qsuEH4NWFkTQVvCqHgxX1jOYnY79s9BMi02KTo3-A,86
|
2
|
+
llm_dialog_manager/agent.py,sha256=ou9D8NtRt6fDXgrneXP5jZRil7XyKpCTUHCADPJmeeA,25332
|
3
|
+
llm_dialog_manager/chat_history.py,sha256=DKKRnj_M6h-4JncnH6KekMTghX7vMgdN3J9uOwXKzMU,10347
|
4
|
+
llm_dialog_manager/key_manager.py,sha256=shvxmn4zUtQx_p-x1EFyOmnk-WlhigbpKtxTKve-zXk,4421
|
5
|
+
llm_dialog_manager-0.4.4.dist-info/LICENSE,sha256=vWGbYgGuWpWrXL8-xi6pNcX5UzD6pWoIAZmcetyfbus,1064
|
6
|
+
llm_dialog_manager-0.4.4.dist-info/METADATA,sha256=Rjjs7I8JwbQ21QyMxTDrDrwzmAqMcdY30srUOJxYzWs,4194
|
7
|
+
llm_dialog_manager-0.4.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
8
|
+
llm_dialog_manager-0.4.4.dist-info/top_level.txt,sha256=u2EQEXW0NGAt0AAHT7jx1odXZ4rZfjcgbmJhvKFuMkI,19
|
9
|
+
llm_dialog_manager-0.4.4.dist-info/RECORD,,
|
@@ -1,9 +0,0 @@
|
|
1
|
-
llm_dialog_manager/__init__.py,sha256=JfEU5PUkn2YXXKa6yCMjGd6usEpf6Yp9r7FPwhaZzAs,86
|
2
|
-
llm_dialog_manager/agent.py,sha256=sV3RhZFlNCdTuOyCxJ3pRdUv5mwk4xFEfKs68LXAalg,24261
|
3
|
-
llm_dialog_manager/chat_history.py,sha256=DKKRnj_M6h-4JncnH6KekMTghX7vMgdN3J9uOwXKzMU,10347
|
4
|
-
llm_dialog_manager/key_manager.py,sha256=shvxmn4zUtQx_p-x1EFyOmnk-WlhigbpKtxTKve-zXk,4421
|
5
|
-
llm_dialog_manager-0.4.2.dist-info/LICENSE,sha256=vWGbYgGuWpWrXL8-xi6pNcX5UzD6pWoIAZmcetyfbus,1064
|
6
|
-
llm_dialog_manager-0.4.2.dist-info/METADATA,sha256=p40WrWZheemV-4rWErChIXZGFAcdx1bZHcw1DD3lF7o,4194
|
7
|
-
llm_dialog_manager-0.4.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
8
|
-
llm_dialog_manager-0.4.2.dist-info/top_level.txt,sha256=u2EQEXW0NGAt0AAHT7jx1odXZ4rZfjcgbmJhvKFuMkI,19
|
9
|
-
llm_dialog_manager-0.4.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|