prompt-caller 0.0.3__py3-none-any.whl → 0.0.5__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.
@@ -1,13 +1,18 @@
1
1
  import os
2
2
  import re
3
3
 
4
+ import requests
4
5
  import yaml
5
6
  from dotenv import load_dotenv
6
7
  from jinja2 import Template
7
8
  from langchain_core.messages import HumanMessage, SystemMessage
8
9
  from langchain_openai import ChatOpenAI
10
+ from PIL import Image
9
11
  from pydantic import BaseModel, Field, create_model
10
12
 
13
+ from io import BytesIO
14
+ import base64
15
+
11
16
  load_dotenv()
12
17
 
13
18
 
@@ -32,7 +37,7 @@ class PromptCaller:
32
37
 
33
38
  def _parseJSXBody(self, body):
34
39
  elements = []
35
- tag_pattern = r"<(system|user|assistant)>(.*?)</\1>"
40
+ tag_pattern = r"<(system|user|assistant|image)>(.*?)</\1>"
36
41
 
37
42
  matches = re.findall(tag_pattern, body, re.DOTALL)
38
43
 
@@ -41,6 +46,15 @@ class PromptCaller:
41
46
 
42
47
  return elements
43
48
 
49
+ def getImageBase64(self, url: str) -> str:
50
+ response = requests.get(url)
51
+ response.raise_for_status()
52
+ img = Image.open(BytesIO(response.content))
53
+ buffered = BytesIO()
54
+ img.save(buffered, format="PNG")
55
+ img_base64 = base64.b64encode(buffered.getvalue()).decode("utf-8")
56
+ return f"data:image/png;base64,{img_base64}"
57
+
44
58
  def loadPrompt(self, promptName, context=None):
45
59
  # initialize context
46
60
  if context is None:
@@ -63,6 +77,23 @@ class PromptCaller:
63
77
  if message.get("role") == "user":
64
78
  messages.append(HumanMessage(content=message.get("content")))
65
79
 
80
+ if message.get("role") == "image":
81
+ base64_image = message.get("content")
82
+
83
+ if base64_image.startswith("http"):
84
+ base64_image = self.getImageBase64(base64_image)
85
+
86
+ messages.append(
87
+ HumanMessage(
88
+ content=[
89
+ {
90
+ "type": "image_url",
91
+ "image_url": {"url": base64_image},
92
+ }
93
+ ]
94
+ )
95
+ )
96
+
66
97
  return configuration, messages
67
98
 
68
99
  def createPydanticModel(self, dynamic_dict):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prompt_caller
3
- Version: 0.0.3
3
+ Version: 0.0.5
4
4
  Summary: This package is responsible for calling prompts in a specific format. It uses LangChain and OpenAI API
5
5
  Home-page: https://github.com/ThiNepo/prompt-caller
6
6
  Author: Thiago Nepomuceno
@@ -13,7 +13,9 @@ License-File: LICENSE
13
13
  Requires-Dist: pyyaml>=6.0.2
14
14
  Requires-Dist: python-dotenv>=1.0.1
15
15
  Requires-Dist: Jinja2>=3.1.4
16
- Requires-Dist: langchain-openai>=0.1.23
16
+ Requires-Dist: langchain-openai>=0.3.5
17
+ Requires-Dist: openai>=1.63.0
18
+ Requires-Dist: pillow>=11.0.0
17
19
 
18
20
  # PromptCaller
19
21
 
@@ -0,0 +1,8 @@
1
+ prompt_caller/__init__.py,sha256=4EGdeAJ_Ig7A-b-e17-nYbiXjckT7uL3to5lchMsoW4,41
2
+ prompt_caller/__main__.py,sha256=dJ0dYtVmnhZuoV79R6YiAIta1ZkUKb-TEX4VEuYbgk0,139
3
+ prompt_caller/prompt_caller.py,sha256=k5xiY_COGxvuRVOgaVuBzO9vbrUMFrzjG4EXarMj_jk,3899
4
+ prompt_caller-0.0.5.dist-info/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
5
+ prompt_caller-0.0.5.dist-info/METADATA,sha256=Xk8vrEi0fyyQtcXlPT4QhDtc4TPW6cps0cWHW2tYJI8,3947
6
+ prompt_caller-0.0.5.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
7
+ prompt_caller-0.0.5.dist-info/top_level.txt,sha256=iihiDRq-0VrKB8IKjxf7Lrtv-fLMq4tvgM4fH3x0I94,14
8
+ prompt_caller-0.0.5.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- prompt_caller/__init__.py,sha256=4EGdeAJ_Ig7A-b-e17-nYbiXjckT7uL3to5lchMsoW4,41
2
- prompt_caller/__main__.py,sha256=dJ0dYtVmnhZuoV79R6YiAIta1ZkUKb-TEX4VEuYbgk0,139
3
- prompt_caller/prompt_caller.py,sha256=KRQYxvAOPMFIqhoLgJWQYr1ahGEWefNWtIjw1W_v8BM,2842
4
- prompt_caller-0.0.3.dist-info/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
5
- prompt_caller-0.0.3.dist-info/METADATA,sha256=LDXDLiUlMe1U3LQOhKNgM3xrqiMfSsVQglAEXK0tA4g,3886
6
- prompt_caller-0.0.3.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
7
- prompt_caller-0.0.3.dist-info/top_level.txt,sha256=iihiDRq-0VrKB8IKjxf7Lrtv-fLMq4tvgM4fH3x0I94,14
8
- prompt_caller-0.0.3.dist-info/RECORD,,