Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rfc core: basemessage.text #29078

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft

rfc core: basemessage.text #29078

wants to merge 4 commits into from

Conversation

efriis
Copy link
Member

@efriis efriis commented Jan 7, 2025

No description provided.

Copy link

vercel bot commented Jan 7, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Jan 7, 2025 10:23pm

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jan 7, 2025
@efriis efriis changed the title core: basemessage.text rfc core: basemessage.text Jan 7, 2025
@efriis efriis marked this pull request as draft January 7, 2025 22:17
@dosubot dosubot bot added the Ɑ: core Related to langchain-core label Jan 7, 2025
Copy link
Collaborator

@ccurme ccurme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Nicer than having to use StrOutputParser. For streaming this will work with Anthropic but haven't looked at any other providers.

How it works for StrOutputParser:

if isinstance(self.message.content, str):
text = self.message.content
# HACK: Assumes text in content blocks in OpenAI format.
# Uses first text block.
elif isinstance(self.message.content, list):
for block in self.message.content:
if isinstance(block, str):
text = block
break
elif isinstance(block, dict) and "text" in block:
text = block["text"]
break
else:
pass

@@ -92,6 +92,27 @@ def get_lc_namespace(cls) -> list[str]:
"""
return ["langchain", "schema", "messages"]

def text(self) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be a property?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

originally had it as an @property but thought it might be more forward-compatible with config options we might want to add in the future like custom_separator: str = "" or image_placeholder: str = ""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ɑ: core Related to langchain-core size:S This PR changes 10-29 lines, ignoring generated files.
Projects
Status: Internal
Development

Successfully merging this pull request may close these issues.

3 participants