attachments 0.2.3__tar.gz → 0.2.6__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 (33) hide show
  1. {attachments-0.2.3/src/attachments.egg-info → attachments-0.2.6}/PKG-INFO +42 -2
  2. {attachments-0.2.3 → attachments-0.2.6}/README.md +40 -1
  3. {attachments-0.2.3 → attachments-0.2.6}/pyproject.toml +2 -1
  4. {attachments-0.2.3 → attachments-0.2.6}/src/attachments/core.py +54 -1
  5. {attachments-0.2.3 → attachments-0.2.6/src/attachments.egg-info}/PKG-INFO +42 -2
  6. {attachments-0.2.3 → attachments-0.2.6}/src/attachments.egg-info/requires.txt +1 -0
  7. {attachments-0.2.3 → attachments-0.2.6}/LICENSE +0 -0
  8. {attachments-0.2.3 → attachments-0.2.6}/setup.cfg +0 -0
  9. {attachments-0.2.3 → attachments-0.2.6}/src/attachments/__init__.py +0 -0
  10. {attachments-0.2.3 → attachments-0.2.6}/src/attachments/audio_processing.py +0 -0
  11. {attachments-0.2.3 → attachments-0.2.6}/src/attachments/config.py +0 -0
  12. {attachments-0.2.3 → attachments-0.2.6}/src/attachments/detectors.py +0 -0
  13. {attachments-0.2.3 → attachments-0.2.6}/src/attachments/exceptions.py +0 -0
  14. {attachments-0.2.3 → attachments-0.2.6}/src/attachments/image_processing.py +0 -0
  15. {attachments-0.2.3 → attachments-0.2.6}/src/attachments/office_contact_sheet.py +0 -0
  16. {attachments-0.2.3 → attachments-0.2.6}/src/attachments/parsers.py +0 -0
  17. {attachments-0.2.3 → attachments-0.2.6}/src/attachments/renderers.py +0 -0
  18. {attachments-0.2.3 → attachments-0.2.6}/src/attachments/utils.py +0 -0
  19. {attachments-0.2.3 → attachments-0.2.6}/src/attachments.egg-info/SOURCES.txt +0 -0
  20. {attachments-0.2.3 → attachments-0.2.6}/src/attachments.egg-info/dependency_links.txt +0 -0
  21. {attachments-0.2.3 → attachments-0.2.6}/src/attachments.egg-info/top_level.txt +0 -0
  22. {attachments-0.2.3 → attachments-0.2.6}/tests/test_audio_processing.py +0 -0
  23. {attachments-0.2.3 → attachments-0.2.6}/tests/test_base.py +0 -0
  24. {attachments-0.2.3 → attachments-0.2.6}/tests/test_core_functionality.py +0 -0
  25. {attachments-0.2.3 → attachments-0.2.6}/tests/test_document_parsing.py +0 -0
  26. {attachments-0.2.3 → attachments-0.2.6}/tests/test_html_parsing.py +0 -0
  27. {attachments-0.2.3 → attachments-0.2.6}/tests/test_image_processing.py +0 -0
  28. {attachments-0.2.3 → attachments-0.2.6}/tests/test_indexing_slicing.py +0 -0
  29. {attachments-0.2.3 → attachments-0.2.6}/tests/test_markdown_rendering.py +0 -0
  30. {attachments-0.2.3 → attachments-0.2.6}/tests/test_office_contact_sheet.py +0 -0
  31. {attachments-0.2.3 → attachments-0.2.6}/tests/test_pdf_parsing.py +0 -0
  32. {attachments-0.2.3 → attachments-0.2.6}/tests/test_pptx_parsing.py +0 -0
  33. {attachments-0.2.3 → attachments-0.2.6}/tests/test_simple.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: attachments
3
- Version: 0.2.3
3
+ Version: 0.2.6
4
4
  Summary: A Python library to handle various file types for LLMs.
5
5
  Author-email: Maxim Rivest <mrive052@gmail.com>
6
6
  License-Expression: MIT
@@ -35,13 +35,16 @@ Requires-Dist: flake8; extra == "dev"
35
35
  Requires-Dist: mypy; extra == "dev"
36
36
  Requires-Dist: black; extra == "dev"
37
37
  Requires-Dist: filelock; extra == "dev"
38
+ Requires-Dist: mystmd; extra == "dev"
38
39
  Dynamic: license-file
39
40
 
40
- # Attachments
41
+ # Attachments: The Python Library for Effortless LLM Context
41
42
  ## Easiest way to give context to LLMs
42
43
 
43
44
  Attachments has the ambition to be the general funnel for any files to be transformed into images+text for large language models context. For this to be true we, has a community, have to stop implementing this funnel (file -> images+text) each on our own. If you have a detector + parser + renderer contibute it! This will help you and us. Don't let your code alone in a dark corner of you computer.
44
45
 
46
+ From a `path` to a `string` and a `base64` image encoded string. That is the goal.
47
+
45
48
  ## Very quickstart
46
49
 
