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

core: basemessage.text() #29078

Merged
merged 8 commits into from
Feb 19, 2025
Merged

core: basemessage.text() #29078

merged 8 commits into from
Feb 19, 2025

Conversation

efriis
Copy link
Contributor

@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 Feb 18, 2025 7:48pm

@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

@efriis efriis changed the title rfc core: basemessage.text core: basemessage.text Feb 7, 2025
@efriis efriis changed the title core: basemessage.text core: basemessage.text() Feb 7, 2025
@efriis efriis marked this pull request as ready for review February 7, 2025 21:06
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Feb 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.

Would be good to document a streaming example, e.g.,

for chunk in llm.stream(...):
    print(chunk.text(), end="|")

Should target being able to replace this page: https://python.langchain.com/docs/how_to/output_parser_string/

@dosubot dosubot bot added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Feb 7, 2025
@efriis efriis merged commit 6c1e21d into master Feb 19, 2025
153 checks passed
@efriis efriis deleted the erick/core-basemessage-text branch February 19, 2025 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ɑ: core Related to langchain-core lgtm PR looks good. Use to confirm that a PR is ready for merging. size:M This PR changes 30-99 lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants