-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Labels
area-aiplatform/iosplatform/macosmacOS / Mac CatalystmacOS / Mac Catalysts/triagedIssue has been reviewedIssue has been reviewed
Description
Description
When using streaming responses in the Foundation Models, the response is actually a JSON object. We then have to serialize the response.
This means that responses are not sequential. The serialization process may reorder members. And the json is laways a complete JSON.
For example, if the model response is:
{"product":".NET MAUI","rating":5,"description":"This is the best things since sliThe Foundation Model response is a complete JSON object. This means that in order for us to return as a string, we have to serialize:
{"product":".NET MAUI","rating":5,"description":"This is the best things since sli"}However, serialization is not deterministic and property order could change:
{"description":"This is the best things since sli","rating":5,"product":".NET MAUI"}Workaround
For now, I am just adding a user message at the end that does this:
actualMessages.Add(new ChatMessage(ChatRole.User,
$"""
Please format your response as a JSON object according to the specified schema.
Ensure that the JSON is well-formed and complete.
IMPORTANT: DO NOT wrap with triple backticks! ONLY return the JSON object!
{json.Schema}
"""));Metadata
Metadata
Assignees
Labels
area-aiplatform/iosplatform/macosmacOS / Mac CatalystmacOS / Mac Catalysts/triagedIssue has been reviewedIssue has been reviewed