fix (templates): ai-search OK.

This commit is contained in:
Rodrigo Rodriguez 2024-09-17 19:27:06 -03:00
parent 8f00b4648b
commit be53fd2200
4 changed files with 75 additions and 57 deletions

View file

@ -11,7 +11,6 @@ const conversationsCleanupInterval = 10000;
const conversations: { [key: string]: IConversation } = {};
const botDataStore: { [key: string]: IBotData } = {};
export const getRouter = (
serviceUrl: string,
botUrl: string,
@ -46,9 +45,7 @@ export const getRouter = (
};
console.log('Created conversation with conversationId: ' + conversationId);
const activity = createConversationUpdateActivity
(serviceUrl, conversationId
);
const activity = createConversationUpdateActivity(serviceUrl, conversationId);
fetch(botUrl, {
method: 'POST',
body: JSON.stringify(activity),
@ -80,11 +77,11 @@ export const getRouter = (
console.warn('/v3/directline/conversations/:conversationId not implemented');
};
router.get('/v3/directline/conversations/:conversationId',req3);
router.get(`/directline/${botId}/conversations/:conversationId`,req3);
router.get('/v3/directline/conversations/:conversationId', req3);
router.get(`/directline/${botId}/conversations/:conversationId`, req3);
// Gets activities from store (local history array for now)
const req45= (req, res) => {
const req45 = (req, res) => {
const watermark = req.query.watermark && req.query.watermark !== 'null' ? Number(req.query.watermark) : 0;
const conversation = getConversation(req.params.conversationId, conversationInitRequired);
@ -107,10 +104,9 @@ export const getRouter = (
// Conversation was never initialized
res.status(400).send();
}
}
};
const req34 = (req, res) => {
const req34 = (req, res) => {
const watermark = req.query.watermark && req.query.watermark !== 'null' ? Number(req.query.watermark) : 0;
const conversation = getConversation(req.params.conversationId, conversationInitRequired);
@ -133,18 +129,17 @@ const req34 = (req, res) => {
// Conversation was never initialized
res.status(400).send();
}
};
};
router.get(`/directline/${botId}/conversations/:conversationId/activities`, req34);
router.get(`/api/messages/${botId}/v3/directline/conversations/:conversationId/activities`, req34);
// Sends message to bot. Assumes message activities
const res2= (req, res) => {
const res2 = (req, res) => {
const incomingActivity = req.body;
// Make copy of activity. Add required fields
const activity = createMessageActivity(incomingActivity, serviceUrl, req.params.conversationId,
req.params['pid']);
const activity = createMessageActivity(incomingActivity, serviceUrl, req.params.conversationId, req.params['pid']);
const conversation = getConversation(req.params.conversationId, conversationInitRequired);
@ -354,7 +349,8 @@ const deleteStateForUser = (req: express.Request, res: express.Response) => {
const createMessageActivity = (
incomingActivity: IMessageActivity,
serviceUrl: string,
conversationId: string, pid
conversationId: string,
pid
): IMessageActivity => {
const obj = {
...incomingActivity,
@ -375,7 +371,7 @@ const createConversationUpdateActivity = (serviceUrl: string, conversationId: st
id: uuidv4.v4(),
membersAdded: [],
membersRemoved: [],
from: {id: "bot", name: "bot"}
from: { id: 'bot', name: 'bot' }
};
return activity;
@ -397,6 +393,3 @@ const conversationsCleanup = () => {
});
}, conversationsCleanupInterval);
};

View file

@ -50,10 +50,11 @@ class RenderItem extends Component {
<div className="gb-video-player-wrapper">
{this.props.list.map(item => (
<iframe
key={item.url}
title="Video"
ref="video"
className="gb-video-react-player"
src={item.url}
src={`${item.url}?t=${Date.now()}`}
width="100%"
height="100%"
/>

View file

@ -134,6 +134,7 @@ export class GBLLMOutputParser extends BaseLLMOutputParser<ExpectedOutput> {
let res;
try {
GBLogEx.info(this.min, result);
result = result.replace(/\u000A/g, '\\n');
result = result.replace(/\\n/g, '');
result = result.replace(/\`\`\`/g, '');
res = JSON.parse(result);
@ -158,7 +159,7 @@ export class GBLLMOutputParser extends BaseLLMOutputParser<ExpectedOutput> {
}
}
if (found) {
if (!found) {
GBLogEx.info(this.min, `File not found referenced in other .pdf: ${source.file}`);
}
});
@ -226,7 +227,9 @@ export class ChatServices {
page ? page : 'entire document'
}
(you will fill the JSON sources collection field later),
memorize this block among document information and return when you are refering this part of content:\n\n\n\n ${
never use Index or Summary pages to answer, just content. And
memorize this block among document information and return when you
are refering this part of content:\n\n\n\n ${
doc.pageContent
} \n\n\n\n.`;
}
@ -410,17 +413,38 @@ export class ChatServices {
Folowing answer:`)
] as any);
const jsonInformation = `VERY IMPORTANT: ALWAYS return VALID standard JSON with the folowing structure: 'text' as answer,
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 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 RFC 8259 JSON. all fields are required: text, file, page.
`;
const jsonInformation = `
CRITICAL INSTRUCTION: You MUST ALWAYS return ONLY a valid JSON object matching this exact structure, with no additional text before or after:
{{
"text": "Your answer goes here, providing a thorough response using information from multiple source documents.",
"sources": [
{{
"file": "document1.pdf",
"page": 5
}},
{{
"file": "document2.pdf",
"page": 12
}}
// Add more source objects as needed
]
}}
Note: The example shows two source documents for illustration. You may include any number of source documents in the "sources" array as needed. Ensure each source has both "file" and "page" fields. The "page" values should refer to actual content pages, not index or summary pages.
Requirements:
- The JSON must be valid according to RFC 8259 and parseable without errors
- The "text" field must contain your full response
- Never say that a person needs to go a part of the document, instead look for the page content and answer the question.
- The "sources" array must list the source documents used, with each source having "file" and "page" fields
- Ensure the "page" numbers refer to real pages of content, not index or summary pages
- Do not include any text, markdown, or other content outside the JSON object
- Double check that your response contains ONLY the JSON object before returning
Failure to follow these requirements exactly will result in an error.`;
const combineDocumentsPrompt = ChatPromptTemplate.fromMessages([
AIMessagePromptTemplate.fromTemplate(