_call() — langchain Function Reference
Architecture documentation for the _call() function in llms.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD e1e4f815_3e2a_75f8_675e_9a5e7f0f868a["_call()"] c95a497f_938f_2be9_842e_087a0766cf00["AnthropicLLM"] e1e4f815_3e2a_75f8_675e_9a5e7f0f868a -->|defined in| c95a497f_938f_2be9_842e_087a0766cf00 cb1cae7d_4a5d_cfbf_994a_88075fe175e2["_stream()"] e1e4f815_3e2a_75f8_675e_9a5e7f0f868a -->|calls| cb1cae7d_4a5d_cfbf_994a_88075fe175e2 5b0cfa0b_130d_960a_411e_cc97a2c28a93["_get_anthropic_stop()"] e1e4f815_3e2a_75f8_675e_9a5e7f0f868a -->|calls| 5b0cfa0b_130d_960a_411e_cc97a2c28a93 04edfbcc_f913_d95a_6261_c2a81f9f570e["_format_messages()"] e1e4f815_3e2a_75f8_675e_9a5e7f0f868a -->|calls| 04edfbcc_f913_d95a_6261_c2a81f9f570e style e1e4f815_3e2a_75f8_675e_9a5e7f0f868a fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/anthropic/langchain_anthropic/llms.py lines 249–296
def _call(
self,
prompt: str,
stop: list[str] | None = None,
run_manager: CallbackManagerForLLMRun | None = None,
**kwargs: Any,
) -> str:
r"""Call out to Anthropic's completion endpoint.
Args:
prompt: The prompt to pass into the model.
stop: Optional list of stop words to use when generating.
run_manager: Optional callback manager for LLM run.
kwargs: Additional keyword arguments to pass to the model.
Returns:
The string generated by the model.
Example:
```python
prompt = "What are the biggest risks facing humanity?"
prompt = f"\n\nHuman: {prompt}\n\nAssistant:"
response = model.invoke(prompt)
```
"""
if self.streaming:
completion = ""
for chunk in self._stream(
prompt=prompt,
stop=stop,
run_manager=run_manager,
**kwargs,
):
completion += chunk.text
return completion
stop = self._get_anthropic_stop(stop)
params = {**self._default_params, **kwargs}
# Remove parameters not supported by Messages API
params = {k: v for k, v in params.items() if k != "max_tokens_to_sample"}
response = self.client.messages.create(
messages=self._format_messages(prompt),
stop_sequences=stop if stop else None,
**params,
)
return response.content[0].text
Domain
Subdomains
Source
Frequently Asked Questions
What does _call() do?
_call() is a function in the langchain codebase, defined in libs/partners/anthropic/langchain_anthropic/llms.py.
Where is _call() defined?
_call() is defined in libs/partners/anthropic/langchain_anthropic/llms.py at line 249.
What does _call() call?
_call() calls 3 function(s): _format_messages, _get_anthropic_stop, _stream.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free