99import requests
1010
1111from gptscript .confirm import AuthResponse
12- from gptscript .frame import RunFrame , CallFrame , PromptFrame
12+ from gptscript .frame import RunFrame , CallFrame , PromptFrame , Program
1313from gptscript .opts import GlobalOptions
1414from gptscript .prompt import PromptResponse
1515from gptscript .run import Run , RunBasicCommand , Options
@@ -90,7 +90,7 @@ def evaluate(
9090 opts .merge_global_opts (self .opts ),
9191 self ._server_url ,
9292 event_handlers = event_handlers ,
93- ).next_chat ("" if opts is None else opts .input )
93+ ).next_chat (opts .input )
9494
9595 def run (
9696 self , tool_path : str ,
@@ -104,7 +104,31 @@ def run(
104104 opts .merge_global_opts (self .opts ),
105105 self ._server_url ,
106106 event_handlers = event_handlers ,
107- ).next_chat ("" if opts is None else opts .input )
107+ ).next_chat (opts .input )
108+
109+ async def load_file (self , file_path : str , disable_cache : bool = False , sub_tool : str = '' ) -> Program :
110+ out = await self ._run_basic_command (
111+ "load" ,
112+ {"file" : file_path , "disableCache" : disable_cache , "subTool" : sub_tool },
113+ )
114+ parsed_nodes = json .loads (out )
115+ return Program (** parsed_nodes .get ("program" , {}))
116+
117+ async def load_content (self , content : str , disable_cache : bool = False , sub_tool : str = '' ) -> Program :
118+ out = await self ._run_basic_command (
119+ "load" ,
120+ {"content" : content , "disableCache" : disable_cache , "subTool" : sub_tool },
121+ )
122+ parsed_nodes = json .loads (out )
123+ return Program (** parsed_nodes .get ("program" , {}))
124+
125+ async def load_tools (self , tool_defs : list [ToolDef ], disable_cache : bool = False , sub_tool : str = '' ) -> Program :
126+ out = await self ._run_basic_command (
127+ "load" ,
128+ {"toolDefs" : [t .to_json () for t in tool_defs ], "disableCache" : disable_cache , "subTool" : sub_tool },
129+ )
130+ parsed_nodes = json .loads (out )
131+ return Program (** parsed_nodes .get ("program" , {}))
108132
109133 async def parse (self , file_path : str , disable_cache : bool = False ) -> list [Text | Tool ]:
110134 out = await self ._run_basic_command ("parse" , {"file" : file_path , "disableCache" : disable_cache })
@@ -114,8 +138,8 @@ async def parse(self, file_path: str, disable_cache: bool = False) -> list[Text
114138 return [Text (** node ["textNode" ]) if "textNode" in node else Tool (** node .get ("toolNode" , {}).get ("tool" , {})) for
115139 node in parsed_nodes .get ("nodes" , [])]
116140
117- async def parse_tool (self , tool_def : str ) -> list [Text | Tool ]:
118- out = await self ._run_basic_command ("parse" , {"content" : tool_def })
141+ async def parse_content (self , content : str ) -> list [Text | Tool ]:
142+ out = await self ._run_basic_command ("parse" , {"content" : content })
119143 parsed_nodes = json .loads (out )
120144 if parsed_nodes is None or parsed_nodes .get ("nodes" , None ) is None :
121145 return []
0 commit comments