okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
f5b255007
main
1"""#5979: a declared boolean parameter came back as the string "True" / "False" (the model's Python spelling), not as true / false.""" 2 3import unittest 4 5from serve .frontend import OutputParser ,coerce_value ,parse_tool_call 6 7TOOL = {"name" :"write_note" ,"parameters" : {"type" :"object" ,"properties" : { 8"formatted" : {"type" :"boolean" },"title" : {"type" :"string" },"pinned" : {"type" : ["boolean" ,"null" ]}, 9"label" : {"type" : ["boolean" ,"string" ]}}}} 10 11 12class BooleanArguments (unittest .TestCase ): 13def test_the_python_spelling_of_a_declared_boolean_is_the_boolean (self ): 14for text ,want in (("True" ,True ), ("False" ,False ), ("true" ,True ), ("false" ,False ), (" TRUE " ,True )): 15self .assertIs (coerce_value (text ,"boolean" ),want ,text ) 16self .assertIs (coerce_value ("False" , ["boolean" ,"null" ]),False ) 17 18def test_strings_and_other_words_are_left_as_they_were (self ): 19self .assertEqual (coerce_value ("True" ,"string" ),"True" ) 20self .assertEqual (coerce_value ("True" , ["boolean" ,"string" ]),"True" ,"a string is allowed: the text stays text" ) 21self .assertEqual (coerce_value ("yes" ,"boolean" ),"yes" ) 22self .assertEqual (coerce_value ("True" ,None ),"True" ,"no schema: as before" ) 23 24def test_a_whole_call_and_the_streamed_parser_give_booleans (self ): 25body = "<function=write_note>\n<parameter=formatted>\nTrue\n</parameter>\n<parameter=title>\nTrue\n</parameter>\n</function>" 26self .assertEqual (parse_tool_call (body ,TOOL ).arguments , {"formatted" :True ,"title" :"True" }) 27parser = OutputParser (thinking = False ,tools = [TOOL ],stream_tools = True ) 28events = parser .feed ("<tool_call>\n" + body + "\n</tool_call>" )+ parser .finish () 29calls = [e for e in events if e .kind == "tool_call" ] 30self .assertEqual (len (calls ),1 ,events ) 31self .assertEqual (calls [0 ].call .arguments ["formatted" ],True ) 32self .assertEqual (calls [0 ].call .arguments ["title" ],"True" ) 33 34 35if __name__ == "__main__" : 36unittest .main ()