fix (templates): ai-search OK.

This commit is contained in:
Rodrigo Rodriguez 2024-09-11 18:39:37 -03:00
parent 6cdce1b9ee
commit 393c73c217
3 changed files with 23 additions and 10 deletions

View file

@ -414,12 +414,12 @@ export class ChatServices {
sources as an array of ('file' indicating the PDF filename and 'page' indicating the page number) listing all segmented context.
Example JSON format: "text": "this is the answer, anything LLM output as text answer shoud be here.",
"sources": [{{"file": "filename.pdf", "page": 3}}, {{"file": "filename2.pdf", "page": 1}}],
return valid JSON with brackets. Avoid explaining the context directly
return *valid READY TO BE PARSED JSON* with brackets. Avoid explaining the context directly
to the Human; instead, refer to the document source, always return more than one source document
and check if the answer can be extended by using additional contexts in
other files, as specified before.
Double check if the output is a valid JSON with brackets. all fields are required: text, file, page.
Double check if the output is a valid RFC 8259 JSON. all fields are required: text, file, page.
`;
const combineDocumentsPrompt = ChatPromptTemplate.fromMessages([

View file

@ -120,24 +120,37 @@ export class GBUtil {
}
public static caseInsensitive(listOrRow) {
// If the input is not an object or array, return it as is
if (!listOrRow || typeof listOrRow !== 'object') {
return listOrRow;
}
const lowercase = oldKey => (typeof oldKey === 'string' ? oldKey.toLowerCase() : oldKey);
// Helper function to convert property names to lowercase
const lowercase = key => typeof key === 'string' ? key.toLowerCase() : key;
// Create a proxy that maps property accesses to lowercase property names
const createCaseInsensitiveProxy = obj => {
const propertiesMap = new Map(Object.keys(obj).map(propKey => [lowercase(propKey), obj[propKey]]));
const propertiesMap = new Map(
Object.keys(obj).map(propKey => [lowercase(propKey), obj[propKey]])
);
const caseInsensitiveGetHandler = {
get: (target, property) => propertiesMap.get(lowercase(property))
};
return new Proxy(obj, caseInsensitiveGetHandler);
};
// Handle arrays by mapping each element to a case-insensitive proxy
if (Array.isArray(listOrRow)) {
return listOrRow.map(row => createCaseInsensitiveProxy(row));
return listOrRow.map(row =>
typeof row === 'object' && row !== null ? createCaseInsensitiveProxy(row) : row
);
} else {
return createCaseInsensitiveProxy(listOrRow);
}
}
public static async exists(filePath: string): Promise<boolean> {
try {
await fs.access(filePath);

View file

@ -1,4 +1,4 @@
name,value
Answer Mode,sql
llm File,northwind.db
llm Driver,sqlite
name,value
Answer Mode,sql
llm File,northwind.db
llm Driver,sqlite
1 name value
2 Answer Mode sql
3 llm File northwind.db
4 llm Driver sqlite