in excel-addin/src/taskpane/taskpane.js [268:301]
async function suggest_completions({topic, fields, completions=[], partial=[], side_info=[], temperature=0.0}) {
const query_obj = _build_completion_query_context_string({topic: topic, fields: fields, completions: completions, partial: partial, side_info: side_info});
const context_string = query_obj["context_string"];
const existing_completions = query_obj["existing_completions"];
const response_json = await cached_request({context_string: context_string + existing_completions, logprobs: 0, length: 100, temperature: temperature});
// TODO could use logits here to produce hybrid answers
const text_offsets = response_json['data'][0]['text_offset'];
const texts = response_json['data'][0]['text'];
// first index after context
var start_idx = text_offsets.indexOf(context_string.length + 1); // always ends on a |
var parsed_results = new Array();
while (true) {
var next_line_obj = _advance_line(start_idx, texts)
var result = next_line_obj['result'];
var next_idx = next_line_obj['next_idx'];
if (next_idx == -1) {
break;
}
// hack: sometimes we get empty completions :(
if (result.length && result != ['']) {
parsed_results.push(result);
}
start_idx = next_idx + 2 // skipping newline and starting cell separator
}
// parse the last partial line
var last_line_tokens = texts.slice(start_idx);
if (last_line_tokens.length && last_line_tokens[last_line_tokens.length - 1] == ' |') {
last_line_tokens = last_line_tokens.slice(0, last_line_tokens.length - 1);
}
var last_partial = _strip(last_line_tokens.join("")).split(CELL_SEPARATOR);
return {result: parsed_results, partial: last_partial.filter(x => !!(x))};
}