inferencesh 0.2.13__tar.gz → 0.2.15__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.
Potentially problematic release.
This version of inferencesh might be problematic. Click here for more details.
- {inferencesh-0.2.13/src/inferencesh.egg-info → inferencesh-0.2.15}/PKG-INFO +1 -1
- {inferencesh-0.2.13 → inferencesh-0.2.15}/pyproject.toml +1 -1
- {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh/models/llm.py +32 -35
- {inferencesh-0.2.13 → inferencesh-0.2.15/src/inferencesh.egg-info}/PKG-INFO +1 -1
- {inferencesh-0.2.13 → inferencesh-0.2.15}/LICENSE +0 -0
- {inferencesh-0.2.13 → inferencesh-0.2.15}/README.md +0 -0
- {inferencesh-0.2.13 → inferencesh-0.2.15}/setup.cfg +0 -0
- {inferencesh-0.2.13 → inferencesh-0.2.15}/setup.py +0 -0
- {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh/__init__.py +0 -0
- {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh/models/__init__.py +0 -0
- {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh/models/base.py +0 -0
- {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh/models/file.py +0 -0
- {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh/utils/__init__.py +0 -0
- {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh/utils/download.py +0 -0
- {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh/utils/storage.py +0 -0
- {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh.egg-info/SOURCES.txt +0 -0
- {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh.egg-info/dependency_links.txt +0 -0
- {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh.egg-info/entry_points.txt +0 -0
- {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh.egg-info/requires.txt +0 -0
- {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh.egg-info/top_level.txt +0 -0
- {inferencesh-0.2.13 → inferencesh-0.2.15}/tests/test_sdk.py +0 -0
|
@@ -5,6 +5,7 @@ from queue import Queue
|
|
|
5
5
|
from threading import Thread
|
|
6
6
|
import time
|
|
7
7
|
from contextlib import contextmanager
|
|
8
|
+
import base64
|
|
8
9
|
|
|
9
10
|
from .base import BaseAppInput, BaseAppOutput
|
|
10
11
|
from .file import File
|
|
@@ -136,55 +137,51 @@ def timing_context():
|
|
|
136
137
|
finally:
|
|
137
138
|
pass
|
|
138
139
|
|
|
140
|
+
def image_to_base64_data_uri(file_path):
|
|
141
|
+
with open(file_path, "rb") as img_file:
|
|
142
|
+
base64_data = base64.b64encode(img_file.read()).decode('utf-8')
|
|
143
|
+
return f"data:image/png;base64,{base64_data}"
|
|
139
144
|
|
|
140
145
|
def build_messages(
|
|
141
146
|
input_data: LLMInput,
|
|
142
147
|
transform_user_message: Optional[Callable[[str], str]] = None
|
|
143
148
|
) -> List[Dict[str, Any]]:
|
|
144
149
|
"""Build messages for LLaMA.cpp chat completion.
|
|
145
|
-
|
|
146
|
-
Args:
|
|
147
|
-
input_data: The input data
|
|
148
|
-
transform_user_message: Optional function to transform user message text before building messages
|
|
149
|
-
"""
|
|
150
|
-
messages = [
|
|
151
|
-
{
|
|
152
|
-
"role": "system",
|
|
153
|
-
"content": [{"type": "text", "text": input_data.system_prompt}],
|
|
154
|
-
}
|
|
155
|
-
]
|
|
156
150
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
151
|
+
If any message includes image content, builds OpenAI-style multipart format.
|
|
152
|
+
Otherwise, uses plain string-only format.
|
|
153
|
+
"""
|
|
154
|
+
def render_message(msg: ContextMessage, allow_multipart: bool) -> str | List[dict]:
|
|
155
|
+
parts = []
|
|
156
|
+
text = transform_user_message(msg.text) if transform_user_message and msg.role == ContextMessageRole.USER else msg.text
|
|
163
157
|
if text:
|
|
164
|
-
|
|
165
|
-
if
|
|
158
|
+
parts.append({"type": "text", "text": text})
|
|
159
|
+
if msg.image:
|
|
166
160
|
if msg.image.path:
|
|
167
|
-
|
|
161
|
+
image_data_uri = image_to_base64_data_uri(msg.image.path)
|
|
162
|
+
parts.append({"type": "image_url", "image_url": {"url": image_data_uri}})
|
|
168
163
|
elif msg.image.uri:
|
|
169
|
-
|
|
164
|
+
parts.append({"type": "image_url", "image_url": {"url": msg.image.uri}})
|
|
165
|
+
if allow_multipart:
|
|
166
|
+
return parts
|
|
167
|
+
if len(parts) == 1 and parts[0]["type"] == "text":
|
|
168
|
+
return parts[0]["text"]
|
|
169
|
+
raise ValueError("Image content requires multipart support")
|
|
170
|
+
|
|
171
|
+
multipart = any(m.image for m in input_data.context) or input_data.image is not None
|
|
172
|
+
messages = [{"role": "system", "content": input_data.system_prompt}]
|
|
173
|
+
|
|
174
|
+
for msg in input_data.context:
|
|
170
175
|
messages.append({
|
|
171
176
|
"role": msg.role,
|
|
172
|
-
"content":
|
|
177
|
+
"content": render_message(msg, allow_multipart=multipart)
|
|
173
178
|
})
|
|
174
179
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if text:
|
|
181
|
-
user_content.append({"type": "text", "text": text})
|
|
182
|
-
if hasattr(input_data, 'image') and input_data.image:
|
|
183
|
-
if input_data.image.path:
|
|
184
|
-
user_content.append({"type": "image_url", "image_url": {"url": input_data.image.path}})
|
|
185
|
-
elif input_data.image.uri:
|
|
186
|
-
user_content.append({"type": "image_url", "image_url": {"url": input_data.image.uri}})
|
|
187
|
-
messages.append({"role": "user", "content": user_content})
|
|
180
|
+
user_msg = ContextMessage(role=ContextMessageRole.USER, text=input_data.text, image=input_data.image)
|
|
181
|
+
messages.append({
|
|
182
|
+
"role": "user",
|
|
183
|
+
"content": render_message(user_msg, allow_multipart=multipart)
|
|
184
|
+
})
|
|
188
185
|
|
|
189
186
|
return messages
|
|
190
187
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|