MCPcopy
hub / github.com/langchain-ai/langchain / _load_template

Function _load_template

libs/core/langchain_core/prompts/loading.py:33–52  ·  view source on GitHub ↗

Load template from the path if applicable.

(var_name: str, config: dict)

Source from the content-addressed store, hash-verified

31
32
33def _load_template(var_name: str, config: dict) -> dict:
34 """Load template from the path if applicable."""
35 # Check if template_path exists in config.
36 if f"{var_name}_path" in config:
37 # If it does, make sure template variable doesn't also exist.
38 if var_name in config:
39 raise ValueError(
40 f"Both `{var_name}_path` and `{var_name}` cannot be provided."
41 )
42 # Pop the template path from the config.
43 template_path = Path(config.pop(f"{var_name}_path"))
44 # Load the template.
45 if template_path.suffix == ".txt":
46 with open(template_path) as f:
47 template = f.read()
48 else:
49 raise ValueError
50 # Set the template variable to the extracted variable.
51 config[var_name] = template
52 return config
53
54
55def _load_examples(config: dict) -> dict:

Callers 2

_load_few_shot_promptFunction · 0.85
_load_promptFunction · 0.85

Calls 2

popMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected