@@ -25,9 +25,13 @@ def gptscript():
2525 if os .getenv ("OPENAI_API_KEY" ) is None :
2626 pytest .fail ("OPENAI_API_KEY not set" , pytrace = False )
2727 try :
28+ # Start an initial GPTScript instance.
29+ # This one doesn't have any options, but it's there to ensure that using another instance works as expected in all cases.
30+ g_first = GPTScript ()
2831 gptscript = GPTScript (GlobalOptions (apiKey = os .getenv ("OPENAI_API_KEY" )))
2932 yield gptscript
3033 gptscript .close ()
34+ g_first .close ()
3135 except Exception as e :
3236 pytest .fail (e , pytrace = False )
3337
@@ -111,6 +115,33 @@ async def test_list_models(gptscript):
111115 assert isinstance (models , list ) and len (models ) > 1 , "Expected list_models to return a list"
112116
113117
118+ @pytest .mark .asyncio
119+ async def test_list_models_from_provider (gptscript ):
120+ models = await gptscript .list_models (
121+ providers = ["github.com/gptscript-ai/claude3-anthropic-provider" ],
122+ credential_overrides = ["github.com/gptscript-ai/claude3-anthropic-provider/credential:ANTHROPIC_API_KEY" ],
123+ )
124+ assert isinstance (models , list ) and len (models ) > 1 , "Expected list_models to return a list"
125+ for model in models :
126+ assert model .startswith ("claude-3-" ), "Unexpected model name"
127+ assert model .endswith ("from github.com/gptscript-ai/claude3-anthropic-provider" ), "Unexpected model name"
128+
129+
130+ @pytest .mark .asyncio
131+ async def test_list_models_from_default_provider ():
132+ g = GPTScript (GlobalOptions (defaultModelProvider = "github.com/gptscript-ai/claude3-anthropic-provider" ))
133+ try :
134+ models = await g .list_models (
135+ credential_overrides = ["github.com/gptscript-ai/claude3-anthropic-provider/credential:ANTHROPIC_API_KEY" ],
136+ )
137+ assert isinstance (models , list ) and len (models ) > 1 , "Expected list_models to return a list"
138+ for model in models :
139+ assert model .startswith ("claude-3-" ), "Unexpected model name"
140+ assert model .endswith ("from github.com/gptscript-ai/claude3-anthropic-provider" ), "Unexpected model name"
141+ finally :
142+ g .close ()
143+
144+
114145@pytest .mark .asyncio
115146async def test_list_tools (gptscript ):
116147 out = await gptscript .list_tools ()
@@ -472,10 +503,11 @@ async def process_event(r: Run, frame: CallFrame | RunFrame | PromptFrame):
472503 event_content += output .content
473504
474505 tool = ToolDef (tools = ["sys.exec" ], instructions = "List the files in the current directory as '.'." )
475- out = await gptscript .evaluate (tool ,
476- Options (confirm = True , disableCache = True ),
477- event_handlers = [process_event ],
478- ).text ()
506+ out = await gptscript .evaluate (
507+ tool ,
508+ Options (confirm = True , disableCache = True ),
509+ event_handlers = [process_event ],
510+ ).text ()
479511
480512 assert confirm_event_found , "No confirm event"
481513 # Running the `dir` command in Windows will give the contents of the tests directory
0 commit comments