langchain-b12 0.1.1__py3-none-any.whl → 0.1.2__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.
@@ -24,22 +24,37 @@ def multi_content_to_part(
24
24
  Args:
25
25
  contents: A sequence of dictionaries representing content. Examples:
26
26
  [
27
- {
27
+ { # Text content
28
28
  "type": "text",
29
29
  "text": "This is a text message"
30
30
  },
31
- {
31
+ { # Image content from base64 encoded string with OpenAI format
32
32
  "type": "image_url",
33
33
  "image_url": {
34
34
  "url": f"data:{mime_type};base64,{encoded_artifact}"
35
35
  },
36
36
  },
37
- {
37
+ { # Image content fro base64 encoded string with LangChain format
38
+ "type": "image",
39
+ "source_type": "base64",
40
+ "data": "<base64 string>",
41
+ "mime_type": "image/jpeg",
42
+ },
43
+ { # Image content from URL
44
+ "type": "image",
45
+ "source_type": "url",
46
+ "url": "https://...",
47
+ },
48
+ { # File content from base64 encoded string
49
+ "type": "file",
50
+ "source_type": "base64",
51
+ "mime_type": "application/pdf",
52
+ "data": "<base64 data string>",
53
+ },
54
+ { # File content from URL
38
55
  "type": "file",
39
- "file": {
40
- "uri": f"gs://{bucket_name}/{file_name}",
41
- "mime_type": mime_type,
42
- }
56
+ "source_type": "url",
57
+ "url": "https://...",
43
58
  }
44
59
  ]
45
60
  """
@@ -60,15 +75,51 @@ def multi_content_to_part(
60
75
  mime_type = header.split(":", 1)[1].split(";", 1)[0]
61
76
  data = base64.b64decode(encoded_data)
62
77
  parts.append(types.Part.from_bytes(data=data, mime_type=mime_type))
78
+ elif content["type"] == "image":
79
+ if "data" in content:
80
+ assert isinstance(content["data"], str), "Expected str data"
81
+ assert "mime_type" in content, "Expected 'mime_type' in content"
82
+ assert isinstance(content["mime_type"], str), "Expected str mime_type"
83
+ data = base64.b64decode(content["data"])
84
+ parts.append(
85
+ types.Part.from_bytes(data=data, mime_type=content["mime_type"])
86
+ )
87
+ elif "url" in content:
88
+ assert isinstance(content["url"], str), "Expected str url"
89
+ mime_type = content.get("mime_type", None)
90
+ assert mime_type is None or isinstance(
91
+ mime_type, str
92
+ ), "Expected str mime_type"
93
+ parts.append(
94
+ types.Part.from_uri(file_uri=content["url"], mime_type=mime_type)
95
+ )
96
+ else:
97
+ raise ValueError(
98
+ "Expected either 'data' or 'url' in content for image type"
99
+ )
63
100
  elif content["type"] == "file":
64
- assert "file" in content, "Expected 'file' in content"
65
- file = content["file"]
66
- assert isinstance(file, dict), "Expected dict file"
67
- assert "uri" in file, "Expected 'uri' in content['file']"
68
- assert "mime_type" in file, "Expected 'mime_type' in content['file']"
69
- parts.append(
70
- types.Part.from_uri(file_uri=file["uri"], mime_type=file["mime_type"])
71
- )
101
+ if "data" in content:
102
+ assert isinstance(content["data"], str), "Expected str data"
103
+ assert "mime_type" in content, "Expected 'mime_type' in content"
104
+ assert isinstance(content["mime_type"], str), "Expected str mime_type"
105
+ data = base64.b64decode(content["data"])
106
+ parts.append(
107
+ types.Part.from_bytes(data=data, mime_type=content["mime_type"])
108
+ )
109
+ elif "url" in content:
110
+ assert isinstance(content["url"], str), "Expected str url"
111
+ assert content["url"], "File URI is required"
112
+ mime_type = content.get("mime_type", None)
113
+ assert mime_type is None or isinstance(
114
+ mime_type, str
115
+ ), "Expected str mime_type"
116
+ parts.append(
117
+ types.Part.from_uri(file_uri=content["url"], mime_type=mime_type)
118
+ )
119
+ else:
120
+ raise ValueError(
121
+ "Expected either 'data' or 'url' in content for file type"
122
+ )
72
123
  else:
73
124
  raise ValueError(f"Unknown content type: {content['type']}")
74
125
  return parts
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langchain-b12
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: A reusable collection of tools and implementations for Langchain
5
5
  Author-email: Vincent Min <vincent.min@b12-consulting.com>
6
6
  Requires-Python: >=3.11
@@ -2,7 +2,7 @@ langchain_b12/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  langchain_b12/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  langchain_b12/genai/embeddings.py,sha256=od2bVIgt7v9aNAHG0PVypVF1H_XgHto2nTd8vwfvyN8,3355
4
4
  langchain_b12/genai/genai.py,sha256=gzkgtvs3wNjcslS_KFZYCajUZIsJkVN2Tq2Q1RMIPyc,15910
5
- langchain_b12/genai/genai_utils.py,sha256=2ojnSumovXyx3CxM7JwzyOkEdD7mQxfLnk50-usPbw8,8221
6
- langchain_b12-0.1.1.dist-info/METADATA,sha256=PEQWNct2qhdYUEsgubI95ekd8X1HBKp_WXq8JGS8zbU,1204
7
- langchain_b12-0.1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
- langchain_b12-0.1.1.dist-info/RECORD,,
5
+ langchain_b12/genai/genai_utils.py,sha256=La3FOtRGmzI5IDql3ojaYzz-lJqSgHOn0Wp3KwZ3P4I,10735
6
+ langchain_b12-0.1.2.dist-info/METADATA,sha256=8Uzn2ChQ8scEHLRiMykPTdP58wZEgiAaRXS8f2DjTe4,1204
7
+ langchain_b12-0.1.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
+ langchain_b12-0.1.2.dist-info/RECORD,,