47
50
  ```bash
@@ -121,6 +124,43 @@ message = anthropic.Anthropic().messages.create(
121
124
  print(message.content)
122
125
  ```
123
126
 
127
+ ## How to give a word document (with tables and images) to langchain?
128
+
129
+ I am not a fan of the object that langchain and anthropic make you create, but hey!, I don't make the rules...
130
+
131
+ ```python
132
+ from langchain.chat_models import init_chat_model
133
+ from attachments import Attachments
134
+
135
+ docx_file = Attachments("https://github.com/microsoft/markitdown/raw/refs/heads/main/packages/markitdown/tests/test_files/test.docx")
136
+
137
+ llm = init_chat_model("anthropic:claude-3-5-sonnet-latest")
138
+
139
+ # Creation of a list of object as expected by langchain/anthropic
140
+ content = [{"type": "text", "text": f"Analyze the following documents: {docx_file}"}]
141
+
142
+ for image in docx_file.images
143
+ media_type_i = image.split(";")[0].split(":")[1]
144
+ media_data_i = image.split(",")[1]
145
+ content.append({
146
+ "type": "image",
147
+ "source": {
148
+ "type": "base64",
149
+ "media_type": media_type_i,
150
+ "data": media_data_i
151
+ }
152
+ })
153
+
154
+
155
+ message = {
156
+ "role": "user",
157
+ "content": content,
158
+ }
159
+
160
+ #Finally call the llm
161
+ response = llm.invoke([message])
162
+ print(response.text())
163
+ ```
124
164
 
125
165
  ## Usage
126
166
 
@@ -1,8 +1,10 @@
1
- # Attachments
1
+ # Attachments: The Python Library for Effortless LLM Context
2
2
  ## Easiest way to give context to LLMs
3
3
 
4
4
  Attachments has the ambition to be the general funnel for any files to be transformed into images+text for large language models context. For this to be true we, has a community, have to stop implementing this funnel (file -> images+text) each on our own. If you have a detector + parser + renderer contibute it! This will help you and us. Don't let your code alone in a dark corner of you computer.
5
5
 
6
+ From a `path` to a `string` and a `base64` image encoded string. That is the goal.
7
+
6
8
  ## Very quickstart
7
9
 
8
10
  ```bash
@@ -82,6 +84,43 @@ message = anthropic.Anthropic().messages.create(
82
84
  print(message.content)
83
85
  ```
84
86
 
87
+ ## How to give a word document (with tables and images) to langchain?
88
+
89
+ I am not a fan of the object that langchain and anthropic make you create, but hey!, I don't make the rules...
90
+
91
+ ```python
92
+ from langchain.chat_models import init_chat_model
93
+ from attachments import Attachments
94
+
95
+ docx_file = Attachments("https://github.com/microsoft/markitdown/raw/refs/heads/main/packages/markitdown/tests/test_files/test.docx")
96
+
97
+ llm = init_chat_model("anthropic:claude-3-5-sonnet-latest")
98
+
99
+ # Creation of a list of object as expected by langchain/anthropic
100
+ content = [{"type": "text", "text": f"Analyze the following documents: {docx_file}"}]
101
+
102
+ for image in docx_file.images
103
+ media_type_i = image.split(";")[0].split(":")[1]
104
+ media_data_i = image.split(",")[1]
105
+ content.append({
106
+ "type": "image",
107
+ "source": {
108
+ "type": "base64",
109
+ "media_type": media_type_i,
110
+ "data": media_data_i
111
+ }
112
+ })
113
+
114
+
115
+ message = {
116
+ "role": "user",
117
+ "content": content,
118
+ }
119
+
120
+ #Finally call the llm
121
+ response = llm.invoke([message])
122
+ print(response.text())
123
+ ```
85
124
 
86
125
  ## Usage
87
126
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "attachments"
7
- version = "0.2.3"
7
+ version = "0.2.6"
8
8
  authors = [
9
9
  { name="Maxim Rivest", email="mrive052@gmail.com" },
10
10
  ]
@@ -53,6 +53,7 @@ dev = [
53
53
  "mypy",
54
54
  "black",
55
55
  "filelock",
56
+ "mystmd",
56
57
  ]
57
58
 
58
59
  [tool.setuptools]
@@ -278,7 +278,7 @@ class Attachments:
278
278
  'm4a': 'audio/m4a', # mimetypes might say audio/mp4, which is also fine for .m4a
279
279
  'mp4_audio': 'audio/mp4',
280
280
  'wav': 'audio/wav',
281
- 'flac': 'audio/flac',
281
+ 'flac': 'audio/flac',
282
282
  'ogg_audio': 'audio/ogg',
283
283
  'oga': 'audio/ogg',
284
284
  'webm_audio': 'audio/webm',
@@ -634,6 +634,59 @@ class Attachments:
634
634
  def another_method_or_end_of_class_placeholder(self):
635
635
  pass
636
636
 
