-
Notifications
You must be signed in to change notification settings - Fork 3.7k
fix(real-time-voicebot): use env vars for API keys #215
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?
fix(real-time-voicebot): use env vars for API keys #215
Conversation
WalkthroughAdds a Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
real-time-voicebot/.env.example(1 hunks)real-time-voicebot/README.md(1 hunks)real-time-voicebot/app.py(2 hunks)
🧰 Additional context used
🪛 dotenv-linter (4.0.0)
real-time-voicebot/.env.example
[warning] 3-3: [UnorderedKey] The ELEVENLABS_API_KEY key should go before the OPENAI_API_KEY key
(UnorderedKey)
🪛 Ruff (0.14.7)
real-time-voicebot/app.py
67-67: f-string without any placeholders
Remove extraneous f prefix
(F541)
🔇 Additional comments (6)
real-time-voicebot/.env.example (1)
1-3: LGTM!The
.env.examplefile correctly documents all required API keys with clear placeholder values. The key ordering matches the initialization order inapp.py, which is more intuitive than alphabetical ordering.real-time-voicebot/app.py (4)
1-2: LGTM!The dotenv integration is correctly implemented with proper imports and initialization at module load time.
Also applies to: 8-9
44-49: LGTM!The normalized parameter formatting (no spaces around equals) improves code consistency and readability.
57-57: LGTM!Using explicit dictionary keys for role and content makes the message structure clearer and more maintainable.
Also applies to: 70-70
72-76: LGTM!Using explicit parameter names for the ElevenLabs generate call improves code clarity.
real-time-voicebot/README.md (1)
23-27: LGTM!The README updates provide clear, actionable setup instructions that align with the environment-based configuration. The dependency list correctly includes
python-dotenv.Also applies to: 32-32
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
real-time-voicebot/app.py (3)
12-24: Env var validation is solid; consider taming the long error message (TRY003)Nice job reading all three API keys and validating them before initializing the clients; this cleanly addresses the earlier review about missing-key failures. To satisfy Ruff’s TRY003 and keep the constructor a bit leaner, you might move the long error string into a small custom exception or module-level constant and raise that instead—purely an optional polish.
Also applies to: 27-27
27-27: Bound the size ofself.interactionto avoid unbounded growth
self.interactionaccumulates every user and assistant turn (Lines 27, 67, 80). For long calls this list can grow large, increasing memory usage and token costs when passed tochat.completions. Consider capping the history (e.g., keep last N turns) or periodically summarizing older context into a single message.- self.interaction.append({"role": "user", "content": transcript.text}) + self.interaction.append({"role": "user", "content": transcript.text}) + # Optionally trim history to last N turns to keep memory/token usage bounded. + MAX_TURNS = 20 + if len(self.interaction) > MAX_TURNS + 1: # +1 for system prompt + self.interaction = [self.interaction[0]] + self.interaction[-MAX_TURNS:]Also applies to: 67-67, 80-80, 83-85
90-93: Wrap script startup logic in anif __name__ == "__main__":guardRight now, importing this module will immediately create an assistant, play the greeting, and start transcription. If you ever want to reuse
AI_Assistantfrom other modules or tests, guarding the startup code will prevent those side effects on import.-greeting = "Thank you for calling London Travel Guide. My name is Rachel, how may I assist you?" -ai_assistant = AI_Assistant() -ai_assistant.generate_audio(greeting) -ai_assistant.start_transcription() +if __name__ == "__main__": + greeting = ( + "Thank you for calling London Travel Guide. " + "My name is Rachel, how may I assist you?" + ) + ai_assistant = AI_Assistant() + ai_assistant.generate_audio(greeting) + ai_assistant.start_transcription()
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
real-time-voicebot/app.py(2 hunks)
🧰 Additional context used
🪛 Ruff (0.14.7)
real-time-voicebot/app.py
17-20: Avoid specifying long messages outside the exception class
(TRY003)
🔇 Additional comments (2)
real-time-voicebot/app.py (2)
1-2: Environment loading pattern looks good for this script-style moduleImporting
load_dotenvand calling it once at module import is appropriate here given that the module immediately runs the assistant as a script; no issues from a correctness or security standpoint.Also applies to: 8-8
54-60: RealtimeTranscriber configuration is clear and explicitUsing keyword arguments for callbacks and
end_utterance_silence_thresholdmakes the transcription setup readable and easy to tweak; no issues spotted in this block.
Hey! Noticed the real-time-voicebot project had hardcoded API keys in the code which isn't great for security or usability.
Made a few changes:
Follows the same pattern as rag-voice-agent and other projects in the repo. Let me know if you want any changes!
Summary by CodeRabbit
New Features
Improvements
Documentation
Chores
✏️ Tip: You can customize this high-level summary in your review settings.