fix (templates): ai-search OK.
This commit is contained in:
parent
6cdce1b9ee
commit
393c73c217
3 changed files with 23 additions and 10 deletions
|
@ -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.
|
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.",
|
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}}],
|
"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
|
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
|
and check if the answer can be extended by using additional contexts in
|
||||||
other files, as specified before.
|
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([
|
const combineDocumentsPrompt = ChatPromptTemplate.fromMessages([
|
||||||
|
|
19
src/util.ts
19
src/util.ts
|
@ -120,19 +120,32 @@ export class GBUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static caseInsensitive(listOrRow) {
|
public static caseInsensitive(listOrRow) {
|
||||||
|
// If the input is not an object or array, return it as is
|
||||||
if (!listOrRow || typeof listOrRow !== 'object') {
|
if (!listOrRow || typeof listOrRow !== 'object') {
|
||||||
return listOrRow;
|
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 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 = {
|
const caseInsensitiveGetHandler = {
|
||||||
get: (target, property) => propertiesMap.get(lowercase(property))
|
get: (target, property) => propertiesMap.get(lowercase(property))
|
||||||
};
|
};
|
||||||
|
|
||||||
return new Proxy(obj, caseInsensitiveGetHandler);
|
return new Proxy(obj, caseInsensitiveGetHandler);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Handle arrays by mapping each element to a case-insensitive proxy
|
||||||
if (Array.isArray(listOrRow)) {
|
if (Array.isArray(listOrRow)) {
|
||||||
return listOrRow.map(row => createCaseInsensitiveProxy(row));
|
return listOrRow.map(row =>
|
||||||
|
typeof row === 'object' && row !== null ? createCaseInsensitiveProxy(row) : row
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return createCaseInsensitiveProxy(listOrRow);
|
return createCaseInsensitiveProxy(listOrRow);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
name,value
|
name,value
|
||||||
Answer Mode,sql
|
Answer Mode,sql
|
||||||
llm File,northwind.db
|
llm File,northwind.db
|
||||||
llm Driver,sqlite
|
llm Driver,sqlite
|
|
Loading…
Add table
Reference in a new issue