Reputation: 163
What is the default value of the temperature parameter when I create an instance of ChatOpenAI
in Langchain?
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-4o")
print(llm.temperature) # it is None!
llm=ChatOpenAI(model="gpt-4o", temperature=0.1)
print(llm.temperature) # it is 0.1
when I don't explicitly set a value to temperature
it would be None
! so what does it mean? is it Zero or One in this case?
Upvotes: 0
Views: 39
Reputation: 292
The default value of temperature
when creating a ChatOpenAI
instance in LangChain is actually 0.7, not None.
When you see None
printed, it doesn't mean the actual temperature being used is None. What's happening is that LangChain uses a lazy-loading pattern where some parameters are only set when actually needed (typically at request time).
Here's what's going on:
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-4o")
print(llm.temperature) # Prints None, but actual default is 0.7
llm=ChatOpenAI(model="gpt-4o", temperature=0.1)
print(llm.temperature) # Prints 0.1 as expected
You can verify this by checking the source code or by actually making a call with the model and inspecting the request that gets sent to OpenAI.
If you look at the implementation, you'll see that when you don't specify a temperature, it uses a default of 0.7 when making the actual API call - this is consistent with OpenAI's own default.
This is a standard design pattern in many libraries where parameters are only fully initialized at runtime rather than at instantiation time.
Upvotes: 0