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: sort func schemas and metadata in diffs #473

Merged
merged 5 commits into from
Dec 1, 2024
Merged

Conversation

jamescalam
Copy link
Member

@jamescalam jamescalam commented Dec 1, 2024

PR Type

Bug fix


Description

  • Fixed an issue with inconsistent ordering in function schemas and metadata by sorting them before stringification.
  • Ensured accurate comparison of stringified function schemas and metadata by using sorted keys.

Changes walkthrough 📝

Relevant files
Bug fix
schema.py
Sort function schemas and metadata for consistent diffs   

semantic_router/schema.py

  • Added sorting for function_schemas and metadata using json.dumps with
    sort_keys=True.
  • Ensured consistent order for stringified function schemas and metadata
    for accurate comparison.
  • +10/-1   

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link

    github-actions bot commented Dec 1, 2024

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Performance Concern
    The addition of sorting keys and JSON serialization in the to_str method might introduce performance overhead, especially with large schemas or metadata. Consider profiling this change to ensure that the performance impact is acceptable.

    Copy link

    github-actions bot commented Dec 1, 2024

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Ensure the function schemas are sorted and serialized without changing their data structure

    Convert the list of JSON strings back to a list of dictionaries after sorting and
    serializing the function schemas to ensure the output remains consistent and
    readable.

    semantic_router/schema.py [132-134]

     function_schemas_sorted = [
    -    json.dumps(schema, sort_keys=True)
    +    json.loads(json.dumps(schema, sort_keys=True))
         for schema in self.function_schemas
     ]
    Suggestion importance[1-10]: 3

    Why: The suggestion to convert JSON strings back to dictionaries after sorting ensures the data structure remains consistent. However, the impact is minor as the primary functionality of sorting and serialization is already achieved.

    3
    Maintain the original dictionary structure of metadata after sorting and serializing

    Convert the sorted and serialized metadata back to a dictionary to maintain the
    original data structure and improve readability.

    semantic_router/schema.py [137]

    -metadata_sorted = json.dumps(self.metadata, sort_keys=True)
    +metadata_sorted = json.loads(json.dumps(self.metadata, sort_keys=True))
    Suggestion importance[1-10]: 3

    Why: Converting the serialized metadata back to a dictionary maintains the original data structure, enhancing readability and consistency. The suggestion is valid but offers a minor improvement in terms of overall functionality.

    3

    Copy link

    codecov bot commented Dec 1, 2024

    Codecov Report

    All modified and coverable lines are covered by tests ✅

    Project coverage is 73.51%. Comparing base (fb1544d) to head (89b3afe).
    Report is 7 commits behind head on main.

    Additional details and impacted files
    @@            Coverage Diff             @@
    ##             main     #473      +/-   ##
    ==========================================
    + Coverage   73.47%   73.51%   +0.03%     
    ==========================================
      Files          43       43              
      Lines        3540     3545       +5     
    ==========================================
    + Hits         2601     2606       +5     
      Misses        939      939              

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

    @jamescalam jamescalam merged commit a7846a5 into main Dec 1, 2024
    9 checks passed
    @jamescalam jamescalam deleted the james/sort-keys-diff branch December 1, 2024 19:29
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant