Make ordering of LLM responses consistent w vars dict ordering

This commit is contained in:
Ian Arawjo 2023-11-26 20:59:05 -05:00
parent 687c277a22
commit d00788369c
2 changed files with 15 additions and 2 deletions

View File

@ -718,7 +718,21 @@ export async function queryLLM(id: string,
}
// Convert the responses into a more standardized format with less information
const res = Object.values(responses).flatMap(rs => rs.map(to_standard_format));
let res = Object.values(responses).flatMap(rs => rs.map(to_standard_format));
// Reorder the responses to match the original vars dict ordering of keys and values
res.sort((a, b) => {
if (!a.vars || !b.vars) return 0;
for (const [varname, vals] of Object.entries(vars)) {
if (varname in a.vars && varname in b.vars) {
const a_idx = vals.indexOf(a.vars[varname]);
const b_idx = vals.indexOf(b.vars[varname]);
if (a_idx > -1 && b_idx > -1 && a_idx !== b_idx)
return a_idx - b_idx;
}
}
return 0;
});
// Save the responses *of this run* to the storage cache, for further recall:
let cache_filenames = past_cache_files;

View File

@ -160,7 +160,6 @@ const useStore = create((set, get) => ({
const row_keys = Object.keys(row);
// Check if this is an 'empty' row (with all empty strings); if so, skip it:
console.log(row);
if (row_keys.every(key => key === '__uid' || !row[key] || (typeof row[key] === "string" && row[key].trim() === "")))
return undefined;