@@ -60,7 +60,7 @@ def convert_nonserializable_objects(obj):
60
60
new_obj = {}
61
61
for key , value in obj .items ():
62
62
# Convert key to string if it is a UUID or not already a string.
63
- new_key = str ( key ) if not isinstance (key , str ) else key
63
+ new_key = key if isinstance (key , str ) else str ( key )
64
64
new_obj [new_key ] = convert_nonserializable_objects (value )
65
65
return new_obj
66
66
elif isinstance (obj , list ):
@@ -104,10 +104,8 @@ def dump_collector(collector: SearchResultsCollector) -> list[dict[str, Any]]:
104
104
105
105
def tokens_count_for_message (message , encoding ):
106
106
"""Return the number of tokens used by a single message."""
107
- tokens_per_message = 3
107
+ num_tokens = 3
108
108
109
- num_tokens = 0
110
- num_tokens += tokens_per_message
111
109
if message .get ("function_call" ):
112
110
num_tokens += len (encoding .encode (message ["function_call" ]["name" ]))
113
111
num_tokens += len (
@@ -1136,8 +1134,8 @@ def _parse_user_and_collection_filters(
1136
1134
filters : dict [str , Any ],
1137
1135
):
1138
1136
### TODO - Come up with smarter way to extract owner / collection ids for non-admin
1139
- filter_starts_with_and = filters .get ("$and" , None )
1140
- filter_starts_with_or = filters .get ("$or" , None )
1137
+ filter_starts_with_and = filters .get ("$and" )
1138
+ filter_starts_with_or = filters .get ("$or" )
1141
1139
if filter_starts_with_and :
1142
1140
try :
1143
1141
filter_starts_with_and_then_or = filter_starts_with_and [0 ][
@@ -1262,8 +1260,15 @@ async def _build_aware_system_instruction(
1262
1260
else self .config .agent .agent_static_prompt
1263
1261
)
1264
1262
1263
+ # TODO: This should just be enforced in the config
1264
+ if model is None :
1265
+ raise R2RException (
1266
+ status_code = 400 ,
1267
+ message = "Model not provided for system instruction" ,
1268
+ )
1269
+
1265
1270
if ("gemini" in model or "claude" in model ) and reasoning_agent :
1266
- prompt_name = prompt_name + " _prompted_reasoning"
1271
+ prompt_name = f" { prompt_name } _prompted_reasoning"
1267
1272
1268
1273
if use_system_context or reasoning_agent :
1269
1274
doc_context_str = await self ._build_documents_context (
0 commit comments