Skip to content

Commit

Permalink
fix: sort func schemas and metadata in diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescalam committed Dec 1, 2024
1 parent 77539cf commit c0b293d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion semantic_router/schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime
from difflib import Differ
from enum import Enum
import json
import numpy as np
from typing import List, Optional, Union, Any, Dict, Tuple
from pydantic import BaseModel, Field
Expand Down Expand Up @@ -126,7 +127,15 @@ def to_tuple(self):

def to_str(self, include_metadata: bool = False):
if include_metadata:
return f"{self.route}: {self.utterance} | {self.function_schemas} | {self.metadata}"
# we sort the dicts to ensure consistent order as we need this to compare
# stringified function schemas accurately
function_schemas_sorted = [
json.dumps(schema, sort_keys=True)
for schema in self.function_schemas
]
# we must do the same for metadata
metadata_sorted = json.dumps(self.metadata, sort_keys=True)
return f"{self.route}: {self.utterance} | {function_schemas_sorted} | {metadata_sorted}"
return f"{self.route}: {self.utterance}"

def to_diff_str(self, include_metadata: bool = False):
Expand Down

0 comments on commit c0b293d

Please sign in to comment.