@@ -25,9 +25,13 @@ def gptscript():
25
25
if os .getenv ("OPENAI_API_KEY" ) is None :
26
26
pytest .fail ("OPENAI_API_KEY not set" , pytrace = False )
27
27
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 ()
28
31
gptscript = GPTScript (GlobalOptions (apiKey = os .getenv ("OPENAI_API_KEY" )))
29
32
yield gptscript
30
33
gptscript .close ()
34
+ g_first .close ()
31
35
except Exception as e :
32
36
pytest .fail (e , pytrace = False )
33
37
@@ -111,6 +115,33 @@ async def test_list_models(gptscript):
111
115
assert isinstance (models , list ) and len (models ) > 1 , "Expected list_models to return a list"
112
116
113
117
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
+
114
145
@pytest .mark .asyncio
115
146
async def test_list_tools (gptscript ):
116
147
out = await gptscript .list_tools ()
@@ -472,10 +503,11 @@ async def process_event(r: Run, frame: CallFrame | RunFrame | PromptFrame):
472
503
event_content += output .content
473
504
474
505
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 ()
479
511
480
512
assert confirm_event_found , "No confirm event"
481
513
# Running the `dir` command in Windows will give the contents of the tests directory
0 commit comments