in excel-addin/src/taskpane/taskpane.js [200:228]
async function suggest_fields({topic, fields=[]}) {
const context_string = _build_field_query_context_string({topic: topic, fields: fields});
const response_json = await cached_request({context_string: context_string, logprobs: 5, length: 48});
const text_offsets = response_json['data'][0]['text_offset'];
const texts = response_json['data'][0]['text'];
const logits = response_json['data'][0]['top_logprobs'];
// first index after context
var context_idx = text_offsets.indexOf(context_string.length);
// newline at end of sampled header
var endheader_idx = texts.indexOf('\n', context_idx);
// pull out the actual fields, the -1 is for the ending |
var sampled_fields = _strip(texts.slice(context_idx, endheader_idx-1).join("")).split(CELL_SEPARATOR);
// # we need to join onto end tokens
if (fields.length && _strip(texts[context_idx-1]) == fields[fields.length-1]) {
sampled_fields = [fields[fields.length-1] + sampled_fields[0], ...sampled_fields.slice(1)];
fields = fields.slice(0, -1);
}
// pull the other possible options for the endheader newline. these should be
// other possible fields, in likelihood order (though it will only be the
// first token)
const sorted_fields = Object.entries(logits[endheader_idx][0]).sort((a, b) => { return b[1] - a[1] });
const extra_fields = sorted_fields.filter(x => x[0] != '\n' && x[0] != ' ').map(x => [_strip(x[0]), x[1]]);
return {fields: [...fields, ...sampled_fields].filter(x => x.length), extra_fields: extra_fields};
//return {fields: [...fields, ...sampled_fields].filter(x => x.length), extra_fields: []};
}