set_text() — langchain Function Reference
Architecture documentation for the set_text() function in chat_generation.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 2f40f76f_3158_b30f_1232_ac432f0b8e8f["set_text()"] 2bdc4d81_5592_3e8d_1079_4eb50790f1d0["ChatGeneration"] 2f40f76f_3158_b30f_1232_ac432f0b8e8f -->|defined in| 2bdc4d81_5592_3e8d_1079_4eb50790f1d0 style 2f40f76f_3158_b30f_1232_ac432f0b8e8f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/outputs/chat_generation.py lines 45–73
def set_text(self) -> Self:
"""Set the text attribute to be the contents of the message.
Args:
values: The values of the object.
Returns:
The values of the object with the text attribute set.
Raises:
ValueError: If the message is not a string or a list.
"""
text = ""
if isinstance(self.message.content, str):
text = self.message.content
# Extracts first text block from content blocks.
# Skips blocks with explicit non-text type (e.g., thinking, reasoning).
elif isinstance(self.message.content, list):
for block in self.message.content:
if isinstance(block, str):
text = block
break
if isinstance(block, dict) and "text" in block:
block_type = block.get("type")
if block_type is None or block_type == "text":
text = block["text"]
break
self.text = text
return self
Domain
Subdomains
Source
Frequently Asked Questions
What does set_text() do?
set_text() is a function in the langchain codebase, defined in libs/core/langchain_core/outputs/chat_generation.py.
Where is set_text() defined?
set_text() is defined in libs/core/langchain_core/outputs/chat_generation.py at line 45.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free