unique_toolkit 1.40.0__py3-none-any.whl → 1.40.1__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.
@@ -1,4 +1,5 @@
1
1
  import logging
2
+ from enum import StrEnum
2
3
  from string import Template
3
4
 
4
5
  from unique_toolkit.agentic.evaluation.config import EvaluationMetricConfig
@@ -9,6 +10,7 @@ from unique_toolkit.agentic.evaluation.schemas import (
9
10
  EvaluationMetricName,
10
11
  EvaluationMetricResult,
11
12
  )
13
+ from unique_toolkit.content import ContentReference
12
14
  from unique_toolkit.content.schemas import ContentChunk
13
15
  from unique_toolkit.language_model.schemas import (
14
16
  LanguageModelMessages,
@@ -201,13 +203,58 @@ def _get_user_prompt_default(config: EvaluationMetricConfig):
201
203
  )
202
204
 
203
205
 
206
+ class SourceSelectionMode(StrEnum):
207
+ FROM_IDS = "FROM_IDS"
208
+ FROM_ORDER = "FROM_ORDER"
209
+
210
+
204
211
  def context_text_from_stream_response(
205
- response: LanguageModelStreamResponse, selected_chunks: list[ContentChunk]
212
+ response: LanguageModelStreamResponse,
213
+ selected_chunks: list[ContentChunk],
214
+ source_selection_mode: SourceSelectionMode = SourceSelectionMode.FROM_IDS,
206
215
  ):
207
216
  response_references = response.message.references
208
- reference_ids = [reference.source_id for reference in response_references]
209
- filtered_contexts: list[str] = []
210
- for chunk in selected_chunks:
211
- if f"{chunk.id}_{chunk.chunk_id}" in reference_ids:
212
- filtered_contexts.append(chunk.text)
213
- return filtered_contexts
217
+ match source_selection_mode:
218
+ case SourceSelectionMode.FROM_IDS:
219
+ referenced_chunks = _default_source_selection_mode(
220
+ response_references, selected_chunks
221
+ )
222
+ case SourceSelectionMode.FROM_ORDER:
223
+ referenced_chunks = _from_order_source_selection_mode(
224
+ response_references, selected_chunks
225
+ )
226
+ case _:
227
+ raise ValueError(f"Invalid source selection mode: {source_selection_mode}")
228
+
229
+ return [chunk.text for chunk in referenced_chunks]
230
+
231
+
232
+ def _default_source_selection_mode(
233
+ references: list[ContentReference], selected_chunks: list[ContentChunk]
234
+ ):
235
+ reference_ids = {reference.source_id for reference in references}
236
+
237
+ def build_chunk_id(chunk: ContentChunk) -> str:
238
+ return f"{chunk.id}_{chunk.chunk_id}"
239
+
240
+ referenced_chunks = [
241
+ chunk for chunk in selected_chunks if build_chunk_id(chunk) in reference_ids
242
+ ]
243
+
244
+ return referenced_chunks
245
+
246
+
247
+ def _from_order_source_selection_mode(
248
+ references: list[ContentReference], selected_chunks: list[ContentChunk]
249
+ ):
250
+ original_chunks_order: list[int] = []
251
+ for reference in references:
252
+ for original_index in reference.original_index:
253
+ if original_index not in original_chunks_order:
254
+ original_chunks_order.append(original_index)
255
+
256
+ referenced_chunks: list[ContentChunk] = []
257
+ for index in original_chunks_order:
258
+ referenced_chunks.append(selected_chunks[index])
259
+
260
+ return referenced_chunks
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unique_toolkit
3
- Version: 1.40.0
3
+ Version: 1.40.1
4
4
  Summary:
5
5
  License: Proprietary
6
6
  Author: Cedric Klinkert
@@ -123,6 +123,9 @@ All notable changes to this project will be documented in this file.
123
123
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
124
124
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
125
125
 
126
+ ## [1.40.0] - 2025-12-22
127
+ - Add option to use retrieve referenced chunks from their order
128
+
126
129
  ## [1.40.0] - 2025-12-22
127
130
  - Add `hide_in_chat` parameter to `upload_to_chat_from_bytes` and `upload_to_chat_from_bytes_async`
128
131
  - Hide code interpreter files in chat
@@ -54,7 +54,7 @@ unique_toolkit/agentic/evaluation/hallucination/constants.py,sha256=SoGmoYti2J33
54
54
  unique_toolkit/agentic/evaluation/hallucination/hallucination_evaluation.py,sha256=x5ta2Fum4fE5ySgIXPKlnbTtmV140z0IazSATd0-REg,4092
55
55
  unique_toolkit/agentic/evaluation/hallucination/prompts.py,sha256=O3Hi_rOzZlujvnO2wn2jhoPmrYLjzVtRWwxn5Q81m9Y,3405
56
56
  unique_toolkit/agentic/evaluation/hallucination/service.py,sha256=WJF1f45uHnYLx1S4TW31bSFobFpV-YlOS3G_zMhuBVU,2512
57
- unique_toolkit/agentic/evaluation/hallucination/utils.py,sha256=kM5kqUZb5riINr1Oqf3wyrj25o25H2WaJ64haKTJLMo,8213
57
+ unique_toolkit/agentic/evaluation/hallucination/utils.py,sha256=uHKTJw4kJyq0_Gi-EOhbocBAij4_Vzn3dW1wTxAuFg4,9706
58
58
  unique_toolkit/agentic/evaluation/output_parser.py,sha256=0FDo8YY_Dc4qlTNeYyQkznzIFj9aX9wMrLOTbhhTl6g,1418
59
59
  unique_toolkit/agentic/evaluation/schemas.py,sha256=m9JMCUmeqP8KhsJOVEzsz6dRXUe1uKw-bxRDtn5qwvM,3156
60
60
  unique_toolkit/agentic/evaluation/tests/test_context_relevancy_service.py,sha256=4tDxHTApbaTMxN1sNS8WCqj2BweRk6YqZ5_zHP45jto,7977
@@ -212,7 +212,7 @@ unique_toolkit/short_term_memory/service.py,sha256=5PeVBu1ZCAfyDb2HLVvlmqSbyzBBu
212
212
  unique_toolkit/smart_rules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
213
213
  unique_toolkit/smart_rules/compile.py,sha256=Ozhh70qCn2yOzRWr9d8WmJeTo7AQurwd3tStgBMPFLA,1246
214
214
  unique_toolkit/test_utilities/events.py,sha256=_mwV2bs5iLjxS1ynDCjaIq-gjjKhXYCK-iy3dRfvO3g,6410
215
- unique_toolkit-1.40.0.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
216
- unique_toolkit-1.40.0.dist-info/METADATA,sha256=iEwBy-tYmByLek8I9T4Eck-LCO5eDQKtk8fkAgnhS-g,46331
217
- unique_toolkit-1.40.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
218
- unique_toolkit-1.40.0.dist-info/RECORD,,
215
+ unique_toolkit-1.40.1.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
216
+ unique_toolkit-1.40.1.dist-info/METADATA,sha256=yjUi84bUvdUEGqMC3PLKEDzJXZj-ul3AvIdl3-HouSQ,46421
217
+ unique_toolkit-1.40.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
218
+ unique_toolkit-1.40.1.dist-info/RECORD,,