Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs-website/reference/haystack-api/audio_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ For the supported audio formats, languages, and other parameters, see the

### Usage example

<!-- test-ignore -->

```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__
Expand Down
29 changes: 13 additions & 16 deletions docs-website/reference/haystack-api/converters_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -537,32 +533,33 @@ Documents are expected to have metadata containing:

### Usage example

<!-- test-ignore -->

```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})
# )]
```

Expand Down
6 changes: 4 additions & 2 deletions docs-website/reference/haystack-api/extractors_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,6 @@ in the documents.

Usage example:

<!-- test-ignore -->

```python
from haystack import Document
from haystack.components.extractors.named_entity_extractor import NamedEntityExtractor
Expand All @@ -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__
Expand Down
37 changes: 20 additions & 17 deletions docs-website/reference/haystack-api/generators_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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="<Your Azure endpoint e.g. `https://your-company.azure.openai.com/>",
api_key=Secret.from_token("<your-api-key>"),
azure_deployment="<this is a model name, e.g. gpt-4.1-mini>")
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':
Expand Down Expand Up @@ -708,28 +708,32 @@ format for input and output. Use it to generate text with Hugging Face APIs:

#### With the serverless inference API (Inference Providers) - free tier available

<!-- test-ignore -->

```python
from haystack.components.generators.chat import HuggingFaceAPIChatGenerator
from haystack.dataclasses import ChatMessage
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("<your-api-key>"))
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=<ChatRole.ASSISTANT: 'assistant'>,
# >> _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
Expand All @@ -743,18 +747,17 @@ 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])]

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("<your-api-key>")
token=Secret.from_env_var("HF_API_TOKEN")
)

result = generator.run(messages)
Expand Down
15 changes: 8 additions & 7 deletions docs-website/reference/haystack-api/image_converters_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,33 @@ Documents are expected to have metadata containing:

### Usage example

<!-- test-ignore -->

```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})
# )]
```

Expand Down