It appears the `prefix` property is ignored when a `responseConstraint` is also specified.
My understanding is that in the example below, it should always return a rating of 2. However, it does not.
I guess allowing both `prefix` and `responseConstraint` would allow you to construct impossible to complete scenarios where the prefix is simply incompatible with what the responseConstraint expects? Maybe in scenarios like that, an error could be thrown.
Example:
const session = await LanguageModel.create();
const schema = {
type: "object",
required: ["rating"],
additionalProperties: false,
properties: {
rating: {
type: "number",
minimum: 0,
maximum: 5,
},
},
};
// Prompt the model and wait for the JSON response to come back.
const result = await session.prompt([{
role: "user",
content: "Summarize this feedback into a rating between 0-5: The food was delicious, service was excellent, will recommend."
},
{
role: "assistant",
content: '{"rating":2',
prefix: true
}],
{ responseConstraint: schema }
);
console.log(result);