-
Notifications
You must be signed in to change notification settings - Fork 41
DEV: Use structured responses for summaries #1252
Conversation
87f39d7 to
78198b6
Compare
keegangeorge
left a comment
There was a problem hiding this 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
assets/javascripts/discourse/components/modal/ai-persona-response-format-editor.gjs
Outdated
Show resolved
Hide resolved
c364743 to
0c23be8
Compare
| response_format: schema, | ||
| ) { |partial, cancel| result << partial } | ||
|
|
||
| expect(result).to eq("\"key\":\"Hello!\"}") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
ddbba21 to
2ad1d65
Compare
4db7773 to
4c9e080
Compare
System personas:
Regular personas:
Schema editor: