ara-cli 0.1.9.83__py3-none-any.whl → 0.1.9.85__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.
Potentially problematic release.
This version of ara-cli might be problematic. Click here for more details.
- ara_cli/ara_command_action.py +1 -1
- ara_cli/file_loaders/__init__.py +0 -0
- ara_cli/file_loaders/binary_file_loader.py +33 -0
- ara_cli/file_loaders/document_file_loader.py +34 -0
- ara_cli/file_loaders/document_reader.py +245 -0
- ara_cli/file_loaders/file_loader.py +50 -0
- ara_cli/file_loaders/text_file_loader.py +189 -0
- ara_cli/prompt_extractor.py +7 -8
- ara_cli/version.py +1 -1
- {ara_cli-0.1.9.83.dist-info → ara_cli-0.1.9.85.dist-info}/METADATA +1 -1
- {ara_cli-0.1.9.83.dist-info → ara_cli-0.1.9.85.dist-info}/RECORD +14 -8
- {ara_cli-0.1.9.83.dist-info → ara_cli-0.1.9.85.dist-info}/WHEEL +0 -0
- {ara_cli-0.1.9.83.dist-info → ara_cli-0.1.9.85.dist-info}/entry_points.txt +0 -0
- {ara_cli-0.1.9.83.dist-info → ara_cli-0.1.9.85.dist-info}/top_level.txt +0 -0
ara_cli/ara_command_action.py
CHANGED
|
File without changes
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
import os
|
|
3
|
+
from ara_cli.file_loaders.file_loader import FileLoader
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class BinaryFileLoader(FileLoader):
|
|
7
|
+
"""Loads binary files (images)"""
|
|
8
|
+
|
|
9
|
+
def load(
|
|
10
|
+
self,
|
|
11
|
+
file_path: str,
|
|
12
|
+
mime_type: str,
|
|
13
|
+
prefix: str = "",
|
|
14
|
+
suffix: str = "",
|
|
15
|
+
block_delimiter: str = "",
|
|
16
|
+
extract_images: bool = False
|
|
17
|
+
) -> bool:
|
|
18
|
+
"""Load binary file as base64"""
|
|
19
|
+
|
|
20
|
+
with open(file_path, 'rb') as file:
|
|
21
|
+
file_content = file.read()
|
|
22
|
+
|
|
23
|
+
base64_image = base64.b64encode(file_content).decode("utf-8")
|
|
24
|
+
|
|
25
|
+
if block_delimiter:
|
|
26
|
+
file_content = f"{block_delimiter}\n{file_content}\n{block_delimiter}"
|
|
27
|
+
|
|
28
|
+
write_content = f"{prefix}{suffix}\n"
|
|
29
|
+
|
|
30
|
+
with open(self.chat.chat_name, 'a', encoding='utf-8') as chat_file:
|
|
31
|
+
chat_file.write(write_content)
|
|
32
|
+
|
|
33
|
+
return True
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from ara_cli.file_loaders.document_reader import DocumentReaderFactory
|
|
2
|
+
from ara_cli.file_loaders.file_loader import FileLoader
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class DocumentFileLoader(FileLoader):
|
|
6
|
+
"""Loads document files (PDF, DOCX, ODT)"""
|
|
7
|
+
|
|
8
|
+
def load(
|
|
9
|
+
self,
|
|
10
|
+
file_path: str,
|
|
11
|
+
prefix: str = "",
|
|
12
|
+
suffix: str = "",
|
|
13
|
+
block_delimiter: str = "```",
|
|
14
|
+
extract_images: bool = False
|
|
15
|
+
) -> bool:
|
|
16
|
+
"""Load document file with optional image extraction"""
|
|
17
|
+
|
|
18
|
+
reader = DocumentReaderFactory.create_reader(file_path)
|
|
19
|
+
|
|
20
|
+
if not reader:
|
|
21
|
+
print("Unsupported document type.")
|
|
22
|
+
return False
|
|
23
|
+
|
|
24
|
+
text_content = reader.read(extract_images=extract_images)
|
|
25
|
+
|
|
26
|
+
if block_delimiter:
|
|
27
|
+
text_content = f"{block_delimiter}\n{text_content}\n{block_delimiter}"
|
|
28
|
+
|
|
29
|
+
write_content = f"{prefix}{text_content}{suffix}\n"
|
|
30
|
+
|
|
31
|
+
with open(self.chat.chat_name, 'a', encoding='utf-8') as chat_file:
|
|
32
|
+
chat_file.write(write_content)
|
|
33
|
+
|
|
34
|
+
return True
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from abc import ABC, abstractmethod
|
|
3
|
+
from typing import Tuple, Optional
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class DocumentReader(ABC):
|
|
7
|
+
"""Abstract base class for document readers"""
|
|
8
|
+
|
|
9
|
+
def __init__(self, file_path: str):
|
|
10
|
+
self.file_path = file_path
|
|
11
|
+
self.base_dir = os.path.dirname(file_path)
|
|
12
|
+
|
|
13
|
+
@abstractmethod
|
|
14
|
+
def read(self, extract_images: bool = False) -> str:
|
|
15
|
+
"""Read document and optionally extract images"""
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
def create_image_data_dir(self, extension_suffix: str) -> str:
|
|
19
|
+
"""
|
|
20
|
+
Create data directory for images with file extension suffix to avoid conflicts.
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
str: Path to images directory
|
|
24
|
+
"""
|
|
25
|
+
file_name_with_ext = os.path.splitext(os.path.basename(self.file_path))[
|
|
26
|
+
0] + f"_{extension_suffix}"
|
|
27
|
+
data_dir = os.path.join(self.base_dir, f"{file_name_with_ext}.data")
|
|
28
|
+
images_dir = os.path.join(data_dir, "images")
|
|
29
|
+
if not os.path.exists(images_dir):
|
|
30
|
+
os.makedirs(images_dir)
|
|
31
|
+
return images_dir
|
|
32
|
+
|
|
33
|
+
def save_and_describe_image(
|
|
34
|
+
self,
|
|
35
|
+
image_data: bytes,
|
|
36
|
+
image_format: str,
|
|
37
|
+
save_dir: str,
|
|
38
|
+
image_counter: int
|
|
39
|
+
) -> Tuple[str, str]:
|
|
40
|
+
"""
|
|
41
|
+
Save image data and get its description from LLM.
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
tuple: (relative_image_path, description)
|
|
45
|
+
"""
|
|
46
|
+
from ara_cli.prompt_handler import describe_image
|
|
47
|
+
|
|
48
|
+
# Save image
|
|
49
|
+
image_filename = f"{image_counter}.{image_format}"
|
|
50
|
+
image_path = os.path.join(save_dir, image_filename)
|
|
51
|
+
|
|
52
|
+
with open(image_path, "wb") as image_file:
|
|
53
|
+
image_file.write(image_data)
|
|
54
|
+
|
|
55
|
+
# Get image description from LLM
|
|
56
|
+
description = describe_image(image_path)
|
|
57
|
+
|
|
58
|
+
# Get relative path
|
|
59
|
+
relative_image_path = os.path.relpath(image_path, self.base_dir)
|
|
60
|
+
|
|
61
|
+
return relative_image_path, description
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class DocxReader(DocumentReader):
|
|
65
|
+
"""Reader for DOCX files"""
|
|
66
|
+
|
|
67
|
+
def read(self, extract_images: bool = False) -> str:
|
|
68
|
+
import docx
|
|
69
|
+
|
|
70
|
+
doc = docx.Document(self.file_path)
|
|
71
|
+
text_content = '\n'.join(para.text for para in doc.paragraphs)
|
|
72
|
+
|
|
73
|
+
if not extract_images:
|
|
74
|
+
return text_content
|
|
75
|
+
|
|
76
|
+
from PIL import Image
|
|
77
|
+
import io
|
|
78
|
+
|
|
79
|
+
# Create data directory for images
|
|
80
|
+
images_dir = self.create_image_data_dir("docx")
|
|
81
|
+
|
|
82
|
+
# Extract and process images
|
|
83
|
+
image_descriptions = []
|
|
84
|
+
image_counter = 1
|
|
85
|
+
|
|
86
|
+
for rel in doc.part.rels.values():
|
|
87
|
+
if "image" in rel.reltype:
|
|
88
|
+
image_data = rel.target_part.blob
|
|
89
|
+
|
|
90
|
+
# Determine image format
|
|
91
|
+
image = Image.open(io.BytesIO(image_data))
|
|
92
|
+
image_format = image.format.lower()
|
|
93
|
+
|
|
94
|
+
# Save and describe image
|
|
95
|
+
relative_path, description = self.save_and_describe_image(
|
|
96
|
+
image_data, image_format, images_dir, image_counter
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
# Add formatted description to list
|
|
100
|
+
image_description = f"\nImage: {relative_path}\n[{description}]\n"
|
|
101
|
+
image_descriptions.append(image_description)
|
|
102
|
+
|
|
103
|
+
image_counter += 1
|
|
104
|
+
|
|
105
|
+
# Combine text content with image descriptions
|
|
106
|
+
if image_descriptions:
|
|
107
|
+
text_content += "\n\n### Extracted Images\n" + \
|
|
108
|
+
"\n".join(image_descriptions)
|
|
109
|
+
|
|
110
|
+
return text_content
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class PdfReader(DocumentReader):
|
|
114
|
+
"""Reader for PDF files"""
|
|
115
|
+
|
|
116
|
+
def read(self, extract_images: bool = False) -> str:
|
|
117
|
+
import pymupdf4llm
|
|
118
|
+
|
|
119
|
+
if not extract_images:
|
|
120
|
+
return pymupdf4llm.to_markdown(self.file_path, write_images=False)
|
|
121
|
+
|
|
122
|
+
import fitz # PyMuPDF
|
|
123
|
+
|
|
124
|
+
# Create images directory
|
|
125
|
+
images_dir = self.create_image_data_dir("pdf")
|
|
126
|
+
|
|
127
|
+
# Extract text without images first
|
|
128
|
+
text_content = pymupdf4llm.to_markdown(
|
|
129
|
+
self.file_path, write_images=False)
|
|
130
|
+
|
|
131
|
+
# Extract and process images
|
|
132
|
+
doc = fitz.open(self.file_path)
|
|
133
|
+
image_descriptions = []
|
|
134
|
+
image_counter = 1
|
|
135
|
+
|
|
136
|
+
for page_num, page in enumerate(doc):
|
|
137
|
+
image_list = page.get_images()
|
|
138
|
+
|
|
139
|
+
for img_index, img in enumerate(image_list):
|
|
140
|
+
# Extract image
|
|
141
|
+
xref = img[0]
|
|
142
|
+
base_image = doc.extract_image(xref)
|
|
143
|
+
image_bytes = base_image["image"]
|
|
144
|
+
image_ext = base_image["ext"]
|
|
145
|
+
|
|
146
|
+
# Save and describe image
|
|
147
|
+
relative_path, description = self.save_and_describe_image(
|
|
148
|
+
image_bytes, image_ext, images_dir, image_counter
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
# Add formatted description to list
|
|
152
|
+
image_description = f"\nImage: {relative_path}\n[{description}]\n"
|
|
153
|
+
image_descriptions.append(image_description)
|
|
154
|
+
|
|
155
|
+
image_counter += 1
|
|
156
|
+
|
|
157
|
+
doc.close()
|
|
158
|
+
|
|
159
|
+
# Combine text content with image descriptions
|
|
160
|
+
if image_descriptions:
|
|
161
|
+
text_content += "\n\n### Extracted Images\n" + \
|
|
162
|
+
"\n".join(image_descriptions)
|
|
163
|
+
|
|
164
|
+
return text_content
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class OdtReader(DocumentReader):
|
|
168
|
+
"""Reader for ODT files"""
|
|
169
|
+
|
|
170
|
+
def read(self, extract_images: bool = False) -> str:
|
|
171
|
+
import pymupdf4llm
|
|
172
|
+
|
|
173
|
+
if not extract_images:
|
|
174
|
+
return pymupdf4llm.to_markdown(self.file_path, write_images=False)
|
|
175
|
+
|
|
176
|
+
import zipfile
|
|
177
|
+
from PIL import Image
|
|
178
|
+
import io
|
|
179
|
+
|
|
180
|
+
# Create data directory for images
|
|
181
|
+
images_dir = self.create_image_data_dir("odt")
|
|
182
|
+
|
|
183
|
+
# Get text content
|
|
184
|
+
text_content = pymupdf4llm.to_markdown(
|
|
185
|
+
self.file_path, write_images=False)
|
|
186
|
+
|
|
187
|
+
# Extract and process images from ODT
|
|
188
|
+
image_descriptions = []
|
|
189
|
+
image_counter = 1
|
|
190
|
+
|
|
191
|
+
try:
|
|
192
|
+
with zipfile.ZipFile(self.file_path, 'r') as odt_zip:
|
|
193
|
+
# List all files in the Pictures directory
|
|
194
|
+
picture_files = [
|
|
195
|
+
f for f in odt_zip.namelist() if f.startswith('Pictures/')]
|
|
196
|
+
|
|
197
|
+
for picture_file in picture_files:
|
|
198
|
+
# Extract image data
|
|
199
|
+
image_data = odt_zip.read(picture_file)
|
|
200
|
+
|
|
201
|
+
# Determine image format
|
|
202
|
+
image = Image.open(io.BytesIO(image_data))
|
|
203
|
+
image_format = image.format.lower()
|
|
204
|
+
|
|
205
|
+
# Save and describe image
|
|
206
|
+
relative_path, description = self.save_and_describe_image(
|
|
207
|
+
image_data, image_format, images_dir, image_counter
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
# Add formatted description to list
|
|
211
|
+
image_description = f"\nImage: {relative_path}\n[{description}]\n"
|
|
212
|
+
image_descriptions.append(image_description)
|
|
213
|
+
|
|
214
|
+
image_counter += 1
|
|
215
|
+
except Exception as e:
|
|
216
|
+
print(f"Warning: Could not extract images from ODT: {e}")
|
|
217
|
+
|
|
218
|
+
# Combine text content with image descriptions
|
|
219
|
+
if image_descriptions:
|
|
220
|
+
text_content += "\n\n### Extracted Images\n" + \
|
|
221
|
+
"\n".join(image_descriptions)
|
|
222
|
+
|
|
223
|
+
return text_content
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
class DocumentReaderFactory:
|
|
227
|
+
"""Factory for creating appropriate document readers"""
|
|
228
|
+
|
|
229
|
+
@staticmethod
|
|
230
|
+
def create_reader(file_path: str) -> Optional[DocumentReader]:
|
|
231
|
+
"""Create appropriate reader based on file extension"""
|
|
232
|
+
_, ext = os.path.splitext(file_path)
|
|
233
|
+
ext = ext.lower()
|
|
234
|
+
|
|
235
|
+
readers = {
|
|
236
|
+
'.docx': DocxReader,
|
|
237
|
+
'.pdf': PdfReader,
|
|
238
|
+
'.odt': OdtReader
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
reader_class = readers.get(ext)
|
|
242
|
+
if reader_class:
|
|
243
|
+
return reader_class(file_path)
|
|
244
|
+
|
|
245
|
+
return None
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class FileLoader(ABC):
|
|
6
|
+
"""Abstract base class for file loaders"""
|
|
7
|
+
|
|
8
|
+
def __init__(self, chat_instance):
|
|
9
|
+
self.chat = chat_instance
|
|
10
|
+
|
|
11
|
+
@abstractmethod
|
|
12
|
+
def load(self, file_path: str, **kwargs) -> bool:
|
|
13
|
+
"""Load file with specific implementation"""
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
def add_prompt_tag_if_needed(self):
|
|
17
|
+
"""Add prompt tag to chat if needed"""
|
|
18
|
+
self.chat.add_prompt_tag_if_needed(self.chat.chat_name)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class FileLoaderFactory:
|
|
22
|
+
"""Factory for creating appropriate file loaders"""
|
|
23
|
+
BINARY_TYPE_MAPPING = {
|
|
24
|
+
".png": "image/png",
|
|
25
|
+
".jpg": "image/jpeg",
|
|
26
|
+
".jpeg": "image/jpeg",
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
DOCUMENT_TYPE_EXTENSIONS = [".docx", ".doc", ".odt", ".pdf"]
|
|
30
|
+
|
|
31
|
+
@staticmethod
|
|
32
|
+
def create_loader(file_name: str, chat_instance) -> Optional[FileLoader]:
|
|
33
|
+
"""Create appropriate loader based on file type"""
|
|
34
|
+
from ara_cli.file_loaders.binary_file_loader import BinaryFileLoader
|
|
35
|
+
from ara_cli.file_loaders.text_file_loader import TextFileLoader
|
|
36
|
+
from ara_cli.file_loaders.document_file_loader import DocumentFileLoader
|
|
37
|
+
|
|
38
|
+
file_name_lower = file_name.lower()
|
|
39
|
+
|
|
40
|
+
# Check if it's a binary file
|
|
41
|
+
for extension, mime_type in FileLoaderFactory.BINARY_TYPE_MAPPING.items():
|
|
42
|
+
if file_name_lower.endswith(extension):
|
|
43
|
+
return BinaryFileLoader(chat_instance)
|
|
44
|
+
|
|
45
|
+
# Check if it's a document
|
|
46
|
+
if any(file_name_lower.endswith(ext) for ext in FileLoaderFactory.DOCUMENT_TYPE_EXTENSIONS):
|
|
47
|
+
return DocumentFileLoader(chat_instance)
|
|
48
|
+
|
|
49
|
+
# Default to text file loader
|
|
50
|
+
return TextFileLoader(chat_instance)
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import re
|
|
3
|
+
import base64
|
|
4
|
+
import tempfile
|
|
5
|
+
from typing import Optional, Tuple
|
|
6
|
+
import requests
|
|
7
|
+
from ara_cli.prompt_handler import describe_image
|
|
8
|
+
from ara_cli.file_loaders.file_loader import FileLoader
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class TextFileLoader(FileLoader):
|
|
12
|
+
"""Loads text files"""
|
|
13
|
+
|
|
14
|
+
def load(
|
|
15
|
+
self,
|
|
16
|
+
file_path: str,
|
|
17
|
+
prefix: str = "",
|
|
18
|
+
suffix: str = "",
|
|
19
|
+
block_delimiter: str = "",
|
|
20
|
+
extract_images: bool = False
|
|
21
|
+
) -> bool:
|
|
22
|
+
"""Load text file with optional markdown image extraction"""
|
|
23
|
+
|
|
24
|
+
is_md_file = file_path.lower().endswith('.md')
|
|
25
|
+
|
|
26
|
+
if is_md_file and extract_images:
|
|
27
|
+
reader = MarkdownReader(file_path)
|
|
28
|
+
file_content = reader.read(extract_images=True)
|
|
29
|
+
else:
|
|
30
|
+
with open(file_path, 'r', encoding='utf-8', errors='replace') as file:
|
|
31
|
+
file_content = file.read()
|
|
32
|
+
|
|
33
|
+
if block_delimiter:
|
|
34
|
+
file_content = f"{block_delimiter}\n{file_content}\n{block_delimiter}"
|
|
35
|
+
|
|
36
|
+
write_content = f"{prefix}{file_content}{suffix}\n"
|
|
37
|
+
|
|
38
|
+
with open(self.chat.chat_name, 'a', encoding='utf-8') as chat_file:
|
|
39
|
+
chat_file.write(write_content)
|
|
40
|
+
|
|
41
|
+
return True
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class MarkdownReader:
|
|
45
|
+
"""Handles markdown file reading with optional image extraction"""
|
|
46
|
+
|
|
47
|
+
def __init__(self, file_path: str):
|
|
48
|
+
self.file_path = file_path
|
|
49
|
+
self.base_dir = os.path.dirname(file_path)
|
|
50
|
+
self.image_processor = ImageProcessor()
|
|
51
|
+
|
|
52
|
+
def read(self, extract_images: bool = False) -> str:
|
|
53
|
+
"""Read markdown file and optionally extract/describe images"""
|
|
54
|
+
with open(self.file_path, 'r', encoding='utf-8') as file:
|
|
55
|
+
content = file.read()
|
|
56
|
+
|
|
57
|
+
if not extract_images:
|
|
58
|
+
return content
|
|
59
|
+
|
|
60
|
+
return self._process_images(content)
|
|
61
|
+
|
|
62
|
+
def _process_images(self, content: str) -> str:
|
|
63
|
+
"""Process all images in markdown content"""
|
|
64
|
+
# Pattern to match markdown images: 
|
|
65
|
+
image_pattern = re.compile(r'!\[([^\]]*)\]\(([^\)]+)\)')
|
|
66
|
+
base64_pattern = re.compile(r'data:image/([^;]+);base64,([^)]+)')
|
|
67
|
+
|
|
68
|
+
# Process each image reference
|
|
69
|
+
for match in image_pattern.finditer(content):
|
|
70
|
+
image_ref = match.group(2)
|
|
71
|
+
replacement = self._process_single_image(image_ref, base64_pattern)
|
|
72
|
+
|
|
73
|
+
if replacement:
|
|
74
|
+
content = content.replace(match.group(0), replacement, 1)
|
|
75
|
+
|
|
76
|
+
return content
|
|
77
|
+
|
|
78
|
+
def _process_single_image(self, image_ref: str, base64_pattern: re.Pattern) -> Optional[str]:
|
|
79
|
+
"""Process a single image reference"""
|
|
80
|
+
try:
|
|
81
|
+
# Try base64 first
|
|
82
|
+
result = self.image_processor.process_base64_image(
|
|
83
|
+
image_ref, base64_pattern)
|
|
84
|
+
if result:
|
|
85
|
+
return result[0]
|
|
86
|
+
|
|
87
|
+
# Try URL
|
|
88
|
+
result, error = self.image_processor.process_url_image(image_ref)
|
|
89
|
+
if result:
|
|
90
|
+
if error:
|
|
91
|
+
print(f"Warning: {error}")
|
|
92
|
+
return result
|
|
93
|
+
|
|
94
|
+
# Try local file
|
|
95
|
+
result, error = self.image_processor.process_local_image(
|
|
96
|
+
image_ref, self.base_dir)
|
|
97
|
+
if error:
|
|
98
|
+
print(f"Warning: {error}")
|
|
99
|
+
return result
|
|
100
|
+
|
|
101
|
+
except Exception as e:
|
|
102
|
+
print(f"Warning: Could not process image {image_ref}: {e}")
|
|
103
|
+
return None
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class ImageProcessor:
|
|
107
|
+
"""Handles image processing operations"""
|
|
108
|
+
|
|
109
|
+
@staticmethod
|
|
110
|
+
def process_base64_image(
|
|
111
|
+
image_ref: str,
|
|
112
|
+
base64_pattern: re.Pattern
|
|
113
|
+
) -> Optional[Tuple[str, str]]:
|
|
114
|
+
"""Process base64 encoded image and return description"""
|
|
115
|
+
base64_match = base64_pattern.match(image_ref)
|
|
116
|
+
if not base64_match:
|
|
117
|
+
return None
|
|
118
|
+
|
|
119
|
+
image_format = base64_match.group(1)
|
|
120
|
+
base64_data = base64_match.group(2)
|
|
121
|
+
image_data = base64.b64decode(base64_data)
|
|
122
|
+
|
|
123
|
+
# Create a temporary file to send to LLM
|
|
124
|
+
with tempfile.NamedTemporaryFile(suffix=f'.{image_format}', delete=False) as tmp_file:
|
|
125
|
+
tmp_file.write(image_data)
|
|
126
|
+
tmp_file_path = tmp_file.name
|
|
127
|
+
|
|
128
|
+
try:
|
|
129
|
+
description = describe_image(tmp_file_path)
|
|
130
|
+
return f"Image: (base64 embedded {image_format} image)\n[{description}]", None
|
|
131
|
+
finally:
|
|
132
|
+
os.unlink(tmp_file_path)
|
|
133
|
+
|
|
134
|
+
@staticmethod
|
|
135
|
+
def process_url_image(image_ref: str) -> Tuple[str, Optional[str]]:
|
|
136
|
+
"""Process image from URL and return description"""
|
|
137
|
+
if not image_ref.startswith(('http://', 'https://')):
|
|
138
|
+
return "", None
|
|
139
|
+
|
|
140
|
+
try:
|
|
141
|
+
response = requests.get(image_ref, timeout=10)
|
|
142
|
+
response.raise_for_status()
|
|
143
|
+
|
|
144
|
+
# Determine file extension from content-type
|
|
145
|
+
content_type = response.headers.get('content-type', '')
|
|
146
|
+
ext = ImageProcessor._get_extension_from_content_type(
|
|
147
|
+
content_type, image_ref)
|
|
148
|
+
|
|
149
|
+
# Create temporary file
|
|
150
|
+
with tempfile.NamedTemporaryFile(suffix=ext, delete=False) as tmp_file:
|
|
151
|
+
tmp_file.write(response.content)
|
|
152
|
+
tmp_file_path = tmp_file.name
|
|
153
|
+
|
|
154
|
+
try:
|
|
155
|
+
description = describe_image(tmp_file_path)
|
|
156
|
+
return f"Image: {image_ref}\n[{description}]", None
|
|
157
|
+
finally:
|
|
158
|
+
os.unlink(tmp_file_path)
|
|
159
|
+
|
|
160
|
+
except Exception as e:
|
|
161
|
+
error_msg = f"Could not download image: {str(e)}"
|
|
162
|
+
return f"Image: {image_ref}\n[{error_msg}]", error_msg
|
|
163
|
+
|
|
164
|
+
@staticmethod
|
|
165
|
+
def process_local_image(image_ref: str, base_dir: str) -> Tuple[str, Optional[str]]:
|
|
166
|
+
"""Process local image file and return description"""
|
|
167
|
+
if os.path.isabs(image_ref):
|
|
168
|
+
local_image_path = image_ref
|
|
169
|
+
else:
|
|
170
|
+
local_image_path = os.path.join(base_dir, image_ref)
|
|
171
|
+
|
|
172
|
+
if os.path.exists(local_image_path):
|
|
173
|
+
description = describe_image(local_image_path)
|
|
174
|
+
return f"Image: {image_ref}\n[{description}]", None
|
|
175
|
+
else:
|
|
176
|
+
error_msg = f"Image file not found"
|
|
177
|
+
return f"Image: {image_ref}\n[{error_msg}]", f"Local image not found: {local_image_path}"
|
|
178
|
+
|
|
179
|
+
@staticmethod
|
|
180
|
+
def _get_extension_from_content_type(content_type: str, url: str) -> str:
|
|
181
|
+
"""Determine file extension from content type or URL"""
|
|
182
|
+
if 'image/jpeg' in content_type:
|
|
183
|
+
return '.jpg'
|
|
184
|
+
elif 'image/png' in content_type:
|
|
185
|
+
return '.png'
|
|
186
|
+
elif 'image/gif' in content_type:
|
|
187
|
+
return '.gif'
|
|
188
|
+
else:
|
|
189
|
+
return os.path.splitext(url)[1] or '.png'
|
ara_cli/prompt_extractor.py
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
from ara_cli.prompt_handler import send_prompt, get_file_content
|
|
2
|
-
from ara_cli.classifier import Classifier
|
|
3
|
-
from ara_cli.directory_navigator import DirectoryNavigator
|
|
4
|
-
from ara_cli.artefact_models.artefact_mapping import title_prefix_to_artefact_class
|
|
5
1
|
import re
|
|
6
2
|
import json
|
|
7
|
-
import json_repair
|
|
8
3
|
import os
|
|
9
|
-
|
|
4
|
+
import json_repair
|
|
10
5
|
from markdown_it import MarkdownIt
|
|
6
|
+
from ara_cli.prompt_handler import send_prompt, get_file_content
|
|
7
|
+
from ara_cli.classifier import Classifier
|
|
8
|
+
from ara_cli.directory_navigator import DirectoryNavigator
|
|
9
|
+
from ara_cli.artefact_models.artefact_mapping import title_prefix_to_artefact_class
|
|
11
10
|
|
|
12
11
|
|
|
13
12
|
def extract_code_blocks_md(markdown_text):
|
|
@@ -21,7 +20,7 @@ def extract_responses(document_path, relative_to_ara_root=False, skip_queries=Fa
|
|
|
21
20
|
print(f"Debug: Starting extraction from {document_path}")
|
|
22
21
|
block_extraction_counter = 0
|
|
23
22
|
|
|
24
|
-
with open(document_path, 'r', encoding='utf-8') as file:
|
|
23
|
+
with open(document_path, 'r', encoding='utf-8', errors='replace') as file:
|
|
25
24
|
content = file.read()
|
|
26
25
|
|
|
27
26
|
cwd = os.getcwd()
|
|
@@ -114,7 +113,7 @@ def modify_and_save_file(response, file_path):
|
|
|
114
113
|
print("Skipping block.")
|
|
115
114
|
return
|
|
116
115
|
|
|
117
|
-
with open(file_path, 'w', encoding='utf-8') as file:
|
|
116
|
+
with open(file_path, 'w', encoding='utf-8', errors='replace') as file:
|
|
118
117
|
file.write(response_data['content'])
|
|
119
118
|
print(f"File {file_path} updated successfully.")
|
|
120
119
|
except json.JSONDecodeError as ex:
|
ara_cli/version.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
# version.py
|
|
2
|
-
__version__ = "0.1.9.
|
|
2
|
+
__version__ = "0.1.9.85" # fith parameter like .0 for local install test purposes only. official numbers should be 4 digit numbers
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ara_cli
|
|
3
|
-
Version: 0.1.9.
|
|
3
|
+
Version: 0.1.9.85
|
|
4
4
|
Summary: Powerful, open source command-line tool for managing, structuring and automating software development artifacts in line with Business-Driven Development (BDD) and AI-assisted processes
|
|
5
5
|
Description-Content-Type: text/markdown
|
|
6
6
|
Requires-Dist: litellm
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
ara_cli/__init__.py,sha256=0zl7IegxTid26EBGLav_fXZ4CCIV3H5TfAoFQiOHjvg,148
|
|
2
2
|
ara_cli/__main__.py,sha256=J5DCDLRZ6UcpYwM1-NkjaLo4PTetcSj2dB4HrrftkUw,2064
|
|
3
|
-
ara_cli/ara_command_action.py,sha256=
|
|
3
|
+
ara_cli/ara_command_action.py,sha256=_LHE2V5hbJxN7ccYiptuPktRfbTnXmQEt_D_FxDBlBY,22456
|
|
4
4
|
ara_cli/ara_command_parser.py,sha256=I-e9W-QwTIMKMzlHycSlCWCyBFQfiFYvGre1XsDbrFI,20573
|
|
5
5
|
ara_cli/ara_config.py,sha256=SgZfQVpqj5JJN4SB0n2IvAH0sKIdS3k1K1Zht2wDywA,8814
|
|
6
6
|
ara_cli/artefact_autofix.py,sha256=WVTiIR-jo4YKmmz4eS3qTFvl45W1YKwAk1XSuz9QX10,20015
|
|
@@ -24,14 +24,14 @@ ara_cli/filename_validator.py,sha256=Aw9PL8d5-Ymhp3EY6lDrUBk3cudaNqo1Uw5RzPpI1jA
|
|
|
24
24
|
ara_cli/list_filter.py,sha256=qKGwwQsrWe7L5FbdxEbBYD1bbbi8c-RMypjXqXvLbgs,5291
|
|
25
25
|
ara_cli/output_suppressor.py,sha256=nwiHaQLwabOjMoJOeUESBnZszGMxrQZfJ3N2OvahX7Y,389
|
|
26
26
|
ara_cli/prompt_chat.py,sha256=kd_OINDQFit6jN04bb7mzgY259JBbRaTaNp9F-webkc,1346
|
|
27
|
-
ara_cli/prompt_extractor.py,sha256=
|
|
27
|
+
ara_cli/prompt_extractor.py,sha256=6xLGd4ZJHDKkamEUQcdRbKM3ilBtxBjp0X2o8wrvHb0,7732
|
|
28
28
|
ara_cli/prompt_handler.py,sha256=iulI3A4lHXvVITX7hiVN-pR61bzJmIfoYMGK_aO2Pfs,20248
|
|
29
29
|
ara_cli/prompt_rag.py,sha256=ydlhe4CUqz0jdzlY7jBbpKaf_5fjMrAZKnriKea3ZAg,7485
|
|
30
30
|
ara_cli/run_file_lister.py,sha256=XbrrDTJXp1LFGx9Lv91SNsEHZPP-PyEMBF_P4btjbDA,2360
|
|
31
31
|
ara_cli/tag_extractor.py,sha256=TGdaQOVnjy25R0zDsAifB67C5oom0Fwo24s0_fr5A_I,3151
|
|
32
32
|
ara_cli/template_manager.py,sha256=YwrN6AYPpl6ZrW8BVQpVXx8yTRf-oNpJUIKeg4NAggs,6606
|
|
33
33
|
ara_cli/update_config_prompt.py,sha256=Oy9vNTw6UhDohyTEfSKkqE5ifEMPlmWNYkKHgUrK_pY,4607
|
|
34
|
-
ara_cli/version.py,sha256=
|
|
34
|
+
ara_cli/version.py,sha256=HkAW6R4-z4t1cEYyw2ptaPZ3mSDYKamKl0luAnoY9WU,146
|
|
35
35
|
ara_cli/artefact_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
36
36
|
ara_cli/artefact_models/artefact_load.py,sha256=IXzWxP-Q_j_oDGMno0m-OuXCQ7Vd5c_NctshGr4ROBw,621
|
|
37
37
|
ara_cli/artefact_models/artefact_mapping.py,sha256=8aD0spBjkJ8toMAmFawc6UTUxB6-tEEViZXv2I-r88Q,1874
|
|
@@ -53,6 +53,12 @@ ara_cli/commands/command.py,sha256=Y_2dNeuxRjbyI3ScXNv55lptSe8Hs_ya78L0nPYNZHA,1
|
|
|
53
53
|
ara_cli/commands/extract_command.py,sha256=TfKuOnKQzJ8JPpJyKDm7qhm5mvbZnHspCem8g6YgACo,835
|
|
54
54
|
ara_cli/commands/load_command.py,sha256=H3CfeHIL-criDU5oi4BONTSpyzJ4m8DzJ0ZCIiAZFeI,2204
|
|
55
55
|
ara_cli/commands/load_image_command.py,sha256=g9-PXAYdqx5Ed1PdVo-FIb4CyJGEpRFbgQf9Dxg6DmM,886
|
|
56
|
+
ara_cli/file_loaders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
57
|
+
ara_cli/file_loaders/binary_file_loader.py,sha256=1HHH1Nk4lEM83CTnf4z9wYz6rMLgpxydFoRcSgkBHmQ,940
|
|
58
|
+
ara_cli/file_loaders/document_file_loader.py,sha256=VxGFChYyM9K-e6eOCK3yk5jQuEXgz01Mh_NoA6CA_RM,1017
|
|
59
|
+
ara_cli/file_loaders/document_reader.py,sha256=SD9_5-XJ6homKUes6o8GWcG--X63UslfAosPbrJZQvo,7721
|
|
60
|
+
ara_cli/file_loaders/file_loader.py,sha256=bc1BrMG4pEtwsZLm3Ct53YsMPgnbSaEvZEd8isRDYRY,1711
|
|
61
|
+
ara_cli/file_loaders/text_file_loader.py,sha256=x_ZqnOUb2glpdxziceWCBX8oEBk7JZhAluLRRvBjuQs,6626
|
|
56
62
|
ara_cli/templates/agile.artefacts,sha256=nTA8dp98HWKAD-0qhmNpVYIfkVGoJshZqMJGnphiOsE,7932
|
|
57
63
|
ara_cli/templates/template.businessgoal.prompt_log.md,sha256=xF6bkgj_GqAAqHxJWJiQNt11mEuSGemIqoZ2wOo6dI0,214
|
|
58
64
|
ara_cli/templates/template.capability.prompt_log.md,sha256=eO8EzrHgb2vYJ-DP1jGzAfDlMo8nY75hZDfhh0s40uQ,208
|
|
@@ -146,8 +152,8 @@ tests/test_list_filter.py,sha256=fJA3d_SdaOAUkE7jn68MOVS0THXGghy1fye_64Zvo1U,796
|
|
|
146
152
|
tests/test_tag_extractor.py,sha256=nSiAYlTKZ7TLAOtcJpwK5zTWHhFYU0tI5xKnivLc1dU,2712
|
|
147
153
|
tests/test_template_manager.py,sha256=q-LMHRG4rHkD6ON6YW4cpZxUx9hul6Or8wVVRC2kb-8,4099
|
|
148
154
|
tests/test_update_config_prompt.py,sha256=xsqj1WTn4BsG5Q2t-sNPfu7EoMURFcS-hfb5VSXUnJc,6765
|
|
149
|
-
ara_cli-0.1.9.
|
|
150
|
-
ara_cli-0.1.9.
|
|
151
|
-
ara_cli-0.1.9.
|
|
152
|
-
ara_cli-0.1.9.
|
|
153
|
-
ara_cli-0.1.9.
|
|
155
|
+
ara_cli-0.1.9.85.dist-info/METADATA,sha256=pA9IA0ZrgLUTuqgYcLbEHss01CZ3qdqaJ2Oo07IQppw,6739
|
|
156
|
+
ara_cli-0.1.9.85.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
157
|
+
ara_cli-0.1.9.85.dist-info/entry_points.txt,sha256=v4h7MzysTgSIDYfEo3oj4Kz_8lzsRa3hq-KJHEcLVX8,45
|
|
158
|
+
ara_cli-0.1.9.85.dist-info/top_level.txt,sha256=WM4cLHT5DYUaWzLtRj-gu3yVNFpGQ6lLRI3FMmC-38I,14
|
|
159
|
+
ara_cli-0.1.9.85.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|