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.

Files changed (21) hide show
  1. {inferencesh-0.2.13/src/inferencesh.egg-info → inferencesh-0.2.15}/PKG-INFO +1 -1
  2. {inferencesh-0.2.13 → inferencesh-0.2.15}/pyproject.toml +1 -1
  3. {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh/models/llm.py +32 -35
  4. {inferencesh-0.2.13 → inferencesh-0.2.15/src/inferencesh.egg-info}/PKG-INFO +1 -1
  5. {inferencesh-0.2.13 → inferencesh-0.2.15}/LICENSE +0 -0
  6. {inferencesh-0.2.13 → inferencesh-0.2.15}/README.md +0 -0
  7. {inferencesh-0.2.13 → inferencesh-0.2.15}/setup.cfg +0 -0
  8. {inferencesh-0.2.13 → inferencesh-0.2.15}/setup.py +0 -0
  9. {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh/__init__.py +0 -0
  10. {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh/models/__init__.py +0 -0
  11. {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh/models/base.py +0 -0
  12. {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh/models/file.py +0 -0
  13. {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh/utils/__init__.py +0 -0
  14. {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh/utils/download.py +0 -0
  15. {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh/utils/storage.py +0 -0
  16. {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh.egg-info/SOURCES.txt +0 -0
  17. {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh.egg-info/dependency_links.txt +0 -0
  18. {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh.egg-info/entry_points.txt +0 -0
  19. {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh.egg-info/requires.txt +0 -0
  20. {inferencesh-0.2.13 → inferencesh-0.2.15}/src/inferencesh.egg-info/top_level.txt +0 -0
  21. {inferencesh-0.2.13 → inferencesh-0.2.15}/tests/test_sdk.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: inferencesh
3
- Version: 0.2.13
3
+ Version: 0.2.15
4
4
  Summary: inference.sh Python SDK
5
5
  Author: Inference Shell Inc.
6
6
  Author-email: "Inference Shell Inc." <hello@inference.sh>
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "inferencesh"
7
- version = "0.2.13"
7
+ version = "0.2.15"
8
8
  description = "inference.sh Python SDK"
9
9
  authors = [
10
10
  {name = "Inference Shell Inc.", email = "hello@inference.sh"},
@@ -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
- # Add context messages
158
- for msg in input_data.context:
159
- message_content = []
160
- text = msg.text
161
- if transform_user_message and msg.role == ContextMessageRole.USER:
162
- text = transform_user_message(text)
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
- message_content.append({"type": "text", "text": text})
165
- if hasattr(msg, 'image') and msg.image:
158
+ parts.append({"type": "text", "text": text})
159
+ if msg.image:
166
160
  if msg.image.path:
167
- message_content.append({"type": "image_url", "image_url": {"url": msg.image.path}})
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
- message_content.append({"type": "image_url", "image_url": {"url": msg.image.uri}})
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": message_content
177
+ "content": render_message(msg, allow_multipart=multipart)
173
178
  })
174
179
 
175
- # Add user message
176
- user_content = []
177
- text = input_data.text
178
- if transform_user_message:
179
- text = transform_user_message(text)
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
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: inferencesh
3
- Version: 0.2.13
3
+ Version: 0.2.15
4
4
  Summary: inference.sh Python SDK
5
5
  Author: Inference Shell Inc.
6
6
  Author-email: "Inference Shell Inc." <hello@inference.sh>
File without changes
File without changes
File without changes
File without changes