Integrating Web Search, File Input, and Voice Interaction: A Practical Guide

    Learn how to integrate web search, file input, link reading, deep thinking, OCR, ASR, and TTS into LLM-powered applications. This guide covers capability selection, server-side orchestration versus self-built pipelines, integration steps, and retry strategies for voice conversations.

    1. Key Takeaways First

    LLM services are moving tool invocation from developer code to the server side. In the past, an application that could answer questions with live web data had to handle intent detection, search calls, result cleaning, token truncation, and error retries on its own. Some platforms now let you enable these capabilities through request parameters, so the server performs searching, fetching, assembling, and reasoning before returning the final text.

    This approach reduces glue code, but engineering work does not disappear. Developers still need to decide when to enable search, how to display returned sources, how to control latency and cost, and how to protect user data. The sections below explain how to integrate each capability type and flag what you need to verify yourself.

    2. What Each Capability Solves

    Capability Typical Scenario Input What to Confirm Before Integration
    Web search Answering time-sensitive questions User query Search scope, source attribution, billing rules
    File input Q&A over contracts and reports PDF, Word, and other files Supported formats, page/size limits, retention period
    Link reading Summarizing web pages URL Whether it handles login pages, dynamic pages, and paywalled content
    Deep thinking Multi-step reasoning tasks User query Changes in response time and output tokens
    OCR Text extraction from receipts and screenshots Images Recognition accuracy for handwriting and complex layouts
    ASR Speech-to-text Audio Sample rate, audio formats, max duration per segment
    TTS Text read-aloud Text, voice parameters Languages, voice list, billing by synthesis duration

    The exact support scope in the table above is subject to the platform’s documentation. Any condition not documented must be tested with your own samples.

    3. Self-Built Pipelines vs. Server-Side Orchestration

    Dimension Self-Built Agent Glue Code Server-Side Managed Orchestration
    Development effort Must implement intent detection, search, cleaning, and assembly Mostly parameter configuration and result handling
    Latency You control the pipeline, making it easier to optimize The platform decides the pipeline; you must measure it yourself
    Reliability Depends on your code and third-party APIs Depends on platform availability; timeouts and fallbacks are required
    Debugging difficulty Full logs, straightforward tracing Internal steps are opaque; you rely on returned metadata
    Best fit Custom retrieval sources, complex workflows Rapid prototyping, general-purpose Q&A

    If your business requires designated search sources, filtering rules, or auditing of every tool call, a self-built pipeline is still the better choice.

    4. How to Integrate

    4.1 Enabling Web Search and Deep Thinking

    The basic integration steps are:

    1. Activate the service on the platform and obtain an API key.
    2. Confirm the request endpoint and authentication method, which typically passes the key in a request header.
    3. Set the tool parameters in the request body.
    4. Check the returned sources, latency, and error codes.

    Store the key in environment variables. Never write it into code or logs.

    The following JSON is a structural illustration only. Field names, nesting, and values are not real callable parameters; always refer to the API documentation of the platform you use.

    1. {
    2. "model": "<model name>",
    3. "messages": [
    4. {"role": "user", "content": "Summarize today's major news in artificial intelligence."}
    5. ],
    6. "tools": {
    7. "web_search": {"enabled": true},
    8. "deep_thinking": {"enabled": true}
    9. }
    10. }
    Parameter Category Type Description How to Verify
    Web search toggle Boolean Controls whether search is triggered Check the default value and confirm whether it is off by default
    Search strategy Enum Automatic decision or a specified search mode Check the documented value range
    Deep thinking toggle Boolean Response time usually increases when enabled Compare latency with the same question before and after enabling
    Source information Array Web pages or files the answer is based on Confirm URLs are returned and verify they are accessible

    4.2 Composing ASR, LLM, and TTS for Voice Conversations

    A voice conversation pipeline runs “speech-to-text, model reply, text-to-speech.” Each step can fail, so each step needs its own timeout and retry logic.

    1. import os
    2. import time
    3. API_KEY = os.environ["MODEL_API_KEY"]
    4. MAX_RETRY = 2
    5. TIMEOUT_SECONDS = 10
    6. def with_retry(func, *args, **kwargs):
    7. """Retry timeout errors with exponential backoff. Rate-limit and auth errors should be handled separately."""
    8. last_error = None
    9. for attempt in range(MAX_RETRY + 1):
    10. try:
    11. return func(*args, timeout=TIMEOUT_SECONDS, **kwargs)
    12. except TimeoutError as err:
    13. last_error = err
    14. time.sleep(2 ** attempt)
    15. raise RuntimeError(f"Request failed after {MAX_RETRY} retries") from last_error
    16. def voice_conversation(audio_file_path):
    17. # 1. Speech-to-text. Audio format and sample rate follow the ASR documentation
    18. asr = with_retry(call_asr_api, audio_file_path, api_key=API_KEY)
    19. user_text = asr.get("text", "").strip()
    20. if not user_text:
    21. return fallback_audio("I didn't catch that. Please say it again.")
    22. # 2. Call the chat API
    23. chat = with_retry(call_chat_api,
    24. messages=[{"role": "user", "content": user_text}],
    25. api_key=API_KEY)
    26. reply_text = chat["choices"][0]["message"]["content"]
    27. # 3. Text-to-speech
    28. tts = with_retry(call_tts_api, text=reply_text, api_key=API_KEY)
    29. return tts["audio_data"]

    The functions call_asr_api, call_chat_api, call_tts_api, and fallback_audio are placeholders that must be implemented with the platform’s SDK.

    Stage Common Issues Handling
    ASR Empty transcription, heavy noise Prompt the user to repeat and log the audio metadata
    LLM Timeout or rate limiting Exponential backoff retries; return a fallback message after the limit
    Web search No results or inaccessible sources State in the answer that no evidence was found; never fabricate sources
    TTS Synthesis failure or overly long text Synthesize in segments and cap the length of each segment
    End-to-end Excessive total latency Process in stages and set an overall time budget