Repository navigation
feat: Add question-based onboarding with phone microphone - #3859
Conversation
- Replace random phrase prompts with goal-oriented questions in speech profile - Questions: age, location, work, long-term goals, monthly goals, daily plans - Use phone microphone instead of Omi device for speech profiling - Auto-detect when user finishes answering (5s silence + word count) - Track transcript per question to avoid counting previous answers - Auto-process conversation when user clicks 'All done' - Create onboarding conversation and memories from user responses - Flow: Rate App -> Speech Profile (skip device connection during onboarding) - Add backend endpoint for AI-based answer detection (/v1/onboarding/check-answer) - Add backend endpoint for onboarding conversation creation (/v1/onboarding/conversation)
|
It works, however i need help to
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new question-based onboarding flow using the phone's microphone, which is a significant and valuable feature. My review has identified a few critical and high-severity issues that should be addressed. On the backend, there are blocking I/O calls in async functions which will degrade performance. On the client-side, there's a critical bug where the speech profile is marked as saved even if the upload fails. Additionally, the logic to detect if a user has answered a question is overly simplistic and doesn't use the new AI-powered backend endpoint, which could lead to a poor user experience. Addressing these points will improve the robustness and performance of this new onboarding flow.
| try { | ||
| await uploadProfile(data.item1); | ||
| } catch (e) {} | ||
| await uploadProfile(data.item1).timeout( | ||
| const Duration(seconds: 30), | ||
| onTimeout: () { | ||
| debugPrint('Profile upload timed out after 30 seconds'); | ||
| return false; // Return false on timeout | ||
| }, | ||
| ); | ||
| debugPrint('Profile upload completed'); | ||
| } catch (e) { | ||
| debugPrint('Error uploading profile: $e'); | ||
| } | ||
|
|
||
| updateLoadingText('Personalizing your experience...'); | ||
| SharedPreferencesUtil().hasSpeakerProfile = true; |
There was a problem hiding this comment.
There's a critical bug in the finalize method. The hasSpeakerProfile preference is set to true regardless of whether the uploadProfile call succeeds, fails, or times out. The result of the timeout operation is not being checked. This will lead to a state where the app believes a speech profile exists when it was never successfully uploaded, which can cause issues later.
bool profileUploaded = false;
try {
profileUploaded = await uploadProfile(data.item1).timeout(
const Duration(seconds: 30),
onTimeout: () {
debugPrint('Profile upload timed out after 30 seconds');
return false; // Return false on timeout
},
);
if (profileUploaded) {
debugPrint('Profile upload completed');
}
} catch (e) {
debugPrint('Error uploading profile: $e');
profileUploaded = false;
}
if (profileUploaded) {
SharedPreferencesUtil().hasSpeakerProfile = true;
}| // Simple client-side answer detection: if user spoke at least 2 words, consider it answered | ||
| final wordCount = currentTranscriptForQuestion.trim().split(RegExp(r'\s+')).where((s) => s.isNotEmpty).length; | ||
| debugPrint('Answer detection: word count = $wordCount'); | ||
|
|
||
| if (wordCount >= 2) { | ||
| debugPrint('Answer detection: User spoke $wordCount words. Moving to next question.'); | ||
| // Save the answer | ||
| questions[currentQuestionIndex].answer = currentTranscriptForQuestion; | ||
| questions[currentQuestionIndex].isAnswered = true; | ||
|
|
||
| // Move to next question (this will reset all tracking) | ||
| _moveToNextQuestion(); | ||
| } else { | ||
| debugPrint('Answer detection: Not enough words ($wordCount), waiting for more input...'); | ||
| isProcessingAnswer = false; | ||
| notifyListeners(); | ||
| } |
There was a problem hiding this comment.
The function _detectAnswerWithAI is misleadingly named as it doesn't use AI. It uses a simple word count (>= 2) to determine if a question is answered. This logic is not robust and can lead to a poor user experience by prematurely moving to the next question. For example, a two-word response to "What is your long-term goal?" is unlikely to be a complete answer.
You have already created a backend endpoint checkQuestionAnswered for this purpose. You should use it here to get a more accurate determination of whether the user has answered the question.
final answered = await checkQuestionAnswered(currentQuestion, currentTranscriptForQuestion);
if (answered == true) {
debugPrint('Answer detection: AI confirmed answer. Moving to next question.');
// Save the answer
questions[currentQuestionIndex].answer = currentTranscriptForQuestion;
questions[currentQuestionIndex].isAnswered = true;
// Move to next question (this will reset all tracking)
_moveToNextQuestion();
} else {
debugPrint('Answer detection: AI determined not answered, waiting for more input...');
isProcessingAnswer = false;
notifyListeners();
}References
- Prefer using existing helper functions over inlining their logic, especially when they handle complex cases like fallbacks or error handling. Inlining can introduce subtle bugs by missing parts of the original logic.
| """ | ||
|
|
||
| try: | ||
| response = llm_mini.invoke(prompt) |
There was a problem hiding this comment.
The llm_mini.invoke() call is synchronous, which blocks the event loop in an async FastAPI route. This can severely degrade the performance of the application, especially under load. You should use the asynchronous version ainvoke() to perform the LLM call without blocking.
This aligns with the general rule: "In an async application, use asynchronous HTTP clients like httpx instead of synchronous ones like requests to avoid blocking the event loop and degrading performance." The same principle applies to LLM client calls.
| response = llm_mini.invoke(prompt) | |
| response = await llm_mini.ainvoke(prompt) |
References
- In an async application, use asynchronous HTTP clients like
httpxinstead of synchronous ones likerequeststo avoid blocking the event loop and degrading performance.
|
|
||
| Write a friendly, personalized overview that captures the key information shared. Return ONLY the overview text, nothing else.""" | ||
|
|
||
| response = llm_mini.invoke(overview_prompt) |
There was a problem hiding this comment.
Similar to the check_question_answered endpoint, the llm_mini.invoke() call here is synchronous and will block the event loop in this async route. This can lead to performance issues. Please use the asynchronous ainvoke() method instead.
| response = llm_mini.invoke(overview_prompt) | |
| response = await llm_mini.ainvoke(overview_prompt) |
References
- In an async application, use asynchronous HTTP clients like
httpxinstead of synchronous ones likerequeststo avoid blocking the event loop and degrading performance.
haha i see. let me > btw what's wrong with > air wearable hard door lol |
|
good catch, AI --- 1 Use WebSocket + MessageEvent in transcribe.py for real-time communication 1 App connects to speech profile websocket with onboarding_mode=true Backend (transcribe.py): • Add onboarding_mode query param to websocket App (SpeechProfileProvider): • Handle new MessageEvent types (onboarding_answer_detected) Remove: • routers/onboarding.py (REST endpoints) -- |
|
Bro @kodjima33, I tried my best in the limited time to make it better, so feel free to test the PR again. You can ask AI to make some adjustments to the experiences. You can also fine-tune the questions on the backend side in P.S. bro, I appreciate your help. By the way, sorry, but this PR is bad and potentially harmful haha |
|
concerns need to be addressed so far:
|
|
good but shoudl be improved:
|
…are#3859) * feat: Add question-based onboarding with phone microphone - Replace random phrase prompts with goal-oriented questions in speech profile - Questions: age, location, work, long-term goals, monthly goals, daily plans - Use phone microphone instead of Omi device for speech profiling - Auto-detect when user finishes answering (5s silence + word count) - Track transcript per question to avoid counting previous answers - Auto-process conversation when user clicks 'All done' - Create onboarding conversation and memories from user responses - Flow: Rate App -> Speech Profile (skip device connection during onboarding) - Add backend endpoint for AI-based answer detection (/v1/onboarding/check-answer) - Add backend endpoint for onboarding conversation creation (/v1/onboarding/conversation) * Integrate onboarding mode into transcribe.py websocket with WebSocket MessageEvents * Enhance onboarding with single language and valid conversation source * Enhance onboarding with more engaging questions and skip support * Reduce silence check timer from 4 to 2 seconds * Enhance onboarding with more engaging questions and skip functionality --------- Co-authored-by: thịnh <[email protected]>
… session starts (#11505) # fix(listen): send the first onboarding question when a speech-profile session starts ## Problem The speech profile page (onboarding and Settings > Profile > Speech Profile) shows no question and its progress bar never moves. Audio still streams and a conversation/recording appears later, so the session looks half-alive. The question flow is server-driven: the client renders whatever `onboarding_question` event the backend pushes, and computes progress as `question_index / total_questions`. PR #9853 split `transcribe.py` into `routers/listen/`, and the split dropped the one-shot kickoff `spawn(onboarding_handler.send_current_question(), ...)` that existed since the flow shipped (#3859). `ListenSessionRuntime._bootstrap` still constructs the `OnboardingHandler`, but nothing ever sends question 0 — `OnboardingHandler.send_current_question` is only reachable after an answer or a skip, which can never happen before the first question exists. The client waits forever on an empty screen at 0%. ## Fix Restore the kickoff at handler creation in `_bootstrap`, spawned through the session task supervisor (same placement and semantics as the pre-refactor code). ## Regression test `test_bootstrap_sends_first_onboarding_question_before_any_audio` runs the real `_bootstrap` with a real `OnboardingHandler` and a recording websocket, and asserts that — with no segments having arrived — the client receives exactly one `onboarding_question` event (question 0 of `len(ONBOARDING_QUESTIONS)`) and the question transcript segment is enqueued with the Omi speaker id. This test fails on `main` today and would have caught the drop in #9853. The existing `_bootstrap` onboarding test's stub handler grew a `send_current_question` coroutine and a real task supervisor, since the production path now calls it. ## Failure class Failure-Class: none No existing class matches "one-shot side effect dropped while splitting a module"; this is the first known instance of that cause in this subsystem, so it lands as an instance fix plus the behavioral guard test above. ## Verification - `BACKEND_UNIT_TEST_FILE_LIST=/tmp/omi-target.txt bash test.sh` (file = `tests/unit/test_listen_runtime_regressions.py`): **20 passed** (includes the new test and the two updated bootstrap tests). - Full unit-suite run surfaced 7 unrelated files exiting status 1 with **all assertions passing** (e.g. "13 passed" + status 1) — the fast-unit CPU duration guard tripping under heavy parallel load on my machine; those files pass when run normally and none touch the listen runtime. - Not exercised against a live device end-to-end: the fix is backend-only and the affected path needs a prod-like STT session; the regression test drives the real `_bootstrap` + `OnboardingHandler` wiring. ## Product invariants affected none <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/11505?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
This is a new onboarding that combines these goals:
- collect speech profile
- collect goals
- generage conversation + memories + action items to show examples to user
- make speech profile from microphone cuz we don’t ned device
It works, however i need help to
If i don’t get help, im merging this tmrw
AI-generated description
RPReplay_Final1766384317.MP4