Skip to content

Commit b86dbf1

Browse files
docs: sync Haystack API reference on Docusaurus (#11585)
Co-authored-by: davidsbatista <7937824+davidsbatista@users.noreply.github.com>
1 parent 0d4f97a commit b86dbf1

5 files changed

Lines changed: 49 additions & 44 deletions

File tree

docs-website/reference/haystack-api/audio_api.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ For the supported audio formats, languages, and other parameters, see the
1818

1919
### Usage example
2020

21-
<!-- test-ignore -->
22-
2321
```python
2422
from haystack.components.audio import LocalWhisperTranscriber
2523

2624
whisper = LocalWhisperTranscriber(model="small")
2725
transcription = whisper.run(sources=["test/test_files/audio/answer.wav"])
26+
print(transcription)
27+
28+
# >> {'documents': [Document(id=dae7051417caaf19304a4ef2ec845e981abe1efd4c8e6ee7ffb25867f165c411,
29+
# >> content: ' Answer.', meta: {'audio_file': PosixPath('test/test_files/audio/answer.wav'), 'language': 'en'})]}
2830
```
2931

3032
#### __init__

docs-website/reference/haystack-api/converters_api.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -385,17 +385,13 @@ Converts files to FileContent objects to be included in ChatMessage objects.
385385
from haystack.components.converters import FileToFileContent
386386

387387
converter = FileToFileContent()
388-
389-
sources = ["document.pdf", "video.mp4"]
390-
388+
sources = ["test/test_files/pdf/react_paper.pdf", "test/test_files/images/haystack-logo.png"]
391389
file_contents = converter.run(sources=sources)["file_contents"]
392-
print(file_contents)
393390

394-
# [FileContent(base64_data='...',
395-
# mime_type='application/pdf',
396-
# filename='document.pdf',
397-
# extra={}),
398-
# ...]
391+
print(file_contents)
392+
# >> [FileContent(base64_data='...', mime_type='application/pdf', filename='react_paper.pdf', extra={}),
393+
# >> FileContent(base64_data='...', mime_type='image/png', filename='haystack-logo.png', extra={})
394+
# >>]
399395
```
400396

401397
#### run
@@ -537,32 +533,33 @@ Documents are expected to have metadata containing:
537533

538534
### Usage example
539535

540-
<!-- test-ignore -->
541-
542536
```python
543537
from haystack import Document
544538
from haystack.components.converters.image.document_to_image import DocumentToImageContent
545539

546540
converter = DocumentToImageContent(
547541
file_path_meta_field="file_path",
548-
root_path="/data/files",
542+
root_path="test/test_files",
549543
detail="high",
550544
size=(800, 600)
551545
)
552546

553547
documents = [
554-
Document(content="Optional description of image.jpg", meta={"file_path": "image.jpg"}),
555-
Document(content="Text content of page 1 of doc.pdf", meta={"file_path": "doc.pdf", "page_number": 1})
548+
Document(content="Optional description of apple.jpg", meta={"file_path": "images/apple.jpg"}),
549+
Document(
550+
content="Optional description of sample_pdf_1.pdf",
551+
meta={"file_path": "pdf/sample_pdf_1.pdf", "page_number": 1}
552+
)
556553
]
557554

558555
result = converter.run(documents)
559556
image_contents = result["image_contents"]
560557
# [ImageContent(
561-
# base64_image='/9j/4A...', mime_type='image/jpeg', detail='high', meta={'file_path': 'image.jpg'}
558+
# base64_image='/9j/4A...', mime_type='image/jpeg', detail='high', meta={'file_path': 'images/apple.jpg'}
562559
# ),
563560
# ImageContent(
564561
# base64_image='/9j/4A...', mime_type='image/jpeg', detail='high',
565-
# meta={'page_number': 1, 'file_path': 'doc.pdf'}
562+
# meta={'file_path': 'pdf/sample_pdf_1.pdf', 'page_number': 1})
566563
# )]
567564
```
568565

docs-website/reference/haystack-api/extractors_api.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,6 @@ in the documents.
469469

470470
Usage example:
471471

472-
<!-- test-ignore -->
473-
474472
```python
475473
from haystack import Document
476474
from haystack.components.extractors.named_entity_extractor import NamedEntityExtractor
@@ -483,6 +481,10 @@ extractor = NamedEntityExtractor(backend="hugging_face", model="dslim/bert-base-
483481
results = extractor.run(documents=documents)["documents"]
484482
annotations = [NamedEntityExtractor.get_stored_annotations(doc) for doc in results]
485483
print(annotations)
484+
# >> [[NamedEntityAnnotation(entity='PER', start=4, end=10, score=np.float32(0.99054915))],
485+
# >> [NamedEntityAnnotation(entity='PER', start=11, end=16, score=np.float32(0.99641764)),
486+
# >> NamedEntityAnnotation(entity='LOC', start=31, end=39, score=np.float32(0.996198)),
487+
# >> NamedEntityAnnotation(entity='LOC', start=41, end=51, score=np.float32(0.9990196))]]
486488
```
487489

488490
#### __init__

docs-website/reference/haystack-api/generators_api.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ For details on OpenAI API parameters, see
3232
```python
3333
from haystack.components.generators import AzureOpenAIGenerator
3434
from haystack.utils import Secret
35+
3536
client = AzureOpenAIGenerator(
36-
azure_endpoint="<Your Azure endpoint e.g. `https://your-company.azure.openai.com/>",
37-
api_key=Secret.from_token("<your-api-key>"),
38-
azure_deployment="<this is a model name, e.g. gpt-4.1-mini>")
37+
azure_endpoint=Secret.from_env_var("AZURE_OPENAI_ENDPOINT").resolve_value(),
38+
api_key=Secret.from_env_var("AZURE_OPENAI_API_KEY"),
39+
azure_deployment="gpt-4.1-mini")
40+
3941
response = client.run("What's Natural Language Processing? Be brief.")
40-
print(response)
41-
```
4242

43-
```
43+
print(response)
4444
# >> {'replies': ['Natural Language Processing (NLP) is a branch of artificial intelligence that focuses on
4545
# >> the interaction between computers and human language. It involves enabling computers to understand, interpret,
4646
# >> and respond to natural human language in a way that is both meaningful and useful.'], 'meta': [{'model':
@@ -708,28 +708,32 @@ format for input and output. Use it to generate text with Hugging Face APIs:
708708

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

711-
<!-- test-ignore -->
712-
713711
```python
714712
from haystack.components.generators.chat import HuggingFaceAPIChatGenerator
715713
from haystack.dataclasses import ChatMessage
716714
from haystack.utils import Secret
717715
from haystack.utils.hf import HFGenerationAPIType
718716

719717
messages = [ChatMessage.from_system("\nYou are a helpful, respectful and honest assistant"),
720-
ChatMessage.from_user("What's Natural Language Processing?")]
718+
ChatMessage.from_user("What's Natural Language Processing? Please be succinct")]
721719

722720
# the api_type can be expressed using the HFGenerationAPIType enum or as a string
723721
api_type = HFGenerationAPIType.SERVERLESS_INFERENCE_API
724722
api_type = "serverless_inference_api" # this is equivalent to the above
725723

726-
generator = HuggingFaceAPIChatGenerator(api_type=api_type,
727-
api_params={"model": "Qwen/Qwen2.5-7B-Instruct",
728-
"provider": "together"},
729-
token=Secret.from_token("<your-api-key>"))
724+
generator = HuggingFaceAPIChatGenerator(
725+
api_type=api_type,
726+
api_params={"model": "Qwen/Qwen2.5-7B-Instruct", "provider": "together"},
727+
token=Secret.from_env_var("HF_API_TOKEN")
728+
)
730729

731730
result = generator.run(messages)
732731
print(result)
732+
# >> {'replies': [ChatMessage(_role=<ChatRole.ASSISTANT: 'assistant'>,
733+
# >> _content=[TextContent(text='Natural Language Processing (NLP) is a field of AI that focuses on the interaction
734+
# >> between humans and computers using natural language. It enables machines to understand, interpret, and
735+
# >> generate human language.')], _name=None, _meta={'model': 'Qwen/Qwen2.5-7B-Instruct', 'finish_reason':
736+
# >> 'tool_calls', 'index': 0, 'usage': {'prompt_tokens': 33, 'completion_tokens': 39}})]}
733737
```
734738

735739
#### With the serverless inference API (Inference Providers) and text+image input
@@ -743,18 +747,17 @@ from haystack.utils import Secret
743747
from haystack.utils.hf import HFGenerationAPIType
744748

745749
# Create an image from file path, URL, or base64
746-
image = ImageContent.from_file_path("path/to/your/image.jpg")
750+
image = ImageContent.from_file_path("test/test_files/images/apple.jpg")
747751

748752
# Create a multimodal message with both text and image
749753
messages = [ChatMessage.from_user(content_parts=["Describe this image in detail", image])]
750754

751755
generator = HuggingFaceAPIChatGenerator(
752756
api_type=HFGenerationAPIType.SERVERLESS_INFERENCE_API,
753757
api_params={
754-
"model": "Qwen/Qwen2.5-VL-7B-Instruct", # Vision Language Model
755-
"provider": "hyperbolic"
758+
"model": "Qwen/Qwen3.5-9B", "provider": "together" # Vision Language Model
756759
},
757-
token=Secret.from_token("<your-api-key>")
760+
token=Secret.from_env_var("HF_API_TOKEN")
758761
)
759762

760763
result = generator.run(messages)

docs-website/reference/haystack-api/image_converters_api.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,33 @@ Documents are expected to have metadata containing:
2424

2525
### Usage example
2626

27-
<!-- test-ignore -->
28-
2927
```python
3028
from haystack import Document
3129
from haystack.components.converters.image.document_to_image import DocumentToImageContent
3230

3331
converter = DocumentToImageContent(
3432
file_path_meta_field="file_path",
35-
root_path="/data/files",
33+
root_path="test/test_files",
3634
detail="high",
3735
size=(800, 600)
3836
)
3937

4038
documents = [
41-
Document(content="Optional description of image.jpg", meta={"file_path": "image.jpg"}),
42-
Document(content="Text content of page 1 of doc.pdf", meta={"file_path": "doc.pdf", "page_number": 1})
39+
Document(content="Optional description of apple.jpg", meta={"file_path": "images/apple.jpg"}),
40+
Document(
41+
content="Optional description of sample_pdf_1.pdf",
42+
meta={"file_path": "pdf/sample_pdf_1.pdf", "page_number": 1}
43+
)
4344
]
4445

4546
result = converter.run(documents)
4647
image_contents = result["image_contents"]
4748
# [ImageContent(
48-
# base64_image='/9j/4A...', mime_type='image/jpeg', detail='high', meta={'file_path': 'image.jpg'}
49+
# base64_image='/9j/4A...', mime_type='image/jpeg', detail='high', meta={'file_path': 'images/apple.jpg'}
4950
# ),
5051
# ImageContent(
5152
# base64_image='/9j/4A...', mime_type='image/jpeg', detail='high',
52-
# meta={'page_number': 1, 'file_path': 'doc.pdf'}
53+
# meta={'file_path': 'pdf/sample_pdf_1.pdf', 'page_number': 1})
5354
# )]
5455
```
5556

0 commit comments

Comments
 (0)