Skip to content

Commit

Permalink
added back search filtering, removed session clearance on server restart
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurvir committed Apr 19, 2024
1 parent 1cdff7b commit 5359cde
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
6 changes: 0 additions & 6 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down
4 changes: 2 additions & 2 deletions services/AI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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...");


Expand All @@ -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),
});

Expand Down
13 changes: 13 additions & 0 deletions services/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5359cde

Please sign in to comment.