@@ -192,9 +192,18 @@ async def test_restart_failed_run(gptscript):
192
192
193
193
@pytest .mark .asyncio
194
194
async def test_eval_simple_tool (gptscript , simple_tool ):
195
- run = gptscript .evaluate (simple_tool )
195
+ run = gptscript .evaluate (simple_tool , Options ( disableCache = True ) )
196
196
out = await run .text ()
197
+ prompt_tokens , completion_tokens , total_tokens = 0 , 0 , 0
198
+ for c in run .calls ().values ():
199
+ prompt_tokens += c .usage .promptTokens
200
+ completion_tokens += c .usage .completionTokens
201
+ total_tokens += c .usage .totalTokens
202
+
197
203
assert "Washington" in out , "Unexpected response for tool run"
204
+ assert prompt_tokens > 0 , "Unexpected promptTokens for tool run"
205
+ assert completion_tokens > 0 , "Unexpected completionTokens for tool run"
206
+ assert total_tokens > 0 , "Unexpected totalTokens for tool run"
198
207
199
208
200
209
@pytest .mark .asyncio
@@ -210,6 +219,13 @@ async def test_eval_tool_list(gptscript, tool_list):
210
219
out = await run .text ()
211
220
assert out .strip () == "hello there" , "Unexpected output from eval using a list of tools"
212
221
222
+ # In this case, we expect the total number of toolResults to be 1
223
+ total_tool_results = 0
224
+ for c in run .calls ().values ():
225
+ total_tool_results += c .toolResults
226
+
227
+ assert total_tool_results == 1 , "Unexpected number of toolResults"
228
+
213
229
214
230
@pytest .mark .asyncio
215
231
async def test_eval_tool_list_with_sub_tool (gptscript , tool_list ):
@@ -234,6 +250,23 @@ async def collect_events(run: Run, e: CallFrame | RunFrame | PromptFrame):
234
250
assert '"artists":' in stream_output , "Expected stream_output to have output"
235
251
236
252
253
+ @pytest .mark .asyncio
254
+ async def test_simple_run_file (gptscript ):
255
+ cwd = os .getcwd ().removesuffix ("/tests" )
256
+ run = gptscript .run (cwd + "/tests/fixtures/test.gpt" )
257
+ out = await run .text ()
258
+ assert "Ronald Reagan" in out , "Expect run file to have correct output"
259
+
260
+ # Run again and make sure the output is the same, and the cache is used
261
+ run = gptscript .run (cwd + "/tests/fixtures/test.gpt" )
262
+ second_out = await run .text ()
263
+ assert second_out == out , "Expect run file to have same output as previous run"
264
+
265
+ # In this case, we expect one cached call frame
266
+ for c in run .calls ().values ():
267
+ assert c .chatResponseCached , "Expect chatResponseCached to be true"
268
+
269
+
237
270
@pytest .mark .asyncio
238
271
async def test_stream_run_file (gptscript ):
239
272
stream_output = ""
@@ -687,11 +720,13 @@ async def test_parse_with_metadata_then_run(gptscript):
687
720
run = gptscript .evaluate (tools [0 ])
688
721
assert "200" == await run .text (), "Expect file to have correct output"
689
722
723
+
690
724
@pytest .mark .asyncio
691
725
async def test_credentials (gptscript ):
692
726
name = "test-" + str (os .urandom (4 ).hex ())
693
727
now = datetime .now ()
694
- res = await gptscript .create_credential (Credential (toolName = name , env = {"TEST" : "test" }, expiresAt = now + timedelta (seconds = 5 )))
728
+ res = await gptscript .create_credential (
729
+ Credential (toolName = name , env = {"TEST" : "test" }, expiresAt = now + timedelta (seconds = 5 )))
695
730
assert not res .startswith ("an error occurred" ), "Unexpected error creating credential: " + res
696
731
697
732
sleep (5 )
0 commit comments