-
Notifications
You must be signed in to change notification settings - Fork 2.5k
chore: Update code snippets in docs (audio and builders components) #10156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,9 +30,10 @@ class RemoteWhisperTranscriber: | |
|
|
||
| ```python | ||
| from haystack.components.audio import RemoteWhisperTranscriber | ||
| from haystack.utils import Secret | ||
|
|
||
| whisper = RemoteWhisperTranscriber(api_key=Secret.from_token("<your-api-key>"), model="tiny") | ||
| transcription = whisper.run(sources=["path/to/audio/file"]) | ||
| whisper = RemoteWhisperTranscriber(api_key=Secret.from_env_var("OPENAI_API_KEY"), model="whisper-1") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can just use |
||
| transcription = whisper.run(sources=["test/test_files/audio/answer.wav"]) | ||
| ``` | ||
| """ | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,7 +75,7 @@ class ChatPromptBuilder: | |
|
|
||
| # no parameter init, we don't use any runtime template variables | ||
| prompt_builder = ChatPromptBuilder() | ||
| llm = OpenAIChatGenerator(api_key=Secret.from_token("<your-api-key>"), model="gpt-4o-mini") | ||
| llm = OpenAIChatGenerator(api_key=Secret.from_env_var("OPENAI_API_KEY"), model="gpt-5-mini") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, deal! |
||
|
|
||
| pipe = Pipeline() | ||
| pipe.add_component("prompt_builder", prompt_builder) | ||
|
|
@@ -90,27 +90,17 @@ class ChatPromptBuilder: | |
| res = pipe.run(data={"prompt_builder": {"template_variables": {"location": location, "language": language}, | ||
| "template": messages}}) | ||
| print(res) | ||
| # Output example (truncated): | ||
| # {'llm': {'replies': [ChatMessage(...)]}} | ||
|
|
||
| >> {'llm': {'replies': [ChatMessage(_role=<ChatRole.ASSISTANT: 'assistant'>, _content=[TextContent(text= | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the long output can be helpful for users
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok will put it back in |
||
| "Berlin is the capital city of Germany and one of the most vibrant | ||
| and diverse cities in Europe. Here are some key things to know...Enjoy your time exploring the vibrant and dynamic | ||
| capital of Germany!")], _name=None, _meta={'model': 'gpt-4o-mini', | ||
| 'index': 0, 'finish_reason': 'stop', 'usage': {'prompt_tokens': 27, 'completion_tokens': 681, 'total_tokens': | ||
| 708}})]}} | ||
|
|
||
| messages = [system_message, ChatMessage.from_user("What's the weather forecast for {{location}} in the next | ||
| {{day_count}} days?")] | ||
| messages = [system_message, ChatMessage.from_user("What's the forecast for {{location}}, next {{day_count}} days?")] | ||
|
|
||
| res = pipe.run(data={"prompt_builder": {"template_variables": {"location": location, "day_count": "5"}, | ||
| "template": messages}}) | ||
|
|
||
| print(res) | ||
| >> {'llm': {'replies': [ChatMessage(_role=<ChatRole.ASSISTANT: 'assistant'>, _content=[TextContent(text= | ||
| "Here is the weather forecast for Berlin in the next 5 | ||
| days:\\n\\nDay 1: Mostly cloudy with a high of 22°C (72°F) and...so it's always a good idea to check for updates | ||
| closer to your visit.")], _name=None, _meta={'model': 'gpt-4o-mini', | ||
| 'index': 0, 'finish_reason': 'stop', 'usage': {'prompt_tokens': 37, 'completion_tokens': 201, | ||
| 'total_tokens': 238}})]}} | ||
| # Output example (truncated): | ||
| # {'llm': {'replies': [ChatMessage(...)]}} | ||
| ``` | ||
|
|
||
| #### String prompt template | ||
|
|
@@ -131,7 +121,8 @@ class ChatPromptBuilder: | |
| {% endmessage %} | ||
| \"\"\" | ||
|
|
||
| images = [ImageContent.from_file_path("apple.jpg"), ImageContent.from_file_path("orange.jpg")] | ||
| images = [ImageContent.from_file_path("test/test_files/images/apple.jpg"), | ||
| ImageContent.from_file_path("test/test_files/images/haystack-logo.png")] | ||
|
|
||
| builder = ChatPromptBuilder(template=template) | ||
| builder.run(user_name="John", images=images) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
anakin87 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fixes: | ||
| - | | ||
| Fixed pydoc examples in audio and builder components to be valid executable scripts. | ||
| Added missing ``Secret`` import in ``RemoteWhisperTranscriber`` example, fixed unterminated | ||
| string literals in ``ChatPromptBuilder`` examples, and updated file paths to use actual test | ||
| files instead of placeholders. API key examples now use environment variables instead of | ||
| hardcoded placeholders. This ensures all documentation examples can be tested and executed | ||
| successfully. | ||
Uh oh!
There was an error while loading. Please reload this page.