1919from unittest .mock import MagicMock , mock_open , patch
2020
2121import cohere
22- from cohere .errors import NotFoundError
2322
2423if "tokenizers" not in sys .modules :
2524 tokenizers_stub = types .ModuleType ("tokenizers" )
@@ -84,22 +83,6 @@ def test_embed_with_model_prefix(self):
8483 self .assertIsNotNone (response .embeddings )
8584 self .assertEqual (len (response .embeddings ), 1 )
8685
87- @unittest .skip (
88- "OCI on-demand models don't support multiple embedding types in a single call. "
89- "The embedding_types parameter in OCI accepts a single value, not a list."
90- )
91- def test_embed_multiple_types (self ):
92- """Test embedding with multiple embedding types."""
93- response = self .client .embed (
94- model = "embed-english-v3.0" ,
95- texts = ["Multi-type test" ],
96- input_type = "search_document" ,
97- embedding_types = ["float" , "int8" ],
98- )
99-
100- self .assertIsNotNone (response )
101- self .assertIsNotNone (response .embeddings )
102-
10386 def test_chat (self ):
10487 """Test chat with OCI."""
10588 response = self .client .chat (
@@ -139,67 +122,6 @@ def test_chat_stream(self):
139122 text_events = [e for e in events if hasattr (e , "text" ) and e .text ]
140123 self .assertTrue (len (text_events ) > 0 )
141124
142- @unittest .skip (
143- "OCI TEXT_GENERATION models are finetune base models, not available via on-demand inference. "
144- "Only CHAT models (command-r, command-a) support on-demand inference on OCI."
145- )
146- def test_generate (self ):
147- """Test text generation with OCI."""
148- response = self .client .generate (
149- model = "command-r-08-2024" ,
150- prompt = "Write a haiku about clouds." ,
151- max_tokens = 100 ,
152- )
153-
154- self .assertIsNotNone (response )
155- self .assertIsNotNone (response .generations )
156- self .assertTrue (len (response .generations ) > 0 )
157- self .assertIsNotNone (response .generations [0 ].text )
158-
159- @unittest .skip (
160- "OCI TEXT_GENERATION models are finetune base models, not available via on-demand inference. "
161- "Only CHAT models (command-r, command-a) support on-demand inference on OCI."
162- )
163- def test_generate_stream (self ):
164- """Test streaming text generation with OCI."""
165- events = []
166- for event in self .client .generate_stream (
167- model = "command-r-08-2024" ,
168- prompt = "Say hello" ,
169- max_tokens = 20 ,
170- ):
171- events .append (event )
172-
173- self .assertTrue (len (events ) > 0 )
174-
175- @unittest .skip (
176- "OCI TEXT_RERANK models are base models, not available via on-demand inference. "
177- "These models require fine-tuning and deployment before use on OCI."
178- )
179- def test_rerank (self ):
180- """Test reranking with OCI."""
181- query = "What is the capital of France?"
182- documents = [
183- "Paris is the capital of France." ,
184- "London is the capital of England." ,
185- "Berlin is the capital of Germany." ,
186- ]
187-
188- response = self .client .rerank (
189- model = "rerank-english-v3.1" ,
190- query = query ,
191- documents = documents ,
192- top_n = 2 ,
193- )
194-
195- self .assertIsNotNone (response )
196- self .assertIsNotNone (response .results )
197- self .assertEqual (len (response .results ), 2 )
198- # First result should be the Paris document
199- self .assertEqual (response .results [0 ].index , 0 )
200- self .assertGreater (response .results [0 ].relevance_score , 0.5 )
201-
202-
203125@unittest .skipIf (os .getenv ("TEST_OCI" ) is None , "TEST_OCI not set" )
204126class TestOciClientV2 (unittest .TestCase ):
205127 """Test OciClientV2 (v2 API) with OCI Generative AI."""
@@ -258,46 +180,6 @@ def test_chat_v2(self):
258180 self .assertIsNotNone (response )
259181 self .assertIsNotNone (response .message )
260182
261- @unittest .skip (
262- "Command A Reasoning model (command-a-reasoning-08-2025) may not be available in all regions. "
263- "Enable this test when the reasoning model is available in your OCI region."
264- )
265- def test_chat_v2_with_thinking (self ):
266- """Test chat with thinking parameter for Command A Reasoning model."""
267- from cohere .types import Thinking
268-
269- response = self .client .chat (
270- model = "command-a-reasoning-08-2025" ,
271- messages = [{"role" : "user" , "content" : "What is 15 * 27? Think step by step." }],
272- thinking = Thinking (type = "enabled" , token_budget = 5000 ),
273- )
274-
275- self .assertIsNotNone (response )
276- self .assertIsNotNone (response .message )
277- # The response should contain content (may include thinking content)
278- self .assertIsNotNone (response .message .content )
279-
280- @unittest .skip (
281- "Command A Reasoning model (command-a-reasoning-08-2025) may not be available in all regions. "
282- "Enable this test when the reasoning model is available in your OCI region."
283- )
284- def test_chat_stream_v2_with_thinking (self ):
285- """Test streaming chat with thinking parameter for Command A Reasoning model."""
286- from cohere .types import Thinking
287-
288- events = []
289- for event in self .client .chat_stream (
290- model = "command-a-reasoning-08-2025" ,
291- messages = [{"role" : "user" , "content" : "What is 15 * 27? Think step by step." }],
292- thinking = Thinking (type = "enabled" , token_budget = 5000 ),
293- ):
294- events .append (event )
295-
296- self .assertTrue (len (events ) > 0 )
297- # Verify we received content-delta events
298- content_delta_events = [e for e in events if hasattr (e , "type" ) and e .type == "content-delta" ]
299- self .assertTrue (len (content_delta_events ) > 0 )
300-
301183 def test_chat_stream_v2 (self ):
302184 """Test streaming chat with v2 client."""
303185 events = []
@@ -330,23 +212,6 @@ def test_chat_stream_v2(self):
330212 # Should have received some text
331213 self .assertTrue (len (full_text ) > 0 )
332214
333- @unittest .skip (
334- "OCI TEXT_RERANK models are base models, not available via on-demand inference. "
335- "These models require fine-tuning and deployment before use on OCI."
336- )
337- def test_rerank_v2 (self ):
338- """Test reranking with v2 client."""
339- response = self .client .rerank (
340- model = "rerank-english-v3.1" ,
341- query = "What is AI?" ,
342- documents = ["AI is artificial intelligence." , "AI is not natural." ],
343- top_n = 1 ,
344- )
345-
346- self .assertIsNotNone (response )
347- self .assertIsNotNone (response .results )
348-
349-
350215@unittest .skipIf (os .getenv ("TEST_OCI" ) is None , "TEST_OCI not set" )
351216class TestOciClientAuthentication (unittest .TestCase ):
352217 """Test different OCI authentication methods."""
@@ -410,21 +275,6 @@ def test_missing_compartment_id(self):
410275 # Missing oci_compartment_id
411276 )
412277
413- @unittest .skip ("Region is available in config file for current test environment" )
414- def test_missing_region (self ):
415- """Test error when region is missing and not in config."""
416- # This test assumes no region in config file
417- # If config has region, this will pass, so we just check it doesn't crash
418- try :
419- client = cohere .OciClient (
420- oci_compartment_id = "ocid1.compartment.oc1..." ,
421- )
422- # If this succeeds, region was in config
423- self .assertIsNotNone (client )
424- except ValueError as e :
425- # Expected if no region in config
426- self .assertIn ("region" , str (e ).lower ())
427-
428278 def test_invalid_model (self ):
429279 """Test error handling with invalid model."""
430280 compartment_id = os .getenv ("OCI_COMPARTMENT_ID" )
@@ -476,21 +326,6 @@ def test_embed_english_v3(self):
476326 self .assertIsNotNone (response .embeddings )
477327 self .assertEqual (len (response .embeddings [0 ]), 1024 )
478328
479- def test_embed_light_v3 (self ):
480- """Test embed-english-light-v3.0 model."""
481- try :
482- response = self .client .embed (
483- model = "embed-english-light-v3.0" ,
484- texts = ["Test" ],
485- input_type = "search_document" ,
486- )
487- except NotFoundError as exc :
488- if "embed-english-light-v3.0" in str (exc ):
489- self .skipTest ("embed-english-light-v3.0 is not available in the current OCI region/profile" )
490- raise
491- self .assertIsNotNone (response .embeddings )
492- self .assertEqual (len (response .embeddings [0 ]), 384 )
493-
494329 def test_embed_multilingual_v3 (self ):
495330 """Test embed-multilingual-v3.0 model."""
496331 response = self .client .embed (
@@ -509,20 +344,6 @@ def test_command_r_plus(self):
509344 )
510345 self .assertIsNotNone (response .text )
511346
512- @unittest .skip (
513- "OCI TEXT_RERANK models are base models, not available via on-demand inference. "
514- "These models require fine-tuning and deployment before use on OCI."
515- )
516- def test_rerank_v3 (self ):
517- """Test rerank-english-v3.0 model."""
518- response = self .client .rerank (
519- model = "rerank-english-v3.1" ,
520- query = "AI" ,
521- documents = ["Artificial Intelligence" , "Biology" ],
522- )
523- self .assertIsNotNone (response .results )
524-
525-
526347class TestOciClientTransformations (unittest .TestCase ):
527348 """Unit tests for OCI request/response transformations (no OCI credentials required)."""
528349
0 commit comments