1+ """
2+ Test cases for GenAI client with response_model=None.
3+
4+ This test verifies that the GenAI client properly handles the case when
5+ response_model is set to None, ensuring that OpenAI-style messages are
6+ correctly converted to GenAI-style contents.
7+ """
8+
9+ import pytest
10+ from instructor .mode import Mode
11+
12+
13+ @pytest .mark .parametrize ("mode" , [Mode .GENAI_TOOLS , Mode .GENAI_STRUCTURED_OUTPUTS ])
14+ def test_genai_response_model_none (genai_client , mode ):
15+ """Test that GenAI client works with response_model=None"""
16+
17+ # This should not raise a "Models.generate_content() got an unexpected keyword argument 'messages'" error
18+ messages = [
19+ {
20+ "role" : "user" ,
21+ "content" : "What is the capital of France?"
22+ }
23+ ]
24+
25+ # This should work without error and return the raw response
26+ response = genai_client .chat .completions .create (
27+ messages = messages ,
28+ response_model = None ,
29+ mode = mode
30+ )
31+
32+ # We expect to get back a response object, not a parsed model
33+ assert response is not None
34+ # The response should not be a Pydantic model since response_model=None
35+ from pydantic import BaseModel
36+ assert not isinstance (response , BaseModel )
37+
38+
39+ def test_genai_response_model_none_with_system_message (genai_client ):
40+ """Test that GenAI client works with response_model=None and system message"""
41+
42+ messages = [
43+ {
44+ "role" : "system" ,
45+ "content" : "You are a helpful assistant."
46+ },
47+ {
48+ "role" : "user" ,
49+ "content" : "What is the capital of France?"
50+ }
51+ ]
52+
53+ # This should work without error and properly extract system message
54+ response = genai_client .chat .completions .create (
55+ messages = messages ,
56+ response_model = None ,
57+ mode = Mode .GENAI_TOOLS
58+ )
59+
60+ assert response is not None
0 commit comments