Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Conversation

romanrizzi
Copy link
Member

@romanrizzi romanrizzi commented Apr 8, 2025

System personas:

Screenshot 2025-04-14 at 2 38 28 PM

Regular personas:

Screenshot 2025-04-14 at 2 38 46 PM

Schema editor:

Screenshot 2025-04-14 at 2 40 36 PM

@romanrizzi romanrizzi force-pushed the summary_structured_prompt branch 4 times, most recently from 87f39d7 to 78198b6 Compare April 14, 2025 18:42
Copy link
Member

@keegangeorge keegangeorge left a comment

Choose a reason for hiding this comment

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

Two minor suggestions, otherwise LGTM

@romanrizzi romanrizzi force-pushed the summary_structured_prompt branch 4 times, most recently from c364743 to 0c23be8 Compare April 14, 2025 21:17
response_format: schema,
) { |partial, cancel| result << partial }

expect(result).to eq("\"key\":\"Hello!\"}")
Copy link
Member

Choose a reason for hiding this comment

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

this is a bit surprising imo... it should be: {key: "Hello!"} or perhaps a special object that inherits off hash eg: StructuredOutput , then nobody needs to worry about parsing and we can enforce structure at the boundary.

Copy link
Member

@xfalcox xfalcox Apr 15, 2025

Choose a reason for hiding this comment

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

What about we use JSON.parse(result, object_class: OpenStruct) so we always have a proper object to work with?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think that will work. During streaming, we only get chunks of the JSON so we cannot use JSON#parse.

I believe Sam's proposal is to have a class that handles the buffering and parsing while decoding the response. This class reads the chunk, keeps track of which key/value are we at, and updates the state:

Chunk 1: "{\"message\": \"Line 1\\"
Partial: {"message"=>"Line 1"}

Chunk 2: "nLine 2\", \"status\": \"o"
Partial: {"message"=>"Line 1\nLine 2", "status"=>"o"}

Chunk 3: "k\"}"
Partial: {"message"=>"Line 1\nLine 2", "status"=>"ok"}

By taking care of it internally, the burden of doing this doesn't fall on the modules using structured outputs, like in this case, FoldContent.

@romanrizzi romanrizzi force-pushed the summary_structured_prompt branch from ddbba21 to 2ad1d65 Compare May 5, 2025 13:57
@romanrizzi romanrizzi force-pushed the summary_structured_prompt branch from 4db7773 to 4c9e080 Compare May 5, 2025 19:28
@romanrizzi romanrizzi merged commit c0a2d4c into main May 6, 2025
6 checks passed
@romanrizzi romanrizzi deleted the summary_structured_prompt branch May 6, 2025 13:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants