-
Notifications
You must be signed in to change notification settings - Fork 31
DEV: Use structured responses for summaries #1252
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
base: main
Are you sure you want to change the base?
Conversation
87f39d7
to
78198b6
Compare
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
4bc599a
to
c364743
Compare
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
.
System personas:
Regular personas:
Schema editor: