validate_environment() — langchain Function Reference
Architecture documentation for the validate_environment() function in chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD e5c4ac2b_e4b3_b591_64b1_79a0ce4eaa10["validate_environment()"] d5ca3c3a_3c29_0cb2_a156_35c92a31f5fd["ChatGroq"] e5c4ac2b_e4b3_b591_64b1_79a0ce4eaa10 -->|defined in| d5ca3c3a_3c29_0cb2_a156_35c92a31f5fd style e5c4ac2b_e4b3_b591_64b1_79a0ce4eaa10 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/groq/langchain_groq/chat_models.py lines 489–534
def validate_environment(self) -> Self:
"""Validate that api key and python package exists in environment."""
if self.n < 1:
msg = "n must be at least 1."
raise ValueError(msg)
if self.n > 1 and self.streaming:
msg = "n must be 1 when streaming."
raise ValueError(msg)
if self.temperature == 0:
self.temperature = 1e-8
default_headers = {"User-Agent": f"langchain/{__version__}"} | dict(
self.default_headers or {}
)
client_params: dict[str, Any] = {
"api_key": (
self.groq_api_key.get_secret_value() if self.groq_api_key else None
),
"base_url": self.groq_api_base,
"timeout": self.request_timeout,
"max_retries": self.max_retries,
"default_headers": default_headers,
"default_query": self.default_query,
}
try:
import groq # noqa: PLC0415
sync_specific: dict[str, Any] = {"http_client": self.http_client}
if not self.client:
self.client = groq.Groq(
**client_params, **sync_specific
).chat.completions
if not self.async_client:
async_specific: dict[str, Any] = {"http_client": self.http_async_client}
self.async_client = groq.AsyncGroq(
**client_params, **async_specific
).chat.completions
except ImportError as exc:
msg = (
"Could not import groq python package. "
"Please install it with `pip install groq`."
)
raise ImportError(msg) from exc
return self
Domain
Subdomains
Source
Frequently Asked Questions
What does validate_environment() do?
validate_environment() is a function in the langchain codebase, defined in libs/partners/groq/langchain_groq/chat_models.py.
Where is validate_environment() defined?
validate_environment() is defined in libs/partners/groq/langchain_groq/chat_models.py at line 489.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free