@@ -148,7 +148,7 @@ def test_anthropic_client_service_url(mock_anthropic_client: MagicMock) -> None:
148148def test_prepare_message_for_anthropic_text (mock_anthropic_client : MagicMock ) -> None :
149149 """Test converting text message to Anthropic format."""
150150 chat_client = create_test_anthropic_client (mock_anthropic_client )
151- message = ChatMessage ("user" , [ "Hello, world!" ] )
151+ message = ChatMessage (role = "user" , text = "Hello, world!" )
152152
153153 result = chat_client ._prepare_message_for_anthropic (message )
154154
@@ -227,8 +227,8 @@ def test_prepare_messages_for_anthropic_with_system(mock_anthropic_client: Magic
227227 """Test converting messages list with system message."""
228228 chat_client = create_test_anthropic_client (mock_anthropic_client )
229229 messages = [
230- ChatMessage ("system" , [ "You are a helpful assistant." ] ),
231- ChatMessage ("user" , [ "Hello!" ] ),
230+ ChatMessage (role = "system" , text = "You are a helpful assistant." ),
231+ ChatMessage (role = "user" , text = "Hello!" ),
232232 ]
233233
234234 result = chat_client ._prepare_messages_for_anthropic (messages )
@@ -243,8 +243,8 @@ def test_prepare_messages_for_anthropic_without_system(mock_anthropic_client: Ma
243243 """Test converting messages list without system message."""
244244 chat_client = create_test_anthropic_client (mock_anthropic_client )
245245 messages = [
246- ChatMessage ("user" , [ "Hello!" ] ),
247- ChatMessage ("assistant" , [ "Hi there!" ] ),
246+ ChatMessage (role = "user" , text = "Hello!" ),
247+ ChatMessage (role = "assistant" , text = "Hi there!" ),
248248 ]
249249
250250 result = chat_client ._prepare_messages_for_anthropic (messages )
@@ -372,7 +372,7 @@ async def test_prepare_options_basic(mock_anthropic_client: MagicMock) -> None:
372372 """Test _prepare_options with basic ChatOptions."""
373373 chat_client = create_test_anthropic_client (mock_anthropic_client )
374374
375- messages = [ChatMessage ("user" , [ "Hello" ] )]
375+ messages = [ChatMessage (role = "user" , text = "Hello" )]
376376 chat_options = ChatOptions (max_tokens = 100 , temperature = 0.7 )
377377
378378 run_options = chat_client ._prepare_options (messages , chat_options )
@@ -388,8 +388,8 @@ async def test_prepare_options_with_system_message(mock_anthropic_client: MagicM
388388 chat_client = create_test_anthropic_client (mock_anthropic_client )
389389
390390 messages = [
391- ChatMessage ("system" , [ "You are helpful." ] ),
392- ChatMessage ("user" , [ "Hello" ] ),
391+ ChatMessage (role = "system" , text = "You are helpful." ),
392+ ChatMessage (role = "user" , text = "Hello" ),
393393 ]
394394 chat_options = ChatOptions ()
395395
@@ -403,7 +403,7 @@ async def test_prepare_options_with_tool_choice_auto(mock_anthropic_client: Magi
403403 """Test _prepare_options with auto tool choice."""
404404 chat_client = create_test_anthropic_client (mock_anthropic_client )
405405
406- messages = [ChatMessage ("user" , [ "Hello" ] )]
406+ messages = [ChatMessage (role = "user" , text = "Hello" )]
407407 chat_options = ChatOptions (tool_choice = "auto" )
408408
409409 run_options = chat_client ._prepare_options (messages , chat_options )
@@ -415,7 +415,7 @@ async def test_prepare_options_with_tool_choice_required(mock_anthropic_client:
415415 """Test _prepare_options with required tool choice."""
416416 chat_client = create_test_anthropic_client (mock_anthropic_client )
417417
418- messages = [ChatMessage ("user" , [ "Hello" ] )]
418+ messages = [ChatMessage (role = "user" , text = "Hello" )]
419419 # For required with specific function, need to pass as dict
420420 chat_options = ChatOptions (tool_choice = {"mode" : "required" , "required_function_name" : "get_weather" })
421421
@@ -429,7 +429,7 @@ async def test_prepare_options_with_tool_choice_none(mock_anthropic_client: Magi
429429 """Test _prepare_options with none tool choice."""
430430 chat_client = create_test_anthropic_client (mock_anthropic_client )
431431
432- messages = [ChatMessage ("user" , [ "Hello" ] )]
432+ messages = [ChatMessage (role = "user" , text = "Hello" )]
433433 chat_options = ChatOptions (tool_choice = "none" )
434434
435435 run_options = chat_client ._prepare_options (messages , chat_options )
@@ -446,7 +446,7 @@ def get_weather(location: str) -> str:
446446 """Get weather for a location."""
447447 return f"Weather for { location } "
448448
449- messages = [ChatMessage ("user" , [ "Hello" ] )]
449+ messages = [ChatMessage (role = "user" , text = "Hello" )]
450450 chat_options = ChatOptions (tools = [get_weather ])
451451
452452 run_options = chat_client ._prepare_options (messages , chat_options )
@@ -459,7 +459,7 @@ async def test_prepare_options_with_stop_sequences(mock_anthropic_client: MagicM
459459 """Test _prepare_options with stop sequences."""
460460 chat_client = create_test_anthropic_client (mock_anthropic_client )
461461
462- messages = [ChatMessage ("user" , [ "Hello" ] )]
462+ messages = [ChatMessage (role = "user" , text = "Hello" )]
463463 chat_options = ChatOptions (stop = ["STOP" , "END" ])
464464
465465 run_options = chat_client ._prepare_options (messages , chat_options )
@@ -471,7 +471,7 @@ async def test_prepare_options_with_top_p(mock_anthropic_client: MagicMock) -> N
471471 """Test _prepare_options with top_p."""
472472 chat_client = create_test_anthropic_client (mock_anthropic_client )
473473
474- messages = [ChatMessage ("user" , [ "Hello" ] )]
474+ messages = [ChatMessage (role = "user" , text = "Hello" )]
475475 chat_options = ChatOptions (top_p = 0.9 )
476476
477477 run_options = chat_client ._prepare_options (messages , chat_options )
@@ -498,11 +498,11 @@ def test_process_message_basic(mock_anthropic_client: MagicMock) -> None:
498498 assert response .response_id == "msg_123"
499499 assert response .model_id == "claude-3-5-sonnet-20241022"
500500 assert len (response .messages ) == 1
501- assert response .messages [0 ].role == "assistant"
501+ assert response .messages [0 ].role . value == "assistant"
502502 assert len (response .messages [0 ].contents ) == 1
503503 assert response .messages [0 ].contents [0 ].type == "text"
504504 assert response .messages [0 ].contents [0 ].text == "Hello there!"
505- assert response .finish_reason == "stop"
505+ assert response .finish_reason . value == "stop"
506506 assert response .usage_details is not None
507507 assert response .usage_details ["input_token_count" ] == 10
508508 assert response .usage_details ["output_token_count" ] == 5
@@ -532,7 +532,7 @@ def test_process_message_with_tool_use(mock_anthropic_client: MagicMock) -> None
532532 assert response .messages [0 ].contents [0 ].type == "function_call"
533533 assert response .messages [0 ].contents [0 ].call_id == "call_123"
534534 assert response .messages [0 ].contents [0 ].name == "get_weather"
535- assert response .finish_reason == "tool_calls"
535+ assert response .finish_reason . value == "tool_calls"
536536
537537
538538def test_parse_usage_from_anthropic_basic (mock_anthropic_client : MagicMock ) -> None :
@@ -666,7 +666,7 @@ async def test_inner_get_response(mock_anthropic_client: MagicMock) -> None:
666666
667667 mock_anthropic_client .beta .messages .create .return_value = mock_message
668668
669- messages = [ChatMessage ("user" , [ "Hi" ] )]
669+ messages = [ChatMessage (role = "user" , text = "Hi" )]
670670 chat_options = ChatOptions (max_tokens = 10 )
671671
672672 response = await chat_client ._inner_get_response ( # type: ignore[attr-defined]
@@ -690,7 +690,7 @@ async def mock_stream():
690690
691691 mock_anthropic_client .beta .messages .create .return_value = mock_stream ()
692692
693- messages = [ChatMessage ("user" , [ "Hi" ] )]
693+ messages = [ChatMessage (role = "user" , text = "Hi" )]
694694 chat_options = ChatOptions (max_tokens = 10 )
695695
696696 chunks : list [ChatResponseUpdate ] = []
@@ -721,13 +721,13 @@ async def test_anthropic_client_integration_basic_chat() -> None:
721721 """Integration test for basic chat completion."""
722722 client = AnthropicClient ()
723723
724- messages = [ChatMessage ("user" , [ "Say 'Hello, World!' and nothing else." ] )]
724+ messages = [ChatMessage (role = "user" , text = "Say 'Hello, World!' and nothing else." )]
725725
726726 response = await client .get_response (messages = messages , options = {"max_tokens" : 50 })
727727
728728 assert response is not None
729729 assert len (response .messages ) > 0
730- assert response .messages [0 ].role == "assistant"
730+ assert response .messages [0 ].role . value == "assistant"
731731 assert len (response .messages [0 ].text ) > 0
732732 assert response .usage_details is not None
733733
@@ -738,7 +738,7 @@ async def test_anthropic_client_integration_streaming_chat() -> None:
738738 """Integration test for streaming chat completion."""
739739 client = AnthropicClient ()
740740
741- messages = [ChatMessage ("user" , [ "Count from 1 to 5." ] )]
741+ messages = [ChatMessage (role = "user" , text = "Count from 1 to 5." )]
742742
743743 chunks = []
744744 async for chunk in client .get_response (messages = messages , stream = True , options = {"max_tokens" : 50 }):
@@ -754,7 +754,7 @@ async def test_anthropic_client_integration_function_calling() -> None:
754754 """Integration test for function calling."""
755755 client = AnthropicClient ()
756756
757- messages = [ChatMessage ("user" , [ "What's the weather in San Francisco?" ] )]
757+ messages = [ChatMessage (role = "user" , text = "What's the weather in San Francisco?" )]
758758 tools = [get_weather ]
759759
760760 response = await client .get_response (
@@ -774,7 +774,7 @@ async def test_anthropic_client_integration_hosted_tools() -> None:
774774 """Integration test for hosted tools."""
775775 client = AnthropicClient ()
776776
777- messages = [ChatMessage ("user" , [ "What tools do you have available?" ] )]
777+ messages = [ChatMessage (role = "user" , text = "What tools do you have available?" )]
778778 tools = [
779779 HostedWebSearchTool (),
780780 HostedCodeInterpreterTool (),
@@ -801,8 +801,8 @@ async def test_anthropic_client_integration_with_system_message() -> None:
801801 client = AnthropicClient ()
802802
803803 messages = [
804- ChatMessage ("system" , [ "You are a pirate. Always respond like a pirate." ] ),
805- ChatMessage ("user" , [ "Hello!" ] ),
804+ ChatMessage (role = "system" , text = "You are a pirate. Always respond like a pirate." ),
805+ ChatMessage (role = "user" , text = "Hello!" ),
806806 ]
807807
808808 response = await client .get_response (messages = messages , options = {"max_tokens" : 50 })
@@ -817,7 +817,7 @@ async def test_anthropic_client_integration_temperature_control() -> None:
817817 """Integration test with temperature control."""
818818 client = AnthropicClient ()
819819
820- messages = [ChatMessage ("user" , [ "Say hello." ] )]
820+ messages = [ChatMessage (role = "user" , text = "Say hello." )]
821821
822822 response = await client .get_response (
823823 messages = messages ,
@@ -835,11 +835,11 @@ async def test_anthropic_client_integration_ordering() -> None:
835835 client = AnthropicClient ()
836836
837837 messages = [
838- ChatMessage ("user" , [ "Say hello." ] ),
839- ChatMessage ("user" , [ "Then say goodbye." ] ),
840- ChatMessage ("assistant" , [ "Thank you for chatting!" ] ),
841- ChatMessage ("assistant" , [ "Let me know if I can help." ] ),
842- ChatMessage ("user" , [ "Just testing things." ] ),
838+ ChatMessage (role = "user" , text = "Say hello." ),
839+ ChatMessage (role = "user" , text = "Then say goodbye." ),
840+ ChatMessage (role = "assistant" , text = "Thank you for chatting!" ),
841+ ChatMessage (role = "assistant" , text = "Let me know if I can help." ),
842+ ChatMessage (role = "user" , text = "Just testing things." ),
843843 ]
844844
845845 response = await client .get_response (messages = messages )
0 commit comments