diff --git a/server.js b/server.js index eb07a8b..5a09416 100644 --- a/server.js +++ b/server.js @@ -37,12 +37,6 @@ app.post('/update-status', updateStatus) app.post('/unpublish-item', unpublishItem) app.post('/webhook-ps', webhookControl) -// Reset all sessions -export const db = new DBService() - -await db.clear_all_sessions() - - // Start the Express server app.listen(process.env.SERVER_PORT, () => { logger.info(`Server is running on port ${process.env.SERVER_PORT}`) diff --git a/services/AI.js b/services/AI.js index b6018a8..0413a17 100644 --- a/services/AI.js +++ b/services/AI.js @@ -76,7 +76,7 @@ class AI { // check for tool calls const toolCalls = responseMessage.tool_calls; - if (toolCalls) { + if (toolCalls && toolCalls.length > 0) { logger.info("Tool calls found in response, proceeding..."); @@ -92,7 +92,7 @@ class AI { messages.push({ tool_call_id: tool.id, role: "tool", - name: functionToCall, + name: tool.function.name, content: JSON.stringify(response), }); diff --git a/services/Actions.js b/services/Actions.js index 5c287c1..576c517 100644 --- a/services/Actions.js +++ b/services/Actions.js @@ -34,6 +34,19 @@ class Actions { try { let response = await axios(request) + // optimise search results. + // This code will ensure that for search resylts, only the responses with catalog providers are returned and out of them we only take the first resopnse to further reduce the token size. + // This should be imlemented by different baps based on their requirements. + if(request.data.context && request.data.context.action==='search'){ + response.data.responses = response.data.responses.filter(res => res.message && res.message.catalog && res.message.catalog.providers && res.message.catalog.providers.length > 0) + if(response.data.responses.length > 0) { + response.data.responses = response.data.responses.slice(0, 1); + if(response?.data?.responses[0].message?.catalog?.providers){ + response.data.responses[0].message.catalog.providers = response.data.responses[0].message.catalog.providers.slice(0, 3); + } + } + + } responseObject = { status: true, data: response.data,