inferencesh 0.2.29__py3-none-any.whl → 0.2.31__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.
- inferencesh/models/llm.py +27 -9
- {inferencesh-0.2.29.dist-info → inferencesh-0.2.31.dist-info}/METADATA +1 -1
- {inferencesh-0.2.29.dist-info → inferencesh-0.2.31.dist-info}/RECORD +7 -7
- {inferencesh-0.2.29.dist-info → inferencesh-0.2.31.dist-info}/WHEEL +0 -0
- {inferencesh-0.2.29.dist-info → inferencesh-0.2.31.dist-info}/entry_points.txt +0 -0
- {inferencesh-0.2.29.dist-info → inferencesh-0.2.31.dist-info}/licenses/LICENSE +0 -0
- {inferencesh-0.2.29.dist-info → inferencesh-0.2.31.dist-info}/top_level.txt +0 -0
inferencesh/models/llm.py
CHANGED
|
@@ -136,7 +136,7 @@ class ToolCallsMixin(BaseModel):
|
|
|
136
136
|
)
|
|
137
137
|
|
|
138
138
|
# Example of how to use:
|
|
139
|
-
class LLMOutput(
|
|
139
|
+
class LLMOutput(LLMUsageMixin, BaseLLMOutput):
|
|
140
140
|
"""Default LLM output model with token usage tracking."""
|
|
141
141
|
pass
|
|
142
142
|
|
|
@@ -232,18 +232,36 @@ def build_messages(
|
|
|
232
232
|
multipart = any(m.image for m in input_data.context) or input_data.image is not None
|
|
233
233
|
messages = [{"role": "system", "content": input_data.system_prompt}] if input_data.system_prompt is not None and input_data.system_prompt != "" else []
|
|
234
234
|
|
|
235
|
+
def merge_messages(messages: List[ContextMessage]) -> ContextMessage:
|
|
236
|
+
text = "\n\n".join(msg.text for msg in messages if msg.text)
|
|
237
|
+
images = [msg.image for msg in messages if msg.image]
|
|
238
|
+
image = images[0] if images else None # TODO: handle multiple images
|
|
239
|
+
return ContextMessage(role=messages[0].role, text=text, image=image)
|
|
240
|
+
|
|
241
|
+
user_msg = ContextMessage(role=ContextMessageRole.USER, text=input_data.text, image=input_data.image)
|
|
242
|
+
|
|
243
|
+
input_data.context.append(user_msg)
|
|
244
|
+
|
|
245
|
+
current_role = None
|
|
246
|
+
current_messages = []
|
|
247
|
+
|
|
235
248
|
for msg in input_data.context:
|
|
249
|
+
if msg.role == current_role or current_role is None:
|
|
250
|
+
current_messages.append(msg)
|
|
251
|
+
current_role = msg.role
|
|
252
|
+
else:
|
|
253
|
+
messages.append({
|
|
254
|
+
"role": current_role,
|
|
255
|
+
"content": render_message(merge_messages(current_messages), allow_multipart=multipart)
|
|
256
|
+
})
|
|
257
|
+
current_messages = [msg]
|
|
258
|
+
current_role = msg.role
|
|
259
|
+
if len(current_messages) > 0:
|
|
236
260
|
messages.append({
|
|
237
|
-
"role":
|
|
238
|
-
"content": render_message(
|
|
261
|
+
"role": current_role,
|
|
262
|
+
"content": render_message(merge_messages(current_messages), allow_multipart=multipart)
|
|
239
263
|
})
|
|
240
264
|
|
|
241
|
-
user_msg = ContextMessage(role=ContextMessageRole.USER, text=input_data.text, image=input_data.image)
|
|
242
|
-
messages.append({
|
|
243
|
-
"role": "user",
|
|
244
|
-
"content": render_message(user_msg, allow_multipart=multipart)
|
|
245
|
-
})
|
|
246
|
-
|
|
247
265
|
return messages
|
|
248
266
|
|
|
249
267
|
|
|
@@ -2,13 +2,13 @@ inferencesh/__init__.py,sha256=WdADtOhfa3HDOunoE9HLFCTFlXRykYstBIH1FpyWvj8,613
|
|
|
2
2
|
inferencesh/models/__init__.py,sha256=FDwcdtT6c4hbRitymjmN-hZMlQa8RbKSftkZZyjtUXA,536
|
|
3
3
|
inferencesh/models/base.py,sha256=4gZQRi8J7y9U6PrGD9pRIehd1MJVJAqGakPQDs2AKFM,3251
|
|
4
4
|
inferencesh/models/file.py,sha256=5xnpypcRahM1YcEjj64rv9g2gTimxrZb41YT4r440hU,7393
|
|
5
|
-
inferencesh/models/llm.py,sha256=
|
|
5
|
+
inferencesh/models/llm.py,sha256=Yj7BGtAlBJBgvEawZQeGb4AB2WvHWY5DG8wEMIXiPoo,27047
|
|
6
6
|
inferencesh/utils/__init__.py,sha256=-xiD6uo2XzcrPAWFb_fUbaimmnW4KFKc-8IvBzaxNd4,148
|
|
7
7
|
inferencesh/utils/download.py,sha256=7n5twvoNYDcFnKJyefImaj2YfzRI7vddQw4usZbj38c,1521
|
|
8
8
|
inferencesh/utils/storage.py,sha256=E4J8emd4eFKdmdDgAqzz3TpaaDd3n0l8gYlMHuY8yIU,519
|
|
9
|
-
inferencesh-0.2.
|
|
10
|
-
inferencesh-0.2.
|
|
11
|
-
inferencesh-0.2.
|
|
12
|
-
inferencesh-0.2.
|
|
13
|
-
inferencesh-0.2.
|
|
14
|
-
inferencesh-0.2.
|
|
9
|
+
inferencesh-0.2.31.dist-info/licenses/LICENSE,sha256=OsgqEWIh2el_QMj0y8O1A5Q5Dl-dxqqYbFE6fszuR4s,1086
|
|
10
|
+
inferencesh-0.2.31.dist-info/METADATA,sha256=cXGDMenDbFRfRfCugNmRlTzoFBw8kC-UuVEKFLMWqZI,2757
|
|
11
|
+
inferencesh-0.2.31.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
12
|
+
inferencesh-0.2.31.dist-info/entry_points.txt,sha256=6IC-fyozAqW3ljsMLGCXxJ0_ui2Jb-2fLHtoH1RTnEE,45
|
|
13
|
+
inferencesh-0.2.31.dist-info/top_level.txt,sha256=TSMHg3T1ThMl1HGAWmzBClwOYH1ump5neof9BfHIwaA,12
|
|
14
|
+
inferencesh-0.2.31.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|