637
+ def to_openai_content(self, prompt: str) -> List[Dict[str, Any]]:
638
+ """
639
+ Formats attachments and a prompt for the OpenAI API.
640
+ Currently supports images.
641
+
642
+ Args:
643
+ prompt: The text prompt to include.
644
+
645
+ Returns:
646
+ A list of dictionaries formatted for the OpenAI API,
647
+ combining image data and the text prompt.
648
+ """
649
+ content = [{"type": "input_image", "image_url": image_data_uri} for image_data_uri in self.images]
650
+ content.append({"type": "input_text", "text": prompt + "\n\n" + self.__str__()})
651
+ return content
652
+
653
+ def to_claude_content(self, prompt: str) -> List[Dict[str, Any]]:
654
+ """
655
+ Formats attachments and a prompt for the Anthropic Claude API.
656
+ Currently supports images.
657
+
658
+ Args:
659
+ prompt: The text prompt to include.
660
+
661
+ Returns:
662
+ A list of dictionaries formatted for the Anthropic Claude API,
663
+ combining image data and the text prompt.
664
+ """
665
+ content = []
666
+ for image_data_uri in self.images:
667
+ try:
668
+ # Example data URI: "data:image/jpeg;base64,BASE64_STRING"
669
+ header, base64_data = image_data_uri.split(',', 1)
670
+ media_type = header.split(';')[0].split(':')[1]
671
+
672
+ content.append({
673
+ "type": "image",
674
+ "source": {
675
+ "type": "base64",
676
+ "media_type": media_type,
677
+ "data": base64_data
678
+ }
679
+ })
680
+ except ValueError as e:
681
+ # Handle cases where the data URI might not be as expected, though self.images should provide valid ones.
682
+ if self.verbose:
683
+ print(f"Warning: Could not parse image data URI for Claude content: {image_data_uri}. Error: {e}")
684
+ # Optionally, append an error or skip this image
685
+ continue # Skip malformed URIs for now
686
+
687
+ content.append({"type": "text", "text": prompt})
688
+ return content
689
+
637
690
  # Potentially other methods follow, or end of class / file
638
691
 
639
692
  def _format_operations_for_markdown(self, operations: Dict[str, Any]) -> str:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: attachments
3
- Version: 0.2.3
3
+ Version: 0.2.6
4
4
  Summary: A Python library to handle various file types for LLMs.
5
5
  Author-email: Maxim Rivest <mrive052@gmail.com>
6
6
  License-Expression: MIT
@@ -35,13 +35,16 @@ Requires-Dist: flake8; extra == "dev"
35
35
  Requires-Dist: mypy; extra == "dev"
36
36
  Requires-Dist: black; extra == "dev"
37
37
  Requires-Dist: filelock; extra == "dev"
38
+ Requires-Dist: mystmd; extra == "dev"
38
39
  Dynamic: license-file
39
40
 
40
- # Attachments
41
+ # Attachments: The Python Library for Effortless LLM Context
41
42
  ## Easiest way to give context to LLMs
42
43
 
43
44
  Attachments has the ambition to be the general funnel for any files to be transformed into images+text for large language models context. For this to be true we, has a community, have to stop implementing this funnel (file -> images+text) each on our own. If you have a detector + parser + renderer contibute it! This will help you and us. Don't let your code alone in a dark corner of you computer.
44
45
 
46
+ From a `path` to a `string` and a `base64` image encoded string. That is the goal.
47
+
45
48
  ## Very quickstart
46
49
 
47
50
  ```bash
@@ -121,6 +124,43 @@ message = anthropic.Anthropic().messages.create(
121
124
  print(message.content)
122
125
  ```
123
126
 
127
+ ## How to give a word document (with tables and images) to langchain?
128
+
129
+ I am not a fan of the object that langchain and anthropic make you create, but hey!, I don't make the rules...
130
+
131
+ ```python
132
+ from langchain.chat_models import init_chat_model
133
+ from attachments import Attachments
134
+
135
+ docx_file = Attachments("https://github.com/microsoft/markitdown/raw/refs/heads/main/packages/markitdown/tests/test_files/test.docx")
136
+
137
+ llm = init_chat_model("anthropic:claude-3-5-sonnet-latest")
138
+
139
+ # Creation of a list of object as expected by langchain/anthropic
140
+ content = [{"type": "text", "text": f"Analyze the following documents: {docx_file}"}]
141
+
142
+ for image in docx_file.images
143
+ media_type_i = image.split(";")[0].split(":")[1]
144
+ media_data_i = image.split(",")[1]
145
+ content.append({
146
+ "type": "image",
147
+ "source": {
148
+ "type": "base64",
149
+ "media_type": media_type_i,
150
+ "data": media_data_i
151
+ }
152
+ })
153
+
154
+
155
+ message = {
156
+ "role": "user",
157
+ "content": content,
158
+ }
159
+
160
+ #Finally call the llm
161
+ response = llm.invoke([message])
162
+ print(response.text())
163
+ ```
124
164
 
125
165
  ## Usage
126
166
 
@@ -23,3 +23,4 @@ flake8
23
23
  mypy
24
24
  black
25
25
  filelock
26
+ mystmd
File without changes
File without changes