Back to Prompt Library
implementation
Implement VAPI and ERNIE 4.0 Integration
Inspect the original prompt language first, then copy or adapt it once you know how it fits your workflow.
Linked challenge: Voice-Activated Dynamic Playlist Generator
Format
Code-aware
Lines
23
Sections
5
Linked challenge
Voice-Activated Dynamic Playlist Generator
Prompt source
Original prompt text with formatting preserved for inspection.
23 lines
5 sections
No variables
1 code block
Write the Python code to integrate VAPI for voice input/output and ERNIE 4.0 as the primary generative model within your LangChain agent. This should include setting up VAPI for streaming audio and creating a custom LangChain LLM wrapper for ERNIE 4.0, or utilizing a pre-existing integration if available. Show how the transcribed text from VAPI is passed to the LangChain agent and how the agent's text response is converted back to speech. Include error handling for API calls.
```python
from langchain.agents import AgentExecutor, create_react_agent
from langchain_core.messages import HumanMessage, AIMessage
from langchain_core.prompts import PromptTemplate
from langchain_core.tools import Tool
# Assuming VAPI and ERNIE 4.0 wrappers/SDKs are installed
# from vapi_sdk import VapiClient
# from ernie_llm import ErnieLLM
# ... (define custom tools like MusicSearchTool, PlaylistBuilderTool)
# llm = ErnieLLM(api_key="YOUR_ERNIE_API_KEY")
# tools = [MusicSearchTool(), PlaylistBuilderTool()]
# prompt = PromptTemplate(...)
# agent = create_react_agent(llm, tools, prompt)
# agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True, memory=ConversationBufferMemory())
# def handle_voice_input(audio_data):
# # Use VAPI to transcribe audio
# transcribed_text = vapi_client.transcribe(audio_data)
# response_text = agent_executor.invoke({"input": transcribed_text})["output"]
# # Use VAPI to synthesize speech
# vapi_client.synthesize_speech(response_text)
# return response_text
```Adaptation plan
Keep the source stable, then change the prompt in a predictable order so the next run is easier to evaluate.
Keep stable
Hold the task contract and output shape stable so generated implementations remain comparable.
Tune next
Update libraries, interfaces, and environment assumptions to match the stack you actually run.
Verify after
Test failure handling, edge cases, and any code paths that depend on hidden context or secrets.