22import  tempfile 
33
44import  pytest 
5+ from  pydantic  import  BaseModel 
6+ 
57from  chatlas  import  (
68    ChatOpenAI ,
79    ContentToolRequest ,
1012    Turn ,
1113)
1214from  chatlas ._chat  import  ToolFailureWarning 
13- from  pydantic  import  BaseModel 
1415
1516
1617def  test_simple_batch_chat ():
@@ -19,157 +20,6 @@ def test_simple_batch_chat():
1920    assert  str (response ) ==  "2" 
2021
2122
22- def  test_chat_to_solver_creates_solver ():
23-     pytest .importorskip ("inspect_ai" )
24- 
25-     chat  =  ChatOpenAI ()
26-     solver  =  chat .to_solver ()
27- 
28-     assert  callable (solver )
29- 
30- 
31- def  test_chat_to_solver_with_history ():
32-     pytest .importorskip ("inspect_ai" )
33- 
34-     chat  =  ChatOpenAI (system_prompt = "You are a helpful assistant." )
35-     chat .set_turns (
36-         [
37-             Turn ("user" , "What is 2 + 2?" ),
38-             Turn ("assistant" , "4" ),
39-         ]
40-     )
41- 
42-     solver  =  chat .to_solver ()
43- 
44-     assert  callable (solver )
45-     assert  len (chat .get_turns (include_system_prompt = False )) ==  2 
46-     assert  chat .system_prompt  ==  "You are a helpful assistant." 
47- 
48- 
49- def  test_chat_to_solver_with_rich_content ():
50-     pytest .importorskip ("inspect_ai" )
51-     from  chatlas  import  content_image_url 
52- 
53-     chat  =  ChatOpenAI (system_prompt = "You analyze images." )
54- 
55-     # Create a turn with mixed content (text + image) 
56-     image_content  =  content_image_url ("https://example.com/image.jpg" )
57-     chat .set_turns (
58-         [
59-             Turn ("user" , ["Describe this image" , image_content ]),
60-             Turn ("assistant" , "This is a test image." ),
61-         ]
62-     )
63- 
64-     solver  =  chat .to_solver ()
65- 
66-     assert  callable (solver )
67-     turns  =  chat .get_turns (include_system_prompt = False )
68-     assert  len (turns ) ==  2 
69-     assert  len (turns [0 ].contents ) ==  2   # text + image 
70-     assert  chat .system_prompt  ==  "You analyze images." 
71- 
72- 
73- def  test_chat_to_solver_with_tool_calls ():
74-     pytest .importorskip ("inspect_ai" )
75-     from  chatlas  import  ContentToolRequest , ContentToolResult 
76- 
77-     chat  =  ChatOpenAI ()
78- 
79-     # Create a turn with tool calls 
80-     tool_request  =  ContentToolRequest (
81-         id = "call_123" , name = "get_weather" , arguments = {"city" : "NYC" }
82-     )
83-     tool_result  =  ContentToolResult (value = "Sunny, 75°F" , request = tool_request )
84- 
85-     chat .set_turns (
86-         [
87-             Turn ("user" , "What's the weather in NYC?" ),
88-             Turn ("assistant" , [tool_request ]),
89-             Turn ("user" , [tool_result ]),
90-             Turn ("assistant" , "The weather in NYC is sunny and 75°F." ),
91-         ]
92-     )
93- 
94-     solver  =  chat .to_solver ()
95- 
96-     assert  callable (solver )
97-     turns  =  chat .get_turns (include_system_prompt = False )
98-     assert  len (turns ) ==  4 
99-     assert  isinstance (turns [1 ].contents [0 ], ContentToolRequest )
100-     assert  isinstance (turns [2 ].contents [0 ], ContentToolResult )
101- 
102- 
103- def  test_chat_to_solver_without_inspect_ai ():
104-     import  sys 
105-     from  unittest .mock  import  patch 
106- 
107-     chat  =  ChatOpenAI ()
108- 
109-     # Mock inspect_ai as not installed in sys.modules 
110-     with  patch .dict (sys .modules , {"inspect_ai" : None , "inspect_ai.model" : None }):
111-         with  pytest .raises (ImportError , match = "pip install inspect-a" ):
112-             chat .to_solver ()
113- 
114- 
115- @pytest .mark .asyncio  
116- async  def  test_chat_to_solver_with_pdf_content ():
117-     pytest .importorskip ("inspect_ai" )
118-     from  chatlas ._content  import  ContentPDF 
119- 
120-     chat  =  ChatOpenAI (system_prompt = "You analyze documents." )
121- 
122-     pdf_content  =  ContentPDF (data = b"Mock PDF data" )
123-     chat .set_turns (
124-         [
125-             Turn ("user" , ["Analyze this document" , pdf_content ]),
126-             Turn ("assistant" , "This appears to be a PDF document." ),
127-         ]
128-     )
129- 
130-     solver  =  chat .to_solver ()
131-     assert  callable (solver )
132- 
133-     turns  =  chat .get_turns (include_system_prompt = False )
134-     assert  len (turns ) ==  2 
135-     assert  any (isinstance (c , ContentPDF ) for  c  in  turns [0 ].contents )
136- 
137- 
138- @pytest .mark .asyncio  
139- async  def  test_chat_to_solver_with_json_content ():
140-     pytest .importorskip ("inspect_ai" )
141-     from  chatlas ._content  import  ContentJson 
142- 
143-     chat  =  ChatOpenAI ()
144- 
145-     json_content  =  ContentJson (value = {"key" : "value" , "number" : 42 })
146-     chat .set_turns (
147-         [
148-             Turn ("user" , "Process this data" ),
149-             Turn ("assistant" , [json_content ]),
150-         ]
151-     )
152- 
153-     solver  =  chat .to_solver ()
154-     assert  callable (solver )
155- 
156-     turns  =  chat .get_turns (include_system_prompt = False )
157-     assert  len (turns ) ==  2 
158-     assert  any (isinstance (c , ContentJson ) for  c  in  turns [1 ].contents )
159- 
160- 
161- def  test_chat_to_solver_deepcopy_isolation ():
162-     pytest .importorskip ("inspect_ai" )
163- 
164-     chat  =  ChatOpenAI ()
165-     initial_turns_count  =  len (chat .get_turns ())
166- 
167-     solver  =  chat .to_solver ()
168- 
169-     assert  len (chat .get_turns ()) ==  initial_turns_count 
170-     assert  callable (solver )
171- 
172- 
17323@pytest .mark .asyncio  
17424async  def  test_simple_async_batch_chat ():
17525    chat  =  ChatOpenAI ()
0 commit comments