Skip to content
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

refactor, better assistant #85

Merged
merged 4 commits into from
Mar 22, 2024
Merged

refactor, better assistant #85

merged 4 commits into from
Mar 22, 2024

Conversation

zachwe
Copy link
Contributor

@zachwe zachwe commented Mar 22, 2024

User description

  • make the assistant better, and default to just 2 parties
  • Fix typing bug
  • make default 1:1, and exit processes to avoid leakage and dev reload issues

Description

  • Added a new log_event function to log events with metadata and audio to the database.
  • Implemented the ResponseAgent class for handling audio transcription, normalization, TTS, and response generation.
  • Refactored voice router to use ResponseAgent and added a new endpoint for podcast room creation.
  • Updated environment variable handling to prevent issues when variables are not set.
  • Fixed a bug to ensure process termination after leaving a daily event.
  • Updated the web app's UI to improve user experience and layout.

Changes walkthrough

Relevant files
Enhancement
db.py
Add event logging functionality with audio support                         

openduck-py/openduck_py/logging/db.py

  • Added a new function log_event to log various events with optional
    metadata and audio.
  • Events are recorded in the database with session ID, event name,
    metadata, and latency.
  • Audio files are saved in the 'logs' directory with a timestamp.
  • +40/-0   
    response_agent.py
    Implement ResponseAgent for audio processing and response generation

    openduck-py/openduck_py/response_agent.py

  • Introduced the ResponseAgent class to handle audio responses.
  • Added methods for audio transcription, text normalization, and
    text-to-speech (TTS) generation.
  • Implemented voice activity detection (VAD) and response generation
    using GPT models.
  • Responses are queued and sent back as audio streams.
  • +381/-0 
    voice.py
    Refactor voice router to use ResponseAgent and add podcast endpoint

    openduck-py/openduck_py/routers/voice.py

  • Refactored code to use the new ResponseAgent class.
  • Removed duplicated code that has been moved to response_agent.py.
  • Added new endpoint /start/podcast to create a podcast room.
  • +31/-382
    page.tsx
    Update UI elements and layout in the main page                                 

    web/src/app/page.tsx

  • Commented out the input field for the user's name.
  • Adjusted the orb button to not depend on the user's name.
  • Updated the main page layout and text.
  • +12/-9   
    Configuration changes
    __init__.py
    Update environment variable handling with default values             

    openduck-py/openduck_py/settings/init.py

  • Updated environment variable retrieval to provide default empty
    strings if not set.
  • +2/-2     
    Bug_fix
    daily.py
    Ensure process termination after leaving daily event                     

    openduck-py/openduck_py/utils/daily.py

  • Added a system exit call after leaving a daily event to ensure process
    termination.
  • +2/-0     

    🔍 Anti-patterns Detected:
    openduck-py/openduck_py/response_agent.py
    IssueLines
    Remove unnecessary else statements65-67
    Remove unnecessary else statements39-41
    openduck-py/openduck_py/routers/voice.py
    IssueLines
    Consider using '{"room_url": room_info['url'], "username": 'Vikram (AI)', "prompt": 'podcast_host', ... }' instead of a call to 'dict'.101-107
    web/src/app/page.tsx
    IssueLines
    Classnames 'w-48, h-48' could be replaced by the 'size-48' shorthand!309-309
    Classname 'transform' is not needed in Tailwind CSS v3!309-309
    Classname 'flex-grow' should be updated to 'grow' in Tailwind CSS v3!337-337
    💡 Usage Guide

    Checking Your Pull Request

    Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

    Talking to CodeAnt AI

    Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

    @codeant-ai ask: Your question here
    

    This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

    Check Your Repository Health

    To analyze the health of your code repository, visit our dashboard at app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

    Copy link

    vercel bot commented Mar 22, 2024

    The latest updates on your projects. Learn more about Vercel for Git ↗︎

    Name Status Preview Comments Updated (UTC)
    openduck ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 22, 2024 3:20pm

    Copy link

    netlify bot commented Mar 22, 2024

    Deploy Preview for openduck ready!

    Name Link
    🔨 Latest commit 81685ef
    🔍 Latest deploy log https://app.netlify.com/sites/openduck/deploys/65fda1949c9b400008e52861
    😎 Deploy Preview https://deploy-preview-85--openduck.netlify.app
    📱 Preview on mobile
    Toggle QR Code...

    QR Code

    Use your smartphone camera to open QR code link.

    To edit notification comments on pull requests, go to your Netlify site configuration.

    @zachwe zachwe changed the title zach better assistant refactor, better assistant Mar 22, 2024
    openduck-py/openduck_py/response_agent.py Show resolved Hide resolved
    openduck-py/openduck_py/routers/voice.py Show resolved Hide resolved
    <button
    className={`orb-button min-w-32 bg-blue-500 hover:bg-blue-600 text-white rounded-full p-4 cursor-pointer shadow-lg transform transition-transform duration-300 ease-in-out ${
    !userName && "opacity-50 cursor-not-allowed"
    className={`orb-button w-48 h-48 bg-blue-500 hover:bg-blue-600 text-white rounded-full p-4 cursor-pointer shadow-lg transform transition-transform duration-300 ease-in-out flex items-center justify-center text-2xl ${
    Copy link
    Contributor

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    • This ESLint rule specifically enforces the usage of shorthand Tailwind CSS classnames, which promotes consistency in coding style by ensuring developers use Tailwind's optimized shorthand syntax where applicable. For instance, converting individual padding classes to a single shorthand p-2 class in the provided example.
    • It helps in reducing the overall file size of the stylesheets by condensing multiple class declarations into fewer shorthand declarations. This can contribute to faster load times and better performance of web applications.
    Suggested change
    className={`orb-button w-48 h-48 bg-blue-500 hover:bg-blue-600 text-white rounded-full p-4 cursor-pointer shadow-lg transform transition-transform duration-300 ease-in-out flex items-center justify-center text-2xl ${
    className={`orb-button size-48 bg-blue-500 hover:bg-blue-600 text-white rounded-full p-4 cursor-pointer shadow-lg transform transition-transform duration-300 ease-in-out flex items-center justify-center text-2xl ${

    <button
    className={`orb-button min-w-32 bg-blue-500 hover:bg-blue-600 text-white rounded-full p-4 cursor-pointer shadow-lg transform transition-transform duration-300 ease-in-out ${
    !userName && "opacity-50 cursor-not-allowed"
    className={`orb-button w-48 h-48 bg-blue-500 hover:bg-blue-600 text-white rounded-full p-4 cursor-pointer shadow-lg transform transition-transform duration-300 ease-in-out flex items-center justify-center text-2xl ${
    Copy link
    Contributor

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    • This ESLint rule specifically targets the migration process from Tailwind CSS v2 to v3 by identifying class names that have either become obsolete or have updated naming conventions in the newer version, making the upgrade smoother and ensuring that the project's styling remains consistent without manual checks.
    • By automatically detecting and suggesting fixes for deprecated or changed class names, this rule not only reduces the time needed for developers to manually search and replace outdated classes but also minimizes the risk of errors that could lead to inconsistent UI/UX throughout the application.
    Suggested change
    className={`orb-button w-48 h-48 bg-blue-500 hover:bg-blue-600 text-white rounded-full p-4 cursor-pointer shadow-lg transform transition-transform duration-300 ease-in-out flex items-center justify-center text-2xl ${
    className={`orb-button w-48 h-48 bg-blue-500 hover:bg-blue-600 text-white rounded-full p-4 cursor-pointer shadow-lg transition-transform duration-300 ease-in-out flex items-center justify-center text-2xl${

    </h1>
    <AudioCall callObject={callObject} />
    <div className="flex-grow flex items-start">
    Copy link
    Contributor

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    • This ESLint rule specifically targets the migration process from Tailwind CSS v2 to v3 by identifying class names that have either become obsolete or have updated naming conventions in the newer version, making the upgrade smoother and ensuring that the project's styling remains consistent without manual checks.
    • By automatically detecting and suggesting fixes for deprecated or changed class names, this rule not only reduces the time needed for developers to manually search and replace outdated classes but also minimizes the risk of errors that could lead to inconsistent UI/UX throughout the application.
    Suggested change
    <div className="flex-grow flex items-start">
    <div className="grow flex items-start">

    @codeant-ai codeant-ai bot added enhancement New feature or request bug_fix labels Mar 22, 2024
    @uberduck-ai uberduck-ai deleted a comment from codeant-ai bot Mar 22, 2024
    "role": "system",
    "content": system_prompt,
    }
    # new_message = {"role": "user", "content": transcription}
    Copy link
    Contributor

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    delete


    # NOTE(zach): retries
    response = None
    for _retry in range(3):
    Copy link
    Contributor

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    not related to this PR but just wondering if the retries help? does it happen often that the openai API fails but then works again on retry? or is it a moderations thing?

    Copy link
    Contributor Author

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    I'm not sure tbh, but I implemented this because things were flagged as moderation violations that clearly shouldn't have been

    @zachwe zachwe merged commit 7138d53 into main Mar 22, 2024
    11 of 13 checks passed
    @zachwe zachwe deleted the zach-better-assistant branch March 22, 2024 15:20
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    bug_fix enhancement New feature or request
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    None yet

    2 participants