9
9
import requests
10
10
11
11
from gptscript .confirm import AuthResponse
12
- from gptscript .frame import RunFrame , CallFrame , PromptFrame
12
+ from gptscript .frame import RunFrame , CallFrame , PromptFrame , Program
13
13
from gptscript .opts import GlobalOptions
14
14
from gptscript .prompt import PromptResponse
15
15
from gptscript .run import Run , RunBasicCommand , Options
@@ -90,7 +90,7 @@ def evaluate(
90
90
opts .merge_global_opts (self .opts ),
91
91
self ._server_url ,
92
92
event_handlers = event_handlers ,
93
- ).next_chat ("" if opts is None else opts .input )
93
+ ).next_chat (opts .input )
94
94
95
95
def run (
96
96
self , tool_path : str ,
@@ -104,7 +104,31 @@ def run(
104
104
opts .merge_global_opts (self .opts ),
105
105
self ._server_url ,
106
106
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" : tool_defs , "disableCache" : disable_cache , "subTool" : sub_tool },
129
+ )
130
+ parsed_nodes = json .loads (out )
131
+ return Program (** parsed_nodes .get ("program" , {}))
108
132
109
133
async def parse (self , file_path : str , disable_cache : bool = False ) -> list [Text | Tool ]:
110
134
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
114
138
return [Text (** node ["textNode" ]) if "textNode" in node else Tool (** node .get ("toolNode" , {}).get ("tool" , {})) for
115
139
node in parsed_nodes .get ("nodes" , [])]
116
140
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 })
119
143
parsed_nodes = json .loads (out )
120
144
if parsed_nodes is None or parsed_nodes .get ("nodes" , None ) is None :
121
145
return []
0 commit comments