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

fix: bug in synced dynamic routes #416

Merged
merged 2 commits into from
Sep 6, 2024
Merged

Conversation

jamescalam
Copy link
Member

@jamescalam jamescalam commented Sep 5, 2024

PR Type

enhancement, bug fix


Description

  • Refactored the get_routes and async_get_routes methods in pinecone.py to use a new parse_route_info function for better code organization and readability.
  • Enhanced docstrings across several methods in pinecone.py to include parameter and return type annotations.
  • Improved route synchronization logic in layer.py by handling function schemas more robustly and added logging for debugging.
  • Added logging in openai.py to assist in debugging function schema handling.

Changes walkthrough 📝

Relevant files
Enhancement
pinecone.py
Refactor route parsing and enhance docstrings                       

semantic_router/index/pinecone.py

  • Refactored the get_routes and async_get_routes methods to use a new
    parse_route_info function.
  • Added detailed docstrings for methods with parameter and return type
    annotations.
  • Introduced a new function parse_route_info to handle metadata parsing.

  • +62/-53 
    layer.py
    Improve route synchronization and add logging                       

    semantic_router/layer.py

  • Added logging for debugging purposes.
  • Refactored route synchronization logic to handle function schemas more
    robustly.
  • +14/-8   
    openai.py
    Add logging for function schema handling                                 

    semantic_router/llms/openai.py

    • Added logging for debugging function schema handling.
    +4/-1     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @github-actions github-actions bot added enhancement Enhancement to existing features Bug fix Review effort [1-5]: 3 labels Sep 5, 2024
    Copy link

    github-actions bot commented Sep 5, 2024

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Code Clarity
    The use of tuple packing in parse_route_info function (lines 801-825) may reduce code readability and maintainability. Consider using a more structured approach, such as named tuples or data classes.

    Redundant Code
    The logging statements added in various methods seem to be for debugging purposes and should be removed or replaced with more appropriate logging levels if they are to be kept for production (e.g., logger.debug instead of logger.info).

    Logging Level
    The logging level used in _add_and_sync_routes method (lines 548-561) should be adjusted. Debugging information should use logger.debug instead of logger.info.

    Copy link

    github-actions bot commented Sep 5, 2024

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Add error handling to prevent crashes due to malformed metadata

    Ensure that the error handling for parse_route_info is robust, especially in cases
    where metadata might be incomplete or malformed.

    semantic_router/index/pinecone.py [793]

    -route_info = parse_route_info(metadata=metadata)
    +try:
    +    route_info = parse_route_info(metadata=metadata)
    +except Exception as e:
    +    logger.error("Failed to parse route info: %s", e)
    +    route_info = []
     
    Suggestion importance[1-10]: 10

    Why: Adding error handling for parsing metadata is crucial to prevent application crashes due to malformed data, which is a significant improvement for robustness and reliability.

    10
    Security
    Remove unnecessary and potentially sensitive logging

    Remove redundant logging statements that could potentially expose sensitive data or
    clutter the log files.

    semantic_router/llms/openai.py [97-99]

    -logger.info(f"{function_schemas=}")
    -logger.info(f"{function_schemas is None=}")
    -logger.info(f"{tools=}")
    +# Removed unnecessary logging
     
    Suggestion importance[1-10]: 9

    Why: Removing redundant logging statements helps prevent potential exposure of sensitive data and reduces log clutter, which is crucial for security and performance.

    9
    Maintainability
    Improve code structure and readability by using named tuples

    Replace the tuple packing with a more structured approach using a data class or
    named tuple for better maintainability and readability.

    semantic_router/index/pinecone.py [824]

    -route_info.append((sr_route, sr_utterance, sr_function_schema, additional_metadata))
    +RouteInfo = namedtuple('RouteInfo', ['route', 'utterance', 'function_schema', 'metadata'])
    +route_info.append(RouteInfo(sr_route, sr_utterance, sr_function_schema, additional_metadata))
     
    Suggestion importance[1-10]: 8

    Why: Using named tuples enhances code readability and maintainability by providing a more structured approach compared to tuple packing, which is beneficial for understanding and future modifications.

    8
    Best practice
    Enhance logging practices by adjusting the log level and message content

    Remove the debug logging statement or replace it with a more appropriate logging
    level and message.

    semantic_router/layer.py [222]

    -logger.info(f"JB TEMP: {self.routes=}")
    +logger.debug("Initializing index with routes: %s", self.routes)
     
    Suggestion importance[1-10]: 7

    Why: Changing the log level to debug and providing a more descriptive message improves logging practices, making logs more meaningful and less cluttered.

    7

    Copy link

    codecov bot commented Sep 5, 2024

    Codecov Report

    Attention: Patch coverage is 5.00000% with 19 lines in your changes missing coverage. Please review.

    Project coverage is 62.53%. Comparing base (40f7ec1) to head (be86fe0).
    Report is 4 commits behind head on main.

    Files with missing lines Patch % Lines
    semantic_router/index/pinecone.py 7.14% 13 Missing ⚠️
    semantic_router/layer.py 0.00% 6 Missing ⚠️
    Additional details and impacted files
    @@            Coverage Diff             @@
    ##             main     #416      +/-   ##
    ==========================================
    - Coverage   62.80%   62.53%   -0.27%     
    ==========================================
      Files          46       46              
      Lines        3452     3465      +13     
    ==========================================
    - Hits         2168     2167       -1     
    - Misses       1284     1298      +14     

    ☔ View full report in Codecov by Sentry.
    📢 Have feedback on the report? Share it here.

    @jamescalam jamescalam merged commit 38eddff into main Sep 6, 2024
    6 of 8 checks passed
    @jamescalam jamescalam deleted the james/func-schema-bug-pinecone branch September 6, 2024 08:16
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    Bug fix enhancement Enhancement to existing features Review effort [1-5]: 3
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant