diff --git a/docs-website/reference/haystack-api/audio_api.md b/docs-website/reference/haystack-api/audio_api.md index fd7e95b1043..394c7877bbe 100644 --- a/docs-website/reference/haystack-api/audio_api.md +++ b/docs-website/reference/haystack-api/audio_api.md @@ -18,13 +18,15 @@ For the supported audio formats, languages, and other parameters, see the ### Usage example - - ```python from haystack.components.audio import LocalWhisperTranscriber whisper = LocalWhisperTranscriber(model="small") transcription = whisper.run(sources=["test/test_files/audio/answer.wav"]) +print(transcription) + +# >> {'documents': [Document(id=dae7051417caaf19304a4ef2ec845e981abe1efd4c8e6ee7ffb25867f165c411, +# >> content: ' Answer.', meta: {'audio_file': PosixPath('test/test_files/audio/answer.wav'), 'language': 'en'})]} ``` #### __init__ diff --git a/docs-website/reference/haystack-api/converters_api.md b/docs-website/reference/haystack-api/converters_api.md index dd0f1a02cda..f5f4d1e0f7d 100644 --- a/docs-website/reference/haystack-api/converters_api.md +++ b/docs-website/reference/haystack-api/converters_api.md @@ -385,17 +385,13 @@ Converts files to FileContent objects to be included in ChatMessage objects. from haystack.components.converters import FileToFileContent converter = FileToFileContent() - -sources = ["document.pdf", "video.mp4"] - +sources = ["test/test_files/pdf/react_paper.pdf", "test/test_files/images/haystack-logo.png"] file_contents = converter.run(sources=sources)["file_contents"] -print(file_contents) -# [FileContent(base64_data='...', -# mime_type='application/pdf', -# filename='document.pdf', -# extra={}), -# ...] +print(file_contents) +# >> [FileContent(base64_data='...', mime_type='application/pdf', filename='react_paper.pdf', extra={}), +# >> FileContent(base64_data='...', mime_type='image/png', filename='haystack-logo.png', extra={}) +# >>] ``` #### run @@ -537,32 +533,33 @@ Documents are expected to have metadata containing: ### Usage example - - ```python from haystack import Document from haystack.components.converters.image.document_to_image import DocumentToImageContent converter = DocumentToImageContent( file_path_meta_field="file_path", - root_path="/data/files", + root_path="test/test_files", detail="high", size=(800, 600) ) documents = [ - Document(content="Optional description of image.jpg", meta={"file_path": "image.jpg"}), - Document(content="Text content of page 1 of doc.pdf", meta={"file_path": "doc.pdf", "page_number": 1}) + Document(content="Optional description of apple.jpg", meta={"file_path": "images/apple.jpg"}), + Document( + content="Optional description of sample_pdf_1.pdf", + meta={"file_path": "pdf/sample_pdf_1.pdf", "page_number": 1} + ) ] result = converter.run(documents) image_contents = result["image_contents"] # [ImageContent( -# base64_image='/9j/4A...', mime_type='image/jpeg', detail='high', meta={'file_path': 'image.jpg'} +# base64_image='/9j/4A...', mime_type='image/jpeg', detail='high', meta={'file_path': 'images/apple.jpg'} # ), # ImageContent( # base64_image='/9j/4A...', mime_type='image/jpeg', detail='high', -# meta={'page_number': 1, 'file_path': 'doc.pdf'} +# meta={'file_path': 'pdf/sample_pdf_1.pdf', 'page_number': 1}) # )] ``` diff --git a/docs-website/reference/haystack-api/extractors_api.md b/docs-website/reference/haystack-api/extractors_api.md index 55b9b372fa9..5196eefb777 100644 --- a/docs-website/reference/haystack-api/extractors_api.md +++ b/docs-website/reference/haystack-api/extractors_api.md @@ -469,8 +469,6 @@ in the documents. Usage example: - - ```python from haystack import Document from haystack.components.extractors.named_entity_extractor import NamedEntityExtractor @@ -483,6 +481,10 @@ extractor = NamedEntityExtractor(backend="hugging_face", model="dslim/bert-base- results = extractor.run(documents=documents)["documents"] annotations = [NamedEntityExtractor.get_stored_annotations(doc) for doc in results] print(annotations) +# >> [[NamedEntityAnnotation(entity='PER', start=4, end=10, score=np.float32(0.99054915))], +# >> [NamedEntityAnnotation(entity='PER', start=11, end=16, score=np.float32(0.99641764)), +# >> NamedEntityAnnotation(entity='LOC', start=31, end=39, score=np.float32(0.996198)), +# >> NamedEntityAnnotation(entity='LOC', start=41, end=51, score=np.float32(0.9990196))]] ``` #### __init__ diff --git a/docs-website/reference/haystack-api/generators_api.md b/docs-website/reference/haystack-api/generators_api.md index 9b420e13ef4..87aa43939de 100644 --- a/docs-website/reference/haystack-api/generators_api.md +++ b/docs-website/reference/haystack-api/generators_api.md @@ -32,15 +32,15 @@ For details on OpenAI API parameters, see ```python from haystack.components.generators import AzureOpenAIGenerator from haystack.utils import Secret + client = AzureOpenAIGenerator( - azure_endpoint="", - api_key=Secret.from_token(""), - azure_deployment="") + azure_endpoint=Secret.from_env_var("AZURE_OPENAI_ENDPOINT").resolve_value(), + api_key=Secret.from_env_var("AZURE_OPENAI_API_KEY"), + azure_deployment="gpt-4.1-mini") + response = client.run("What's Natural Language Processing? Be brief.") -print(response) -``` -``` +print(response) # >> {'replies': ['Natural Language Processing (NLP) is a branch of artificial intelligence that focuses on # >> the interaction between computers and human language. It involves enabling computers to understand, interpret, # >> and respond to natural human language in a way that is both meaningful and useful.'], 'meta': [{'model': @@ -708,8 +708,6 @@ format for input and output. Use it to generate text with Hugging Face APIs: #### With the serverless inference API (Inference Providers) - free tier available - - ```python from haystack.components.generators.chat import HuggingFaceAPIChatGenerator from haystack.dataclasses import ChatMessage @@ -717,19 +715,25 @@ from haystack.utils import Secret from haystack.utils.hf import HFGenerationAPIType messages = [ChatMessage.from_system("\nYou are a helpful, respectful and honest assistant"), - ChatMessage.from_user("What's Natural Language Processing?")] + ChatMessage.from_user("What's Natural Language Processing? Please be succinct")] # the api_type can be expressed using the HFGenerationAPIType enum or as a string api_type = HFGenerationAPIType.SERVERLESS_INFERENCE_API api_type = "serverless_inference_api" # this is equivalent to the above -generator = HuggingFaceAPIChatGenerator(api_type=api_type, - api_params={"model": "Qwen/Qwen2.5-7B-Instruct", - "provider": "together"}, - token=Secret.from_token("")) +generator = HuggingFaceAPIChatGenerator( + api_type=api_type, + api_params={"model": "Qwen/Qwen2.5-7B-Instruct", "provider": "together"}, + token=Secret.from_env_var("HF_API_TOKEN") +) result = generator.run(messages) print(result) +# >> {'replies': [ChatMessage(_role=, +# >> _content=[TextContent(text='Natural Language Processing (NLP) is a field of AI that focuses on the interaction +# >> between humans and computers using natural language. It enables machines to understand, interpret, and +# >> generate human language.')], _name=None, _meta={'model': 'Qwen/Qwen2.5-7B-Instruct', 'finish_reason': +# >> 'tool_calls', 'index': 0, 'usage': {'prompt_tokens': 33, 'completion_tokens': 39}})]} ``` #### With the serverless inference API (Inference Providers) and text+image input @@ -743,7 +747,7 @@ from haystack.utils import Secret from haystack.utils.hf import HFGenerationAPIType # Create an image from file path, URL, or base64 -image = ImageContent.from_file_path("path/to/your/image.jpg") +image = ImageContent.from_file_path("test/test_files/images/apple.jpg") # Create a multimodal message with both text and image messages = [ChatMessage.from_user(content_parts=["Describe this image in detail", image])] @@ -751,10 +755,9 @@ messages = [ChatMessage.from_user(content_parts=["Describe this image in detail" generator = HuggingFaceAPIChatGenerator( api_type=HFGenerationAPIType.SERVERLESS_INFERENCE_API, api_params={ - "model": "Qwen/Qwen2.5-VL-7B-Instruct", # Vision Language Model - "provider": "hyperbolic" + "model": "Qwen/Qwen3.5-9B", "provider": "together" # Vision Language Model }, - token=Secret.from_token("") + token=Secret.from_env_var("HF_API_TOKEN") ) result = generator.run(messages) diff --git a/docs-website/reference/haystack-api/image_converters_api.md b/docs-website/reference/haystack-api/image_converters_api.md index eb4415f7c6d..11d61480767 100644 --- a/docs-website/reference/haystack-api/image_converters_api.md +++ b/docs-website/reference/haystack-api/image_converters_api.md @@ -24,32 +24,33 @@ Documents are expected to have metadata containing: ### Usage example - - ```python from haystack import Document from haystack.components.converters.image.document_to_image import DocumentToImageContent converter = DocumentToImageContent( file_path_meta_field="file_path", - root_path="/data/files", + root_path="test/test_files", detail="high", size=(800, 600) ) documents = [ - Document(content="Optional description of image.jpg", meta={"file_path": "image.jpg"}), - Document(content="Text content of page 1 of doc.pdf", meta={"file_path": "doc.pdf", "page_number": 1}) + Document(content="Optional description of apple.jpg", meta={"file_path": "images/apple.jpg"}), + Document( + content="Optional description of sample_pdf_1.pdf", + meta={"file_path": "pdf/sample_pdf_1.pdf", "page_number": 1} + ) ] result = converter.run(documents) image_contents = result["image_contents"] # [ImageContent( -# base64_image='/9j/4A...', mime_type='image/jpeg', detail='high', meta={'file_path': 'image.jpg'} +# base64_image='/9j/4A...', mime_type='image/jpeg', detail='high', meta={'file_path': 'images/apple.jpg'} # ), # ImageContent( # base64_image='/9j/4A...', mime_type='image/jpeg', detail='high', -# meta={'page_number': 1, 'file_path': 'doc.pdf'} +# meta={'file_path': 'pdf/sample_pdf_1.pdf', 'page_number': 1}) # )] ```