File tree 3 files changed +17
-0
lines changed
3 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -97,12 +97,16 @@ def run(
97
97
async def parse (self , file_path : str , disable_cache : bool = False ) -> list [Text | Tool ]:
98
98
out = await self ._run_basic_command ("parse" , {"file" : file_path , "disableCache" : disable_cache })
99
99
parsed_nodes = json .loads (out )
100
+ if parsed_nodes is None or parsed_nodes .get ("nodes" , None ) is None :
101
+ return []
100
102
return [Text (** node ["textNode" ]) if "textNode" in node else Tool (** node .get ("toolNode" , {}).get ("tool" , {})) for
101
103
node in parsed_nodes .get ("nodes" , [])]
102
104
103
105
async def parse_tool (self , tool_def : str ) -> list [Text | Tool ]:
104
106
out = await self ._run_basic_command ("parse" , {"content" : tool_def })
105
107
parsed_nodes = json .loads (out )
108
+ if parsed_nodes is None or parsed_nodes .get ("nodes" , None ) is None :
109
+ return []
106
110
return [Text (** node ["textNode" ]) if "textNode" in node else Tool (** node .get ("toolNode" , {}).get ("tool" , {})) for
107
111
node in parsed_nodes .get ("nodes" , [])]
108
112
Original file line number Diff line number Diff line change @@ -259,6 +259,19 @@ async def test_parse_simple_file(gptscript):
259
259
"Unexpected output from parsing simple file"
260
260
261
261
262
+ @pytest .mark .asyncio
263
+ async def test_parse_empty_file (gptscript ):
264
+ wd = os .getcwd ()
265
+ tools = await gptscript .parse (wd + "/tests//fixtures/empty.gpt" )
266
+ assert len (tools ) == 0 , "Unexpected number of tools for parsing emtpy file"
267
+
268
+
269
+ @pytest .mark .asyncio
270
+ async def test_parse_empty_str (gptscript ):
271
+ tools = await gptscript .parse_tool ("" )
272
+ assert len (tools ) == 0 , "Unexpected number of tools for parsing empty string"
273
+
274
+
262
275
@pytest .mark .asyncio
263
276
async def test_parse_tool_with_metadata (gptscript ):
264
277
wd = os .getcwd ()
You can’t perform that action at this time.
0 commit comments