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

fix(langchain): structured output response parsing #2214

Merged
merged 7 commits into from
Oct 28, 2024

Conversation

galkleinman
Copy link
Contributor

No description provided.

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working python Pull requests that update Python code labels Oct 27, 2024
Copy link
Member

@nirga nirga left a comment

Choose a reason for hiding this comment

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

Cool, though I'm not sure how it fixes structured outputs - it seems like you're fixing tool calling and not structured outputs - unless I'm missing something?

Also, I'd add tests for this

if dataclasses.is_dataclass(o):
return dataclasses.asdict(o)

if hasattr(o, "to_json"):
return o.to_json()

# check if o is a pydantic model
Copy link
Member

Choose a reason for hiding this comment

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

pydantic should be handled with the to_json, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

depends on the version. in pydantic v1 (which is apparently installed in my env) it won't.. they method was throwing an exception which was caught by the @dont_throw decorator, took me a while to find it.

@@ -585,7 +593,7 @@ def on_llm_end(
)

_set_chat_response(span, response)
span.end()
self._end_span(span, run_id)
Copy link
Member

Choose a reason for hiding this comment

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

you're right - but it won't change anything since an LLM span is a leaf span anyway

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 27, 2024
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Oct 28, 2024
@galkleinman galkleinman merged commit ca3b6f7 into main Oct 28, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lgtm This PR has been approved by a maintainer python Pull requests that update Python code size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants