@@ -236,6 +236,46 @@ def test_chat_v2(self):
236236 self .assertIsNotNone (response )
237237 self .assertIsNotNone (response .message )
238238
239+ @unittest .skip (
240+ "Command A Reasoning model (command-a-reasoning-08-2025) may not be available in all regions. "
241+ "Enable this test when the reasoning model is available in your OCI region."
242+ )
243+ def test_chat_v2_with_thinking (self ):
244+ """Test chat with thinking parameter for Command A Reasoning model."""
245+ from cohere .types import Thinking
246+
247+ response = self .client .chat (
248+ model = "command-a-reasoning-08-2025" ,
249+ messages = [{"role" : "user" , "content" : "What is 15 * 27? Think step by step." }],
250+ thinking = Thinking (type = "enabled" , token_budget = 5000 ),
251+ )
252+
253+ self .assertIsNotNone (response )
254+ self .assertIsNotNone (response .message )
255+ # The response should contain content (may include thinking content)
256+ self .assertIsNotNone (response .message .content )
257+
258+ @unittest .skip (
259+ "Command A Reasoning model (command-a-reasoning-08-2025) may not be available in all regions. "
260+ "Enable this test when the reasoning model is available in your OCI region."
261+ )
262+ def test_chat_stream_v2_with_thinking (self ):
263+ """Test streaming chat with thinking parameter for Command A Reasoning model."""
264+ from cohere .types import Thinking
265+
266+ events = []
267+ for event in self .client .chat_stream (
268+ model = "command-a-reasoning-08-2025" ,
269+ messages = [{"role" : "user" , "content" : "What is 15 * 27? Think step by step." }],
270+ thinking = Thinking (type = "enabled" , token_budget = 5000 ),
271+ ):
272+ events .append (event )
273+
274+ self .assertTrue (len (events ) > 0 )
275+ # Verify we received content-delta events
276+ content_delta_events = [e for e in events if hasattr (e , "type" ) and e .type == "content-delta" ]
277+ self .assertTrue (len (content_delta_events ) > 0 )
278+
239279 def test_chat_stream_v2 (self ):
240280 """Test streaming chat with v2 client."""
241281 events = []
@@ -455,5 +495,108 @@ def test_rerank_v3(self):
455495 self .assertIsNotNone (response .results )
456496
457497
498+ class TestOciClientTransformations (unittest .TestCase ):
499+ """Unit tests for OCI request/response transformations (no OCI credentials required)."""
500+
501+ def test_thinking_parameter_transformation (self ):
502+ """Test that thinking parameter is correctly transformed to OCI format."""
503+ from cohere .oci_client import transform_request_to_oci
504+
505+ cohere_body = {
506+ "model" : "command-a-reasoning-08-2025" ,
507+ "messages" : [{"role" : "user" , "content" : "What is 2+2?" }],
508+ "thinking" : {
509+ "type" : "enabled" ,
510+ "token_budget" : 10000 ,
511+ },
512+ }
513+
514+ result = transform_request_to_oci ("chat" , cohere_body , "compartment-123" )
515+
516+ # Verify thinking parameter is transformed
517+ chat_request = result ["chatRequest" ]
518+ self .assertIn ("thinking" , chat_request )
519+ self .assertEqual (chat_request ["thinking" ]["type" ], "ENABLED" )
520+ self .assertEqual (chat_request ["thinking" ]["token_budget" ], 10000 )
521+
522+ def test_thinking_parameter_disabled (self ):
523+ """Test that disabled thinking is correctly transformed."""
524+ from cohere .oci_client import transform_request_to_oci
525+
526+ cohere_body = {
527+ "model" : "command-a-reasoning-08-2025" ,
528+ "messages" : [{"role" : "user" , "content" : "Hello" }],
529+ "thinking" : {
530+ "type" : "disabled" ,
531+ },
532+ }
533+
534+ result = transform_request_to_oci ("chat" , cohere_body , "compartment-123" )
535+
536+ chat_request = result ["chatRequest" ]
537+ self .assertIn ("thinking" , chat_request )
538+ self .assertEqual (chat_request ["thinking" ]["type" ], "DISABLED" )
539+ self .assertNotIn ("token_budget" , chat_request ["thinking" ])
540+
541+ def test_thinking_response_transformation (self ):
542+ """Test that thinking content in response is correctly transformed."""
543+ from cohere .oci_client import transform_oci_response_to_cohere
544+
545+ oci_response = {
546+ "chatResponse" : {
547+ "id" : "test-id" ,
548+ "message" : {
549+ "role" : "ASSISTANT" ,
550+ "content" : [
551+ {"type" : "THINKING" , "thinking" : "Let me think about this..." },
552+ {"type" : "TEXT" , "text" : "The answer is 4." },
553+ ],
554+ },
555+ "finishReason" : "COMPLETE" ,
556+ "usage" : {"inputTokens" : 10 , "completionTokens" : 20 },
557+ }
558+ }
559+
560+ result = transform_oci_response_to_cohere ("chat" , oci_response , is_v2 = True )
561+
562+ # Verify content types are lowercased
563+ self .assertEqual (result ["message" ]["content" ][0 ]["type" ], "thinking" )
564+ self .assertEqual (result ["message" ]["content" ][1 ]["type" ], "text" )
565+
566+ def test_stream_event_thinking_transformation (self ):
567+ """Test that thinking content in stream events is correctly transformed."""
568+ from cohere .oci_client import transform_stream_event
569+
570+ # OCI thinking event
571+ oci_event = {
572+ "message" : {
573+ "content" : [{"type" : "THINKING" , "thinking" : "Reasoning step..." }]
574+ }
575+ }
576+
577+ result = transform_stream_event ("chat" , oci_event , is_v2 = True )
578+
579+ self .assertEqual (result ["type" ], "content-delta" )
580+ self .assertIn ("thinking" , result ["delta" ]["message" ]["content" ])
581+ self .assertEqual (result ["delta" ]["message" ]["content" ]["thinking" ], "Reasoning step..." )
582+
583+ def test_stream_event_text_transformation (self ):
584+ """Test that text content in stream events is correctly transformed."""
585+ from cohere .oci_client import transform_stream_event
586+
587+ # OCI text event
588+ oci_event = {
589+ "message" : {
590+ "content" : [{"type" : "TEXT" , "text" : "The answer is..." }]
591+ }
592+ }
593+
594+ result = transform_stream_event ("chat" , oci_event , is_v2 = True )
595+
596+ self .assertEqual (result ["type" ], "content-delta" )
597+ self .assertIn ("text" , result ["delta" ]["message" ]["content" ])
598+ self .assertEqual (result ["delta" ]["message" ]["content" ]["text" ], "The answer is..." )
599+
600+
458601if __name__ == "__main__" :
459602 unittest .main ()
0 commit comments