utils.py — langchain Source File
Architecture documentation for utils.py, a python file in the langchain codebase. 1 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 06fe6c27_960b_fecf_7deb_1961a00fab82["utils.py"] 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] 06fe6c27_960b_fecf_7deb_1961a00fab82 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 style 06fe6c27_960b_fecf_7deb_1961a00fab82 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from typing import Any
def _resolve_schema_references(schema: Any, definitions: dict[str, Any]) -> Any:
"""Resolve the $ref keys in a JSON schema object using the provided definitions."""
if isinstance(schema, list):
for i, item in enumerate(schema):
schema[i] = _resolve_schema_references(item, definitions)
elif isinstance(schema, dict):
if "$ref" in schema:
ref_key = schema.pop("$ref").split("/")[-1]
ref = definitions.get(ref_key, {})
schema.update(ref)
else:
for key, value in schema.items():
schema[key] = _resolve_schema_references(value, definitions)
return schema
def _convert_schema(schema: dict) -> dict:
props = {k: {"title": k, **v} for k, v in schema["properties"].items()}
return {
"type": "object",
"properties": props,
"required": schema.get("required", []),
}
def get_llm_kwargs(function: dict) -> dict:
"""Return the kwargs for the LLMChain constructor.
Args:
function: The function to use.
Returns:
The kwargs for the LLMChain constructor.
"""
return {"functions": [function], "function_call": {"name": function["name"]}}
Domain
Subdomains
Dependencies
- typing
Source
Frequently Asked Questions
What does utils.py do?
utils.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in utils.py?
utils.py defines 3 function(s): _convert_schema, _resolve_schema_references, get_llm_kwargs.
What does utils.py depend on?
utils.py imports 1 module(s): typing.
Where is utils.py in the architecture?
utils.py is located at libs/langchain/langchain_classic/chains/openai_functions/utils.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/langchain/langchain_classic/chains/openai_functions).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free