33import pytest
44
55from humanloop .error import HumanloopRuntimeError
6+ from humanloop .requests .chat_message import ChatMessageParams
7+ from humanloop .types .chat_role import ChatRole
68from tests .custom .types import GetHumanloopClientFn , SyncableFile
79
810
@@ -99,17 +101,16 @@ def test_local_file_call(
99101 client = get_humanloop_client (use_local_files = True , local_files_directory = str (tmp_path ))
100102
101103 # WHEN calling the API with the local file path (without extension)
102- response = client .prompts .call (
103- path = test_path , messages = [{"role" : "user" , "content" : "What is the capital of France?" }]
104- )
104+ call_messages = [ChatMessageParams (role = "user" , content = "What is the capital of France?" )]
105+ response = client .prompts .call (path = test_path , messages = call_messages )
105106
106107 # THEN the response should be successful
107108 assert response is not None
108109 assert response .logs is not None
109110 assert len (response .logs ) > 0
110111
111112 # AND the response should contain the expected output format (lowercase city name)
112- assert "paris" in response .logs [0 ].output .lower ()
113+ assert response . logs [ 0 ]. output is not None and "paris" in response .logs [0 ].output .lower ()
113114
114115 # AND the prompt used should match our expected path
115116 assert response .prompt is not None
@@ -150,11 +151,11 @@ def test_local_file_log(
150151 client = get_humanloop_client (use_local_files = True , local_files_directory = str (tmp_path ))
151152
152153 # GIVEN message content to log
153- test_messages = [{"role" : "user" , "content" : "What is the capital of France?" }]
154154 test_output = "Paris is the capital of France."
155155
156156 # WHEN logging the data with the local file path
157- response = client .prompts .log (path = test_path , messages = test_messages , output = test_output )
157+ messages = [ChatMessageParams (role = "user" , content = "What is the capital of France?" )]
158+ response = client .prompts .log (path = test_path , messages = messages , output = test_output )
158159
159160 # THEN the log should be successful
160161 assert response is not None
@@ -179,6 +180,8 @@ def test_overload_version_environment_handling(
179180 humanloop_client = get_humanloop_client (use_local_files = True , local_files_directory = str (tmp_path ))
180181 humanloop_client .pull ()
181182
183+ test_message = [ChatMessageParams (role = "user" , content = "Testing" )]
184+
182185 # GIVEN a test file that exists locally
183186 test_file = syncable_files_fixture [0 ]
184187 extension = f".{ test_file .type } "
@@ -195,13 +198,13 @@ def test_overload_version_environment_handling(
195198 humanloop_client .prompts .call (
196199 path = test_file .path ,
197200 version_id = test_file .version_id ,
198- messages = [{ "role" : "user" , "content" : "Testing" }] ,
201+ messages = test_message ,
199202 )
200203 elif test_file .type == "agent" :
201204 humanloop_client .agents .call (
202205 path = test_file .path ,
203206 version_id = test_file .version_id ,
204- messages = [{ "role" : "user" , "content" : "Testing" }] ,
207+ messages = test_message ,
205208 )
206209
207210 # WHEN calling with environment
@@ -211,13 +214,13 @@ def test_overload_version_environment_handling(
211214 humanloop_client .prompts .call (
212215 path = test_file .path ,
213216 environment = "production" ,
214- messages = [{ "role" : "user" , "content" : "Testing" }] ,
217+ messages = test_message ,
215218 )
216219 elif test_file .type == "agent" :
217220 humanloop_client .agents .call (
218221 path = test_file .path ,
219222 environment = "production" ,
220- messages = [{ "role" : "user" , "content" : "Testing" }] ,
223+ messages = test_message ,
221224 )
222225
223226 # WHEN calling with both version_id and environment
@@ -228,14 +231,14 @@ def test_overload_version_environment_handling(
228231 path = test_file .path ,
229232 version_id = test_file .version_id ,
230233 environment = "staging" ,
231- messages = [{ "role" : "user" , "content" : "Testing" }] ,
234+ messages = test_message ,
232235 )
233236 elif test_file .type == "agent" :
234237 humanloop_client .agents .call (
235238 path = test_file .path ,
236239 version_id = test_file .version_id ,
237240 environment = "staging" ,
238- messages = [{ "role" : "user" , "content" : "Testing" }] ,
241+ messages = test_message ,
239242 )
240243
241244
@@ -280,8 +283,9 @@ def test_overload_version_environment_handling(
280283# client = get_humanloop_client(use_local_files=True, local_files_directory=str(tmp_path))
281284#
282285# # WHEN calling the API with the local file path (without extension)
286+ # agent_call_messages = [ChatMessageParams(role="user", content="What is the capital of France?")]
283287# response = client.agents.call(
284- # path=test_path, messages=[{"role": "user", "content": "What is the capital of France?"}]
288+ # path=test_path, messages=agent_call_messages
285289# )
286290#
287291# # THEN the response should be successful
@@ -290,16 +294,16 @@ def test_overload_version_environment_handling(
290294# assert len(response.logs) > 0
291295#
292296# # AND the response should contain the expected output format (lowercase city name)
293- # assert "paris" in response.logs[0].output.lower()
297+ # assert response.logs[0].output is not None and "paris" in response.logs[0].output.lower()
294298#
295299# # AND the agent used should match our expected path
296300# assert response.agent is not None
297301# assert response.agent.path == test_path
298302#
299303# # WHEN logging with the local agent file
300- # test_messages = [{"role": "user", "content": "What is the capital of Germany?"}]
301304# test_output = "Berlin is the capital of Germany."
302- # log_response = client.agents.log(path=test_path, messages=test_messages, output=test_output)
305+ # agent_messages = [ChatMessageParams(role="user", content="What is the capital of Germany?")]
306+ # log_response = client.agents.log(path=test_path, messages=agent_messages, output=test_output)
303307#
304308# # THEN the log should be successful
305309# assert log_response is not None
0 commit comments