haystack-ai 3.4.1rc1__tar.gz → 3.5.0__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.
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/PKG-INFO +5 -3
- haystack_ai-3.5.0/VERSION.txt +1 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/agents/agent.py +6 -1
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/agents/utils.py +6 -2
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/caching/cache_checker.py +2 -4
- haystack_ai-3.5.0/haystack/components/classifiers/__init__.py +17 -0
- haystack_ai-3.5.0/haystack/components/classifiers/openai_decisions_document_classifier.py +361 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/docx.py +54 -7
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/image/document_to_image.py +10 -3
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/image/file_to_image.py +9 -6
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/json.py +9 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/markdown.py +16 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/msg.py +24 -12
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/pptx.py +56 -14
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/xlsx.py +65 -7
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/embedders/azure_document_embedder.py +6 -1
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/embedders/openai_document_embedder.py +5 -1
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/evaluators/document_map.py +12 -2
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/evaluators/document_mrr.py +16 -2
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/evaluators/document_ndcg.py +7 -5
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/evaluators/document_recall.py +3 -1
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/evaluators/llm_evaluator.py +7 -5
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/evaluators/sas_evaluator.py +3 -3
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/extractors/image/llm_document_content_extractor.py +4 -1
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/extractors/llm_metadata_extractor.py +4 -1
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/fetchers/link_content.py +3 -3
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/generators/chat/azure.py +2 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/generators/chat/llm.py +11 -4
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/generators/chat/mock.py +2 -2
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/generators/chat/openai.py +95 -20
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/generators/chat/openai_responses.py +208 -103
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/generators/utils.py +4 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/joiners/branch.py +5 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/joiners/document_joiner.py +43 -6
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/joiners/list_joiner.py +4 -1
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/preprocessors/csv_document_cleaner.py +3 -5
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/preprocessors/csv_document_splitter.py +4 -2
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/preprocessors/document_cleaner.py +11 -13
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/preprocessors/document_splitter.py +1 -1
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/preprocessors/hierarchical_document_splitter.py +34 -6
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/preprocessors/markdown_header_splitter.py +26 -18
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/preprocessors/python_code_splitter.py +30 -13
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/preprocessors/recursive_splitter.py +19 -7
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/rankers/__init__.py +2 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/rankers/llm_ranker.py +6 -2
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/rankers/lost_in_the_middle.py +12 -7
- haystack_ai-3.5.0/haystack/components/rankers/max_sim.py +151 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/rankers/meta_field.py +2 -2
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/retrievers/auto_merging_retriever.py +37 -23
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/retrievers/filter_retriever.py +4 -3
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/retrievers/multi_query_embedding_retriever.py +7 -3
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/retrievers/multi_query_text_retriever.py +7 -3
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/retrievers/multi_retriever.py +11 -2
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/retrievers/sentence_window_retriever.py +3 -4
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/retrievers/text_embedding_retriever.py +3 -2
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/routers/__init__.py +4 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/routers/file_type_router.py +1 -1
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/routers/metadata_router.py +2 -2
- haystack_ai-3.5.0/haystack/components/routers/openai_decisions_image_router.py +248 -0
- haystack_ai-3.5.0/haystack/components/routers/openai_decisions_text_router.py +227 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/writers/document_writer.py +4 -6
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/core/pipeline/base.py +47 -1
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/core/pipeline/pipeline.py +2 -1
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/core/pipeline/utils.py +9 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/core/type_utils.py +7 -1
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/dataclasses/byte_stream.py +6 -6
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/dataclasses/chat_message.py +378 -407
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/dataclasses/document.py +32 -1
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/dataclasses/file_content.py +3 -3
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/dataclasses/image_content.py +9 -3
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/dataclasses/streaming_chunk.py +4 -3
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/document_stores/in_memory/document_store.py +20 -17
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/evaluation/eval_run_result.py +112 -14
- haystack_ai-3.5.0/haystack/hooks/budget/__init__.py +16 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/budget/hooks.py +93 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/compaction/sliding_window.py +67 -18
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/compaction/utils.py +16 -10
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/human_in_the_loop/strategies.py +9 -4
- {haystack_ai-3.4.1rc1/haystack/hooks/budget → haystack_ai-3.5.0/haystack/hooks/structured_output}/__init__.py +2 -2
- haystack_ai-3.5.0/haystack/hooks/structured_output/hooks.py +258 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/tool_result_offloading/stores.py +2 -1
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/utils.py +9 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/token_counters/tiktoken_counter.py +4 -1
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/tools/component_tool.py +40 -14
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/tools/from_function.py +29 -3
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/tools/parameters_schema_utils.py +4 -1
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/tools/searchable_toolset.py +19 -4
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/tools/tool.py +20 -25
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/async_utils.py +24 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/misc.py +16 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/pyproject.toml +7 -3
- haystack_ai-3.4.1rc1/VERSION.txt +0 -1
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/.gitignore +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/LICENSE +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/README.md +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/agents/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/agents/state/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/agents/state/state.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/agents/state/state_utils.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/agents/tool_calling.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/builders/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/builders/answer_builder.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/builders/chat_prompt_builder.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/builders/prompt_builder.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/caching/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/csv.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/file_to_file_content.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/html.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/image/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/image/file_to_document.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/image/image_utils.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/image/pdf_to_image.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/multi_file_converter.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/output_adapter.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/pdfminer.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/pypdf.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/txt.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/utils.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/embedders/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/embedders/azure_text_embedder.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/embedders/mock_document_embedder.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/embedders/mock_text_embedder.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/embedders/mock_utils.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/embedders/openai_text_embedder.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/embedders/types/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/embedders/types/protocol.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/evaluators/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/evaluators/answer_exact_match.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/evaluators/context_relevance.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/evaluators/faithfulness.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/extractors/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/extractors/image/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/extractors/regex_text_extractor.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/fetchers/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/generators/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/generators/chat/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/generators/chat/azure_responses.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/generators/chat/fallback.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/generators/chat/types/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/generators/chat/types/protocol.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/generators/openai_image_generator.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/joiners/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/joiners/answer_joiner.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/joiners/string_joiner.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/preprocessors/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/preprocessors/_page_numbers.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/preprocessors/document_preprocessor.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/preprocessors/embedding_based_document_splitter.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/preprocessors/sentence_tokenizer.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/preprocessors/text_cleaner.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/query/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/query/query_expander.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/rankers/meta_field_grouping_ranker.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/retrievers/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/retrievers/in_memory/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/retrievers/in_memory/bm25_retriever.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/retrievers/in_memory/embedding_retriever.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/retrievers/types/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/retrievers/types/protocol.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/routers/conditional_router.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/routers/document_length_router.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/routers/document_type_router.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/routers/llm_messages_router.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/samplers/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/samplers/top_p.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/validators/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/validators/json_schema.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/writers/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/core/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/core/component/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/core/component/component.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/core/component/sockets.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/core/component/types.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/core/errors.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/core/pipeline/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/core/pipeline/breakpoint.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/core/pipeline/component_checks.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/core/pipeline/descriptions.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/core/pipeline/draw.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/core/serialization.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/core/serialization_security.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/core/super_component/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/core/super_component/super_component.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/core/super_component/utils.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/data/abbreviations/de.txt +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/data/abbreviations/en.txt +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/dataclasses/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/dataclasses/answer.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/dataclasses/breakpoints.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/dataclasses/skill_info.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/dataclasses/sparse_embedding.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/document_stores/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/document_stores/errors/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/document_stores/errors/errors.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/document_stores/in_memory/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/document_stores/types/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/document_stores/types/filter_policy.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/document_stores/types/policy.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/document_stores/types/protocol.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/errors.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/evaluation/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/compaction/AGENTS.md +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/compaction/CLAUDE.md +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/compaction/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/compaction/hooks.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/compaction/summarization.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/compaction/tool_result_offloading.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/compaction/tool_result_pruning.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/compaction/types/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/compaction/types/protocol.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/from_function.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/human_in_the_loop/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/human_in_the_loop/dataclasses.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/human_in_the_loop/hooks.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/human_in_the_loop/policies.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/human_in_the_loop/types/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/human_in_the_loop/types/protocol.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/human_in_the_loop/user_interfaces.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/invocation.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/protocol.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/tool_result_offloading/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/tool_result_offloading/hooks.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/tool_result_offloading/policies.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/tool_result_offloading/types/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/tool_result_offloading/types/protocol.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/hooks/tool_result_offloading/utils.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/lazy_imports.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/logging.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/marshal/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/marshal/protocol.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/marshal/yaml.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/py.typed +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/skill_stores/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/skill_stores/file_system/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/skill_stores/file_system/skill_store.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/skill_stores/types/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/skill_stores/types/protocol.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/telemetry/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/telemetry/_environment.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/telemetry/_telemetry.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/callable_serialization/random_callable.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/document_store.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/document_store_async.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/factory.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/sample_components/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/sample_components/accumulate.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/sample_components/add_value.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/sample_components/concatenate.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/sample_components/double.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/sample_components/fstring.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/sample_components/future_annotations.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/sample_components/greet.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/sample_components/hello.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/sample_components/joiner.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/sample_components/parity.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/sample_components/remainder.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/sample_components/repeat.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/sample_components/subtract.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/sample_components/sum.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/sample_components/text_splitter.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/sample_components/threshold.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/telemetry.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/testing/test_utils.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/token_counters/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/token_counters/approximate_counter.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/token_counters/openai_counter.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/token_counters/types/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/token_counters/types/protocol.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/token_counters/utils.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/tools/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/tools/agent_tool.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/tools/errors.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/tools/pipeline_tool.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/tools/serde_utils.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/tools/skills/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/tools/skills/skill_toolset.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/tools/tool_types.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/tools/toolset.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/tools/utils.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/tracing/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/tracing/logging_tracer.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/tracing/tracer.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/tracing/utils.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/__init__.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/auth.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/azure.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/base_serialization.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/callable_serialization.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/dataclasses.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/deserialization.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/device.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/experimental.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/filters.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/hf.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/http_client.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/jinja2_chat_extension.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/jinja2_extensions.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/jinja2_sandbox.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/jupyter.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/requests_utils.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/type_serialization.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/utils/url_validation.py +0 -0
- {haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/version.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: haystack-ai
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.5.0
|
|
4
4
|
Summary: LLM framework to build customizable, production-ready LLM applications. Connect components (models, vector DBs, file converters) to pipelines or agents that can interact with your data.
|
|
5
5
|
Project-URL: CI: GitHub, https://github.com/deepset-ai/haystack/actions
|
|
6
6
|
Project-URL: Docs: RTD, https://haystack.deepset.ai/overview/intro
|
|
@@ -26,6 +26,7 @@ Classifier: Programming Language :: Python :: 3.15
|
|
|
26
26
|
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
27
27
|
Requires-Python: >=3.11
|
|
28
28
|
Requires-Dist: anyio>=4.14.2
|
|
29
|
+
Requires-Dist: certifi>=2026.10.19
|
|
29
30
|
Requires-Dist: docstring-parser
|
|
30
31
|
Requires-Dist: filetype
|
|
31
32
|
Requires-Dist: httpx
|
|
@@ -36,9 +37,10 @@ Requires-Dist: markupsafe
|
|
|
36
37
|
Requires-Dist: more-itertools
|
|
37
38
|
Requires-Dist: networkx
|
|
38
39
|
Requires-Dist: numpy
|
|
39
|
-
Requires-Dist: openai>=
|
|
40
|
+
Requires-Dist: openai>=3.26.0
|
|
40
41
|
Requires-Dist: posthog!=3.12.0
|
|
41
|
-
Requires-Dist: pydantic
|
|
42
|
+
Requires-Dist: pydantic>=2.12.0
|
|
43
|
+
Requires-Dist: pydantic>=2.14.0; python_version >= '3.15'
|
|
42
44
|
Requires-Dist: python-dateutil
|
|
43
45
|
Requires-Dist: pyyaml
|
|
44
46
|
Requires-Dist: tenacity!=8.4.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.5.0
|
|
@@ -101,12 +101,14 @@ _RUN_METADATA_STATE_KEYS: dict[str, dict[str, Any]] = {
|
|
|
101
101
|
# - `context_tokens`: approximate current context-window size, refreshed after each LLM call, for hooks to read
|
|
102
102
|
# (e.g. a `before_llm` hook that triggers compaction once the context grows too large). Kept internal rather than
|
|
103
103
|
# exposed as an output because it is a best-effort snapshot; see `_record_context_tokens`.
|
|
104
|
+
# - `max_agent_steps`: the Agent's step limit, for hooks to read alongside `step_count`.
|
|
104
105
|
_INTERNAL_STATE_KEYS: dict[str, dict[str, Any]] = {
|
|
105
106
|
"continue_run": {"type": bool, "handler": replace_values},
|
|
106
107
|
"stop_run": {"type": str, "handler": replace_values},
|
|
107
108
|
"tools": {"type": list, "handler": replace_values},
|
|
108
109
|
"hook_context": {"type": dict[str, Any], "handler": replace_values},
|
|
109
110
|
"context_tokens": {"type": int, "handler": replace_values},
|
|
111
|
+
"max_agent_steps": {"type": int, "handler": replace_values},
|
|
110
112
|
}
|
|
111
113
|
|
|
112
114
|
|
|
@@ -403,7 +405,9 @@ class Agent:
|
|
|
403
405
|
@hook
|
|
404
406
|
def require_save(state: State) -> None:
|
|
405
407
|
if state.data.get("exit_reason") == "text":
|
|
406
|
-
|
|
408
|
+
# Marked as a system reminder so context compaction doesn't take it for the user's task
|
|
409
|
+
nudge = ChatMessage.from_user("Call `save_result` before finishing.", meta={"system_reminder": True})
|
|
410
|
+
state.set("messages", [nudge])
|
|
407
411
|
state.set("continue_run", True) # keep the Agent running instead of stopping
|
|
408
412
|
|
|
409
413
|
|
|
@@ -816,6 +820,7 @@ class Agent:
|
|
|
816
820
|
state = State(schema=self.resolved_state_schema, data=state_kwargs)
|
|
817
821
|
state.set("messages", messages)
|
|
818
822
|
state.set("step_count", 0)
|
|
823
|
+
state.set("max_agent_steps", self.max_agent_steps)
|
|
819
824
|
state.set("token_usage", {})
|
|
820
825
|
state.set("context_tokens", 0)
|
|
821
826
|
state.set("tool_call_counts", {tool.name: 0 for tool in flat_tools})
|
|
@@ -27,12 +27,16 @@ def _accumulate_usage(current: Any, new: Any) -> Any:
|
|
|
27
27
|
Recursively sum numeric leaf values across two usage-like dicts.
|
|
28
28
|
|
|
29
29
|
Used to aggregate `ChatMessage.meta["usage"]` payloads across LLM calls in a run. Nested dicts (e.g. OpenAI's
|
|
30
|
-
`completion_tokens_details`) are merged recursively; numeric leaves are summed;
|
|
31
|
-
value.
|
|
30
|
+
`completion_tokens_details`) are merged recursively; numeric leaves are summed; a `None` on either side counts as
|
|
31
|
+
not reported and keeps the other value; other types fall back to the new value.
|
|
32
32
|
|
|
33
33
|
:param current: The current accumulated usage data.
|
|
34
34
|
:param new: The new usage data to merge in.
|
|
35
35
|
"""
|
|
36
|
+
if new is None:
|
|
37
|
+
return current
|
|
38
|
+
if current is None:
|
|
39
|
+
return deepcopy(new)
|
|
36
40
|
if isinstance(current, dict) and isinstance(new, dict):
|
|
37
41
|
result = dict(current)
|
|
38
42
|
for k, v in new.items():
|
|
@@ -6,6 +6,7 @@ from typing import Any
|
|
|
6
6
|
|
|
7
7
|
from haystack import Document, component, default_from_dict, default_to_dict
|
|
8
8
|
from haystack.document_stores.types import DocumentStore
|
|
9
|
+
from haystack.utils.async_utils import _call_with_async_fallback
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
@component
|
|
@@ -110,12 +111,9 @@ class CacheChecker:
|
|
|
110
111
|
found_documents = []
|
|
111
112
|
misses = []
|
|
112
113
|
|
|
113
|
-
if not hasattr(self.document_store, "filter_documents_async"):
|
|
114
|
-
raise TypeError(f"Document store {type(self.document_store).__name__} does not provide async support.")
|
|
115
|
-
|
|
116
114
|
for item in items:
|
|
117
115
|
filters = {"field": self.cache_field, "operator": "==", "value": item}
|
|
118
|
-
found = await self.document_store
|
|
116
|
+
found = await _call_with_async_fallback(self.document_store, "filter_documents", filters=filters)
|
|
119
117
|
if found:
|
|
120
118
|
found_documents.extend(found)
|
|
121
119
|
else:
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
7
|
+
|
|
8
|
+
from lazy_imports import LazyImporter
|
|
9
|
+
|
|
10
|
+
_import_structure = {"openai_decisions_document_classifier": ["OpenAIDecisionsDocumentClassifier"]}
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from .openai_decisions_document_classifier import (
|
|
14
|
+
OpenAIDecisionsDocumentClassifier as OpenAIDecisionsDocumentClassifier,
|
|
15
|
+
)
|
|
16
|
+
else:
|
|
17
|
+
sys.modules[__name__] = LazyImporter(name=__name__, module_file=__file__, import_structure=_import_structure)
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import os
|
|
7
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
8
|
+
from dataclasses import replace
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from openai import APIError, AsyncOpenAI, OpenAI
|
|
12
|
+
from openai.types import Decision
|
|
13
|
+
from openai.types.decision_create_params import Question
|
|
14
|
+
|
|
15
|
+
from haystack import Document, component, logging
|
|
16
|
+
from haystack.utils import Secret
|
|
17
|
+
|
|
18
|
+
logger = logging.getLogger(__name__)
|
|
19
|
+
|
|
20
|
+
_QUESTION_TYPES = ("choice", "score", "predicate")
|
|
21
|
+
_ERROR_FIELD = "classification_error"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@component
|
|
25
|
+
class OpenAIDecisionsDocumentClassifier:
|
|
26
|
+
"""
|
|
27
|
+
Answers typed questions about each document with an OpenAI Decisions model and stores the answers in its metadata.
|
|
28
|
+
|
|
29
|
+
Each question has one of three types:
|
|
30
|
+
- `choice`: picks one value from `choices`, a list of objects with a `value` and an optional `description`.
|
|
31
|
+
- `score`: rates the text on the ordered `levels`, a list of objects with a `label` and an optional `description`.
|
|
32
|
+
- `predicate`: returns the probability that the yes/no question in `instructions` is true.
|
|
33
|
+
|
|
34
|
+
Answers are stored under `meta[metadata_field]`, keyed by question name. Questions are dicts in the OpenAI format.
|
|
35
|
+
See the [OpenAI documentation](https://developers.openai.com/api/docs/guides/decisions) for the full question and
|
|
36
|
+
answer format. A refusal is stored with `type="refusal"`, preserving the answers to the other questions.
|
|
37
|
+
|
|
38
|
+
Documents without text to classify are returned in `failed_documents` with the reason in
|
|
39
|
+
`meta["classification_error"]`. So are documents whose request failed, unless `raise_on_failure` is `True`.
|
|
40
|
+
|
|
41
|
+
### Usage example
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from haystack import Document
|
|
45
|
+
from haystack.components.classifiers import OpenAIDecisionsDocumentClassifier
|
|
46
|
+
|
|
47
|
+
# Set OPENAI_API_KEY in the environment.
|
|
48
|
+
classifier = OpenAIDecisionsDocumentClassifier(
|
|
49
|
+
questions=[
|
|
50
|
+
{
|
|
51
|
+
"name": "department",
|
|
52
|
+
"type": "choice",
|
|
53
|
+
"instructions": "Which department should handle this ticket?",
|
|
54
|
+
"choices": [{"value": "billing"}, {"value": "technical"}, {"value": "sales"}],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": "urgency",
|
|
58
|
+
"type": "score",
|
|
59
|
+
"instructions": "How urgent is this ticket?",
|
|
60
|
+
"levels": [{"label": "can wait"}, {"label": "this week"}, {"label": "today"}],
|
|
61
|
+
},
|
|
62
|
+
{"name": "refund", "type": "predicate", "instructions": "Is the customer asking for a refund?"},
|
|
63
|
+
]
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
result = classifier.run(documents=[Document(content="I was charged twice, please refund me today.")])
|
|
67
|
+
print(result["documents"][0].meta["openai_decisions"])
|
|
68
|
+
# Example response (values may vary):
|
|
69
|
+
# >> {
|
|
70
|
+
# "department": {"type": "choice", "choice": "billing", "confidence": 0.95,
|
|
71
|
+
# "probabilities": [{"value": "billing", "probability": 0.97},
|
|
72
|
+
# {"value": "technical", "probability": 0.02},
|
|
73
|
+
# {"value": "sales", "probability": 0.01}]},
|
|
74
|
+
# "urgency": {"type": "score", "score": 1.95, "confidence": 0.94,
|
|
75
|
+
# "probabilities": [{"label": "can wait", "value": 0, "probability": 0.01},
|
|
76
|
+
# {"label": "this week", "value": 1, "probability": 0.03},
|
|
77
|
+
# {"label": "today", "value": 2, "probability": 0.96}]},
|
|
78
|
+
# "refund": {"type": "predicate", "probability": 0.95},
|
|
79
|
+
# }
|
|
80
|
+
print(result["failed_documents"])
|
|
81
|
+
# >> []
|
|
82
|
+
```
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
def __init__(
|
|
86
|
+
self,
|
|
87
|
+
questions: list[Question],
|
|
88
|
+
*,
|
|
89
|
+
model: str = "gpt-6-luna",
|
|
90
|
+
api_key: Secret = Secret.from_env_var("OPENAI_API_KEY"),
|
|
91
|
+
api_base_url: str | None = None,
|
|
92
|
+
classification_field: str | None = None,
|
|
93
|
+
metadata_field: str = "openai_decisions",
|
|
94
|
+
timeout: float | None = None,
|
|
95
|
+
max_retries: int | None = None,
|
|
96
|
+
max_workers: int = 3,
|
|
97
|
+
raise_on_failure: bool = False,
|
|
98
|
+
) -> None:
|
|
99
|
+
"""
|
|
100
|
+
Creates an OpenAIDecisionsDocumentClassifier.
|
|
101
|
+
|
|
102
|
+
:param questions:
|
|
103
|
+
Questions to answer for every document. Each item is a dict in the OpenAI format with a `type` (`choice`,
|
|
104
|
+
`score` or `predicate`), `instructions`, and for `choice` and `score` questions, `choices` or `levels`,
|
|
105
|
+
respectively. Each question must have a non-empty, unique string `name`, used as its answer's metadata key.
|
|
106
|
+
:param model:
|
|
107
|
+
The name of the Decisions model to use.
|
|
108
|
+
:param api_key:
|
|
109
|
+
The OpenAI API key. You can set it with an environment variable `OPENAI_API_KEY`, or pass with this
|
|
110
|
+
parameter during initialization.
|
|
111
|
+
:param api_base_url:
|
|
112
|
+
Overrides the default base URL for all HTTP requests.
|
|
113
|
+
:param classification_field:
|
|
114
|
+
Name of the document's metadata field to classify. If `None`, `Document.content` is classified.
|
|
115
|
+
:param metadata_field:
|
|
116
|
+
Name of the metadata field the answers are written to.
|
|
117
|
+
:param timeout:
|
|
118
|
+
Timeout for OpenAI client calls. If not set, it defaults to either the
|
|
119
|
+
`OPENAI_TIMEOUT` environment variable, or 30 seconds.
|
|
120
|
+
:param max_retries:
|
|
121
|
+
Maximum number of retries to contact OpenAI after an internal error.
|
|
122
|
+
If not set, it defaults to either the `OPENAI_MAX_RETRIES` environment variable, or set to 5.
|
|
123
|
+
:param max_workers:
|
|
124
|
+
Maximum number of worker threads in `run` and of concurrent requests in `run_async`. Must be at least 1.
|
|
125
|
+
:param raise_on_failure:
|
|
126
|
+
If `True`, the first failed request raises its error. If `False`, documents whose request failed are
|
|
127
|
+
returned in `failed_documents`.
|
|
128
|
+
:raises ValueError:
|
|
129
|
+
If `questions` is empty, a question has a missing, empty, non-string or duplicate `name`, an unknown
|
|
130
|
+
`type`, a `choice` or `score` question has no `choices` or `levels`, respectively, or `max_workers` is
|
|
131
|
+
smaller than 1.
|
|
132
|
+
"""
|
|
133
|
+
if not questions:
|
|
134
|
+
raise ValueError("`questions` must contain at least one question.")
|
|
135
|
+
names: set[str] = set()
|
|
136
|
+
for index, question in enumerate(questions):
|
|
137
|
+
name = question.get("name")
|
|
138
|
+
if not isinstance(name, str) or not name:
|
|
139
|
+
msg = f"Question at index {index} must have a non-empty string `name`."
|
|
140
|
+
raise ValueError(msg)
|
|
141
|
+
if name in names:
|
|
142
|
+
msg = f"Question name '{name}' is duplicated; names must be unique."
|
|
143
|
+
raise ValueError(msg)
|
|
144
|
+
names.add(name)
|
|
145
|
+
if question.get("type") not in _QUESTION_TYPES:
|
|
146
|
+
msg = f"Question '{name}' has type {question.get('type')!r}; use one of {_QUESTION_TYPES}."
|
|
147
|
+
raise ValueError(msg)
|
|
148
|
+
for question_type, field in (("choice", "choices"), ("score", "levels")):
|
|
149
|
+
if question["type"] == question_type and not question.get(field):
|
|
150
|
+
msg = f"Question '{name}' of type '{question_type}' needs `{field}`."
|
|
151
|
+
raise ValueError(msg)
|
|
152
|
+
if max_workers < 1:
|
|
153
|
+
msg = f"`max_workers` must be at least 1, got {max_workers}."
|
|
154
|
+
raise ValueError(msg)
|
|
155
|
+
|
|
156
|
+
self.questions = questions
|
|
157
|
+
self.model = model
|
|
158
|
+
self.api_key = api_key
|
|
159
|
+
self.api_base_url = api_base_url
|
|
160
|
+
self.classification_field = classification_field
|
|
161
|
+
self.metadata_field = metadata_field
|
|
162
|
+
self.timeout = timeout
|
|
163
|
+
self.max_retries = max_retries
|
|
164
|
+
self.max_workers = max_workers
|
|
165
|
+
self.raise_on_failure = raise_on_failure
|
|
166
|
+
self._client: OpenAI | None = None
|
|
167
|
+
self._async_client: AsyncOpenAI | None = None
|
|
168
|
+
|
|
169
|
+
def _client_kwargs(self) -> dict[str, Any]:
|
|
170
|
+
timeout = self.timeout if self.timeout is not None else float(os.environ.get("OPENAI_TIMEOUT", "30.0"))
|
|
171
|
+
max_retries = (
|
|
172
|
+
self.max_retries if self.max_retries is not None else int(os.environ.get("OPENAI_MAX_RETRIES", "5"))
|
|
173
|
+
)
|
|
174
|
+
return {
|
|
175
|
+
"api_key": self.api_key.resolve_value(),
|
|
176
|
+
"base_url": self.api_base_url,
|
|
177
|
+
"timeout": timeout,
|
|
178
|
+
"max_retries": max_retries,
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
def warm_up(self) -> None:
|
|
182
|
+
"""
|
|
183
|
+
Creates the synchronous OpenAI client.
|
|
184
|
+
"""
|
|
185
|
+
if self._client is None:
|
|
186
|
+
self._client = OpenAI(**self._client_kwargs())
|
|
187
|
+
|
|
188
|
+
async def warm_up_async(self) -> None:
|
|
189
|
+
"""
|
|
190
|
+
Creates the asynchronous OpenAI client.
|
|
191
|
+
"""
|
|
192
|
+
if self._async_client is None:
|
|
193
|
+
self._async_client = AsyncOpenAI(**self._client_kwargs())
|
|
194
|
+
|
|
195
|
+
def close(self) -> None:
|
|
196
|
+
"""
|
|
197
|
+
Releases the synchronous OpenAI client.
|
|
198
|
+
"""
|
|
199
|
+
if self._client is not None:
|
|
200
|
+
self._client.close()
|
|
201
|
+
self._client = None
|
|
202
|
+
|
|
203
|
+
async def close_async(self) -> None:
|
|
204
|
+
"""
|
|
205
|
+
Releases the asynchronous OpenAI client.
|
|
206
|
+
"""
|
|
207
|
+
if self._async_client is not None:
|
|
208
|
+
await self._async_client.close()
|
|
209
|
+
self._async_client = None
|
|
210
|
+
|
|
211
|
+
def _text_to_classify(self, document: Document) -> str | None:
|
|
212
|
+
"""
|
|
213
|
+
Returns `content`, or `meta[classification_field]` if set; `None` if missing, empty, or not a string.
|
|
214
|
+
"""
|
|
215
|
+
text = document.content if self.classification_field is None else document.meta.get(self.classification_field)
|
|
216
|
+
return text if isinstance(text, str) and text else None
|
|
217
|
+
|
|
218
|
+
def _succeed(self, document: Document, response: Decision) -> tuple[Document, bool]:
|
|
219
|
+
"""
|
|
220
|
+
Adds the answers from an OpenAI response to a copy of the document.
|
|
221
|
+
|
|
222
|
+
:param document:
|
|
223
|
+
The classified document.
|
|
224
|
+
:param response:
|
|
225
|
+
The OpenAI response for the document.
|
|
226
|
+
:returns:
|
|
227
|
+
A copy of the document with the answers under `meta[metadata_field]` and no `classification_error`, and
|
|
228
|
+
`True` to mark it as classified.
|
|
229
|
+
"""
|
|
230
|
+
answers = {answer.name: answer.model_dump(mode="json", exclude={"name"}) for answer in response.answers}
|
|
231
|
+
# Drop the error left by an earlier failed run
|
|
232
|
+
meta = {key: value for key, value in document.meta.items() if key != _ERROR_FIELD}
|
|
233
|
+
return replace(document, meta={**meta, self.metadata_field: answers}), True
|
|
234
|
+
|
|
235
|
+
def _classify(self, client: OpenAI, document: Document) -> tuple[Document, bool]:
|
|
236
|
+
"""
|
|
237
|
+
Sends one document to the OpenAI API and adds the answers to a copy of it.
|
|
238
|
+
|
|
239
|
+
:param client:
|
|
240
|
+
The synchronous OpenAI client.
|
|
241
|
+
:param document:
|
|
242
|
+
The document to classify.
|
|
243
|
+
:returns:
|
|
244
|
+
A copy of the document with the answers under `meta[metadata_field]` and `True`, or a copy with the reason
|
|
245
|
+
under `meta["classification_error"]` and `False` if the document has no text or its request failed.
|
|
246
|
+
:raises APIError:
|
|
247
|
+
If the request fails and `raise_on_failure` is `True`.
|
|
248
|
+
"""
|
|
249
|
+
text = self._text_to_classify(document)
|
|
250
|
+
if text is None:
|
|
251
|
+
return replace(document, meta={**document.meta, _ERROR_FIELD: "Document has no text to classify."}), False
|
|
252
|
+
try:
|
|
253
|
+
response = client.decisions.create(model=self.model, input=text, questions=self.questions)
|
|
254
|
+
except APIError as error:
|
|
255
|
+
if self.raise_on_failure:
|
|
256
|
+
raise
|
|
257
|
+
logger.warning("Classifying document {document_id} failed: {error}", document_id=document.id, error=error)
|
|
258
|
+
return replace(document, meta={**document.meta, _ERROR_FIELD: str(error)}), False
|
|
259
|
+
return self._succeed(document=document, response=response)
|
|
260
|
+
|
|
261
|
+
async def _classify_async(
|
|
262
|
+
self, client: AsyncOpenAI, document: Document, semaphore: asyncio.Semaphore
|
|
263
|
+
) -> tuple[Document, bool]:
|
|
264
|
+
"""
|
|
265
|
+
Asynchronously sends one document to the OpenAI API and adds the answers to a copy of it.
|
|
266
|
+
|
|
267
|
+
:param client:
|
|
268
|
+
The asynchronous OpenAI client.
|
|
269
|
+
:param document:
|
|
270
|
+
The document to classify.
|
|
271
|
+
:param semaphore:
|
|
272
|
+
Limits how many requests run at once.
|
|
273
|
+
:returns:
|
|
274
|
+
A copy of the document with the answers under `meta[metadata_field]` and `True`, or a copy with the reason
|
|
275
|
+
under `meta["classification_error"]` and `False` if the document has no text or its request failed.
|
|
276
|
+
:raises APIError:
|
|
277
|
+
If the request fails and `raise_on_failure` is `True`.
|
|
278
|
+
"""
|
|
279
|
+
text = self._text_to_classify(document)
|
|
280
|
+
if text is None:
|
|
281
|
+
return replace(document, meta={**document.meta, _ERROR_FIELD: "Document has no text to classify."}), False
|
|
282
|
+
try:
|
|
283
|
+
async with semaphore:
|
|
284
|
+
response = await client.decisions.create(model=self.model, input=text, questions=self.questions)
|
|
285
|
+
except APIError as error:
|
|
286
|
+
if self.raise_on_failure:
|
|
287
|
+
raise
|
|
288
|
+
logger.warning("Classifying document {document_id} failed: {error}", document_id=document.id, error=error)
|
|
289
|
+
return replace(document, meta={**document.meta, _ERROR_FIELD: str(error)}), False
|
|
290
|
+
return self._succeed(document=document, response=response)
|
|
291
|
+
|
|
292
|
+
@component.output_types(documents=list[Document], failed_documents=list[Document])
|
|
293
|
+
def run(self, documents: list[Document]) -> dict[str, list[Document]]:
|
|
294
|
+
"""
|
|
295
|
+
Answers the questions for each document and adds the answers to its metadata.
|
|
296
|
+
|
|
297
|
+
Each document is sent as its own request, with up to `max_workers` requests running at once.
|
|
298
|
+
|
|
299
|
+
:param documents:
|
|
300
|
+
Documents to classify.
|
|
301
|
+
:returns:
|
|
302
|
+
A dictionary with the following keys:
|
|
303
|
+
- `documents`: The classified documents. Each has a `metadata_field` entry mapping each question name
|
|
304
|
+
to its answer.
|
|
305
|
+
- `failed_documents`: The documents that have no text to classify or whose request failed, with the
|
|
306
|
+
reason in `meta["classification_error"]`.
|
|
307
|
+
:raises APIError:
|
|
308
|
+
If a request fails and `raise_on_failure` is `True`.
|
|
309
|
+
"""
|
|
310
|
+
self.warm_up()
|
|
311
|
+
assert self._client is not None # noqa: S101 # mypy: the client is created by warm_up above
|
|
312
|
+
|
|
313
|
+
client = self._client
|
|
314
|
+
with ThreadPoolExecutor(max_workers=self.max_workers) as executor:
|
|
315
|
+
results = list(executor.map(lambda document: self._classify(client=client, document=document), documents))
|
|
316
|
+
return {
|
|
317
|
+
"documents": [document for document, succeeded in results if succeeded],
|
|
318
|
+
"failed_documents": [document for document, succeeded in results if not succeeded],
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
@component.output_types(documents=list[Document], failed_documents=list[Document])
|
|
322
|
+
async def run_async(self, documents: list[Document]) -> dict[str, list[Document]]:
|
|
323
|
+
"""
|
|
324
|
+
Asynchronously answers the questions for each document and adds the answers to its metadata.
|
|
325
|
+
|
|
326
|
+
This is the asynchronous version of the `run` method with the same parameters and return values. Up to
|
|
327
|
+
`max_workers` requests run concurrently.
|
|
328
|
+
|
|
329
|
+
:param documents:
|
|
330
|
+
Documents to classify.
|
|
331
|
+
:returns:
|
|
332
|
+
A dictionary with the following keys:
|
|
333
|
+
- `documents`: The classified documents. Each has a `metadata_field` entry mapping each question name
|
|
334
|
+
to its answer.
|
|
335
|
+
- `failed_documents`: The documents that have no text to classify or whose request failed, with the
|
|
336
|
+
reason in `meta["classification_error"]`.
|
|
337
|
+
:raises APIError:
|
|
338
|
+
If a request fails and `raise_on_failure` is `True`.
|
|
339
|
+
"""
|
|
340
|
+
await self.warm_up_async()
|
|
341
|
+
assert self._async_client is not None # noqa: S101 # mypy: the client is created by warm_up_async above
|
|
342
|
+
|
|
343
|
+
# Bound concurrency to max_workers, mirroring the ThreadPoolExecutor in the sync `run`
|
|
344
|
+
semaphore = asyncio.Semaphore(self.max_workers)
|
|
345
|
+
tasks = [
|
|
346
|
+
asyncio.create_task(self._classify_async(client=self._async_client, document=document, semaphore=semaphore))
|
|
347
|
+
for document in documents
|
|
348
|
+
]
|
|
349
|
+
try:
|
|
350
|
+
results = await asyncio.gather(*tasks)
|
|
351
|
+
except Exception:
|
|
352
|
+
# We only expect to get here when `raise_on_failure` is `True`, since `_classify_async` otherwise records a
|
|
353
|
+
# failed request in `failed_documents` instead of raising. Cancel the remaining requests before re-raising.
|
|
354
|
+
for task in tasks:
|
|
355
|
+
task.cancel()
|
|
356
|
+
await asyncio.gather(*tasks, return_exceptions=True)
|
|
357
|
+
raise
|
|
358
|
+
return {
|
|
359
|
+
"documents": [document for document, succeeded in results if succeeded],
|
|
360
|
+
"failed_documents": [document for document, succeeded in results if not succeeded],
|
|
361
|
+
}
|
|
@@ -26,6 +26,19 @@ _TEXT_BOX_CONTENT_TAG = f"{{{_WORD_NS}}}txbxContent"
|
|
|
26
26
|
# Word writes a text box twice inside `mc:AlternateContent`: a `wps:txbx` under
|
|
27
27
|
# `mc:Choice` and the same text as a VML text box under `mc:Fallback`.
|
|
28
28
|
_FALLBACK_TAG = f"{{{_MARKUP_COMPATIBILITY_NS}}}Fallback"
|
|
29
|
+
_RUN_TAG = f"{{{_WORD_NS}}}r"
|
|
30
|
+
_HYPERLINK_TAG = f"{{{_WORD_NS}}}hyperlink"
|
|
31
|
+
_CONTENT_CONTROL_TAG = f"{{{_WORD_NS}}}sdt"
|
|
32
|
+
_CONTENT_CONTROL_CONTENT_TAG = f"{{{_WORD_NS}}}sdtContent"
|
|
33
|
+
_PLACEHOLDER_TAG = f"{{{_WORD_NS}}}showingPlcHdr"
|
|
34
|
+
# Runs a paragraph shows can sit inside these wrappers, which python-docx's `Paragraph.text`
|
|
35
|
+
# and `iter_inner_content()` do not enter: a tracked insertion, the new place of moved
|
|
36
|
+
# text, a smart tag, a custom XML element and a simple field such as a page number.
|
|
37
|
+
# A tracked deletion (`w:del`) and the old place of moved text (`w:moveFrom`) are not
|
|
38
|
+
# shown, so they are left out.
|
|
39
|
+
_RUN_CONTAINER_TAGS = frozenset(
|
|
40
|
+
f"{{{_WORD_NS}}}{name}" for name in ("ins", "moveTo", "smartTag", "customXml", "fldSimple")
|
|
41
|
+
)
|
|
29
42
|
|
|
30
43
|
# A Markdown table row ends at a line break and its columns are separated by pipes, so
|
|
31
44
|
# neither can survive inside a cell.
|
|
@@ -331,15 +344,11 @@ class DOCXToDocument:
|
|
|
331
344
|
:param paragraph: The DOCX paragraph to process.
|
|
332
345
|
:returns: A string with links formatted according to the specified format.
|
|
333
346
|
"""
|
|
334
|
-
if self.link_format == DOCXLinkFormat.NONE:
|
|
335
|
-
return paragraph.text
|
|
336
347
|
text = ""
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
for content in paragraph.iter_inner_content():
|
|
340
|
-
if isinstance(content, Run):
|
|
348
|
+
for content in self._inline_content(paragraph._p, paragraph):
|
|
349
|
+
if isinstance(content, Run) or self.link_format == DOCXLinkFormat.NONE:
|
|
341
350
|
text += content.text
|
|
342
|
-
|
|
351
|
+
else:
|
|
343
352
|
# Use `.url` instead of `.address` so a URL fragment stored
|
|
344
353
|
# separately by Word (in `w:anchor`) is not dropped.
|
|
345
354
|
if self.link_format == DOCXLinkFormat.MARKDOWN:
|
|
@@ -350,6 +359,44 @@ class DOCXToDocument:
|
|
|
350
359
|
|
|
351
360
|
return text
|
|
352
361
|
|
|
362
|
+
@staticmethod
|
|
363
|
+
def _shows_placeholder(content_control: Any) -> bool:
|
|
364
|
+
"""
|
|
365
|
+
Tells whether a content control still shows its placeholder prompt.
|
|
366
|
+
|
|
367
|
+
:param content_control: The `w:sdt` element.
|
|
368
|
+
:returns: True if its properties hold `w:showingPlcHdr` and the flag is not turned off.
|
|
369
|
+
"""
|
|
370
|
+
properties = content_control.find(f"{{{_WORD_NS}}}sdtPr")
|
|
371
|
+
flag = properties.find(_PLACEHOLDER_TAG) if properties is not None else None
|
|
372
|
+
return flag is not None and flag.get(f"{{{_WORD_NS}}}val", "true").lower() not in ("0", "false", "off")
|
|
373
|
+
|
|
374
|
+
def _inline_content(self, element: Any, paragraph: "Paragraph") -> list["Run | Hyperlink"]:
|
|
375
|
+
"""
|
|
376
|
+
Lists the runs and hyperlinks a paragraph shows, in reading order.
|
|
377
|
+
|
|
378
|
+
Unlike `Paragraph.iter_inner_content()`, this also enters tracked insertions, moved
|
|
379
|
+
text, smart tags, custom XML, simple fields and inline content controls. A content
|
|
380
|
+
control that still shows its placeholder prompt is skipped, as its text is not
|
|
381
|
+
part of the document.
|
|
382
|
+
|
|
383
|
+
:param element: The `w:p` element, or a wrapper inside it.
|
|
384
|
+
:param paragraph: The paragraph the runs belong to.
|
|
385
|
+
:returns: List of `Run` and `Hyperlink` objects.
|
|
386
|
+
"""
|
|
387
|
+
content: list[Run | Hyperlink] = []
|
|
388
|
+
for child in element:
|
|
389
|
+
if child.tag == _RUN_TAG:
|
|
390
|
+
content.append(Run(child, paragraph))
|
|
391
|
+
elif child.tag == _HYPERLINK_TAG:
|
|
392
|
+
content.append(Hyperlink(child, paragraph))
|
|
393
|
+
elif child.tag in _RUN_CONTAINER_TAGS:
|
|
394
|
+
content.extend(self._inline_content(child, paragraph))
|
|
395
|
+
elif child.tag == _CONTENT_CONTROL_TAG and not self._shows_placeholder(child):
|
|
396
|
+
for control_content in child.iterchildren(_CONTENT_CONTROL_CONTENT_TAG):
|
|
397
|
+
content.extend(self._inline_content(control_content, paragraph))
|
|
398
|
+
return content
|
|
399
|
+
|
|
353
400
|
@staticmethod
|
|
354
401
|
def _escape_markdown_cell(text: str) -> str:
|
|
355
402
|
"""
|
{haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/image/document_to_image.py
RENAMED
|
@@ -114,8 +114,9 @@ class DocumentToImageContent:
|
|
|
114
114
|
Dictionary containing one key:
|
|
115
115
|
- "image_contents": ImageContents created from the processed documents. These contain base64-encoded image
|
|
116
116
|
data and metadata. The order corresponds to the order of the input documents. A document that is
|
|
117
|
-
missing the required metadata keys, has an invalid file path, has an unsupported MIME type,
|
|
118
|
-
to a PDF page that cannot be converted gets None in its
|
|
117
|
+
missing the required metadata keys, has an invalid file path, has an unsupported MIME type, has an
|
|
118
|
+
image file that cannot be decoded, or points to a PDF page that cannot be converted gets None in its
|
|
119
|
+
position and a logged warning with the reason.
|
|
119
120
|
"""
|
|
120
121
|
if not documents:
|
|
121
122
|
return {"image_contents": []}
|
|
@@ -148,7 +149,13 @@ class DocumentToImageContent:
|
|
|
148
149
|
else:
|
|
149
150
|
# Process images directly
|
|
150
151
|
bytestream = ByteStream.from_file_path(filepath=path, mime_type=mime_type)
|
|
151
|
-
|
|
152
|
+
try:
|
|
153
|
+
_, base64_image = _encode_image_to_base64(bytestream=bytestream, size=self.size)
|
|
154
|
+
except Exception as error:
|
|
155
|
+
logger.warning(
|
|
156
|
+
"Skipping document with ID {document_id}: {error}", document_id=document.id, error=str(error)
|
|
157
|
+
)
|
|
158
|
+
continue
|
|
152
159
|
image_contents[doc_idx] = ImageContent(
|
|
153
160
|
base64_image=base64_image,
|
|
154
161
|
mime_type=mime_type,
|
{haystack_ai-3.4.1rc1 → haystack_ai-3.5.0}/haystack/components/converters/image/file_to_image.py
RENAMED
|
@@ -79,7 +79,7 @@ class ImageFileToImageContent:
|
|
|
79
79
|
size: tuple[int, int] | None = None,
|
|
80
80
|
) -> dict[str, list[ImageContent]]:
|
|
81
81
|
"""
|
|
82
|
-
Converts files to ImageContent objects.
|
|
82
|
+
Converts files to ImageContent objects. Sources that fail conversion or validation are logged and skipped.
|
|
83
83
|
|
|
84
84
|
:param sources:
|
|
85
85
|
List of file paths or ByteStream objects to convert.
|
|
@@ -100,7 +100,7 @@ class ImageFileToImageContent:
|
|
|
100
100
|
|
|
101
101
|
:returns:
|
|
102
102
|
A dictionary with the following keys:
|
|
103
|
-
- `image_contents`:
|
|
103
|
+
- `image_contents`: Successfully converted images in source order, or an empty list if none succeed.
|
|
104
104
|
"""
|
|
105
105
|
if not sources:
|
|
106
106
|
return {"image_contents": []}
|
|
@@ -135,16 +135,19 @@ class ImageFileToImageContent:
|
|
|
135
135
|
|
|
136
136
|
try:
|
|
137
137
|
inferred_mime_type, base64_image = _encode_image_to_base64(bytestream=bytestream, size=resolved_size)
|
|
138
|
+
merged_metadata = {**bytestream.meta, **metadata}
|
|
139
|
+
image_content = ImageContent(
|
|
140
|
+
base64_image=base64_image,
|
|
141
|
+
mime_type=inferred_mime_type,
|
|
142
|
+
meta=merged_metadata,
|
|
143
|
+
detail=resolved_detail,
|
|
144
|
+
)
|
|
138
145
|
except Exception as e:
|
|
139
146
|
logger.warning(
|
|
140
147
|
"Could not convert file {source}. Skipping it. Error message: {error}", source=source, error=e
|
|
141
148
|
)
|
|
142
149
|
continue
|
|
143
150
|
|
|
144
|
-
merged_metadata = {**bytestream.meta, **metadata}
|
|
145
|
-
image_content = ImageContent(
|
|
146
|
-
base64_image=base64_image, mime_type=inferred_mime_type, meta=merged_metadata, detail=resolved_detail
|
|
147
|
-
)
|
|
148
151
|
image_contents.append(image_content)
|
|
149
152
|
|
|
150
153
|
return {"image_contents": image_contents}
|
|
@@ -134,7 +134,16 @@ class JSONConverter:
|
|
|
134
134
|
:param store_full_path:
|
|
135
135
|
If True, the full path of the file is stored in the metadata of the document.
|
|
136
136
|
If False, only the file name is stored.
|
|
137
|
+
:raises ValueError:
|
|
138
|
+
If neither `jq_schema` nor `content_key` is set, or if `extra_meta_fields` is a string other than `"*"`.
|
|
137
139
|
"""
|
|
140
|
+
if isinstance(extra_meta_fields, str) and extra_meta_fields != "*":
|
|
141
|
+
msg = (
|
|
142
|
+
f"Invalid extra_meta_fields value '{extra_meta_fields}'. "
|
|
143
|
+
"Provide a set of field names or the literal '*' to include all fields."
|
|
144
|
+
)
|
|
145
|
+
raise ValueError(msg)
|
|
146
|
+
|
|
138
147
|
self._compiled_filter = None
|
|
139
148
|
if jq_schema:
|
|
140
149
|
jq_import.check()
|