@@ -121,7 +121,10 @@ def test_AIAssistant_invoke():
121121 id = "4" ,
122122 ),
123123 HumanMessage (
124- content = "What about tomorrow?" , additional_kwargs = {}, response_metadata = {}, id = "5"
124+ content = "What about tomorrow?" ,
125+ additional_kwargs = {},
126+ response_metadata = {},
127+ id = "5" ,
125128 ),
126129 AIMessage (
127130 content = "" ,
@@ -273,6 +276,95 @@ def tool_a(self, foo: str) -> str:
273276 ]
274277
275278
279+ @patch ("django_ai_assistant.helpers.assistants.ChatOpenAI" )
280+ def test_AIAssistant_get_llm_default_temperature (mock_chat_openai ):
281+ class DefaultTempAssistant (AIAssistant ):
282+ id = "default_temp_assistant" # noqa: A003
283+ name = "Default Temp Assistant"
284+ instructions = "Instructions"
285+ model = "gpt-test"
286+
287+ assistant = DefaultTempAssistant ()
288+ assistant .get_llm ()
289+
290+ mock_chat_openai .assert_called_once_with (
291+ model = "gpt-test" ,
292+ temperature = assistant .temperature ,
293+ model_kwargs = {},
294+ )
295+ AIAssistant .clear_cls_registry ()
296+
297+
298+ @patch ("django_ai_assistant.helpers.assistants.ChatOpenAI" )
299+ def test_AIAssistant_get_llm_custom_temperature (mock_chat_openai ):
300+ custom_temperature = 0.5
301+
302+ class CustomTempAssistant (AIAssistant ):
303+ id = "custom_temp_assistant" # noqa: A003
304+ name = "Custom Temp Assistant"
305+ instructions = "Instructions"
306+ model = "gpt-test"
307+ temperature = custom_temperature
308+
309+ assistant = CustomTempAssistant ()
310+ assistant .get_llm ()
311+
312+ mock_chat_openai .assert_called_once_with (
313+ model = "gpt-test" ,
314+ temperature = custom_temperature ,
315+ model_kwargs = {},
316+ )
317+ AIAssistant .clear_cls_registry ()
318+
319+
320+ @patch ("django_ai_assistant.helpers.assistants.ChatOpenAI" )
321+ def test_AIAssistant_get_llm_override_get_temperature (mock_chat_openai ):
322+ custom_temperature = 0.5
323+
324+ class OverrideGetTempAssistant (AIAssistant ):
325+ id = "override_temp_assistant" # noqa: A003
326+ name = "Override Temp Assistant"
327+ instructions = "Instructions"
328+ model = "gpt-test"
329+
330+ def get_temperature (self ) -> float | None :
331+ return custom_temperature
332+
333+ assistant = OverrideGetTempAssistant ()
334+ assistant .get_llm ()
335+
336+ mock_chat_openai .assert_called_once_with (
337+ model = "gpt-test" ,
338+ temperature = custom_temperature ,
339+ model_kwargs = {},
340+ )
341+ AIAssistant .clear_cls_registry ()
342+
343+
344+ @patch ("django_ai_assistant.helpers.assistants.ChatOpenAI" )
345+ def test_AIAssistant_get_llm_none_temperature (mock_chat_openai ):
346+ class NoneTempAssistant (AIAssistant ):
347+ id = "none_temp_assistant" # noqa: A003
348+ name = "None Temp Assistant"
349+ instructions = "Instructions"
350+ model = "gpt-test"
351+
352+ def get_temperature (self ) -> float | None :
353+ return None
354+
355+ assistant = NoneTempAssistant ()
356+ assistant .get_llm ()
357+
358+ mock_chat_openai .assert_called_once_with (
359+ model = "gpt-test" ,
360+ model_kwargs = {},
361+ )
362+ _ , call_kwargs = mock_chat_openai .call_args
363+ assert "temperature" not in call_kwargs
364+
365+ AIAssistant .clear_cls_registry () # Clean up registry
366+
367+
276368@pytest .mark .vcr
277369def test_AIAssistant_pydantic_structured_output ():
278370 from pydantic import BaseModel
0 commit comments