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

nested POJO extract #575

Merged
merged 15 commits into from Feb 8, 2024
Merged

Conversation

tenpigs267
Copy link
Contributor

This PR enhance ServiceOutPutParser allowing outputFormatInstructions to document nested objects in jsonStructure.

Integration tests have been modified to add a nested address object. Maybe a dedicated test would be better?

Copy link

@mike-adonis mike-adonis 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.

@tenpigs267
Copy link
Contributor Author

I didn't seen there was already a PR (#513) for nested objects.
I think this version is simpler.

@tenpigs267 tenpigs267 marked this pull request as draft February 4, 2024 13:11
@tenpigs267 tenpigs267 marked this pull request as ready for review February 5, 2024 08:21
Copy link
Owner

@langchain4j langchain4j left a comment

Choose a reason for hiding this comment

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

@tenpigs267 great job, thank you!

@langchain4j langchain4j merged commit 4d3e622 into langchain4j:main Feb 8, 2024
6 checks passed
if (name.equals("__$hits$__")) {
if (name.equals("__$hits$__")
|| java.lang.reflect.Modifier.isStatic(field.getModifiers())
|| java.lang.reflect.Modifier.isFinal(field.getModifiers())) {
Copy link
Contributor

@geoand geoand Feb 9, 2024

Choose a reason for hiding this comment

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

Unfortunately this line is severely breaking.

Consider ServiceOutputParserTest.Person: By simply making is class immutable (and adding a constructor so JSON deserialization works), outputFormatInstructions will not return {\n}.
Furthermore, the same problem occurs for Java Records.

I am not sure what the motivation for this line was, but I propose at the very least, it should be removed.

Copy link
Owner

Choose a reason for hiding this comment

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

@geoand thanks for the heads up! Does it break Quarkus extension?

Copy link
Owner

Choose a reason for hiding this comment

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

@tenpigs267 BTW it also does not work if you have a recursion. So if I define it like this:

class Person {

            private String firstName;
            private String lastName;
            private LocalDate birthDate;
            private List<Person> parents;

It will go into endless recursion.

Copy link
Contributor

Choose a reason for hiding this comment

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

@geoand thanks for the heads up! Does it break Quarkus extension?

It breaks some of our tests that use Java Records

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks @langchain4j for #620 and sry for that.
For the recursive thing I'am going to add a PR with the code going through all involved classes and generating a list a class (and test it with openAI)

langchain4j added a commit that referenced this pull request Feb 9, 2024
tenpigs267 added a commit to tenpigs267/langchain4j that referenced this pull request Feb 9, 2024
langchain4j pushed a commit that referenced this pull request Feb 29, 2024
Following #575, here is a PR which add a set of visited classes sot that
each class structure is defined only once (only when it is the root
element class that is re-used, it is then defined a second time (see
outputFormatInstructions_PersonWithParents unit test for a
comprehensible example)
Approch I suggested on #575 seemed less natural (navigate through
classes first and then generate classes structure)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants