Skip to content

Commit cccc225

Browse files
Truncate citation content in kenel function and restrict cosmos call for errored response
1 parent b75d196 commit cccc225

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/App/src/components/Chat/Chat.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,9 @@ const Chat: React.FC<ChatProps> = ({
642642
];
643643
}
644644
}
645-
saveToDB(updatedMessages, conversationId, isChatReq);
645+
if (!updatedMessages.find((msg: any) => msg.role=== "error")) {
646+
saveToDB(updatedMessages, conversationId, isChatReq);
647+
}
646648
} catch (e) {
647649
console.log("Catched with an error while chat and save", e);
648650
if (abortController.signal.aborted) {

src/api/plugins/chat_with_data_plugin.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from semantic_kernel.functions.kernel_function_decorator import kernel_function
55
from azure.identity import DefaultAzureCredential
66
from azure.ai.projects import AIProjectClient
7+
import copy
78

89
from common.config.config import Config
910
from common.database.sqldb_service import execute_sql_query
@@ -197,7 +198,13 @@ def get_answers_from_calltranscripts(
197198
]
198199
}
199200
)
200-
answer = completion.choices[0]
201+
answer = copy.deepcopy(completion.choices[0])
202+
203+
# Limit the content inside citations to 300 characters to minimize load
204+
if 'citations' in answer.message.context:
205+
for citation in answer.message.context['citations']:
206+
if 'content' in citation:
207+
citation['content'] = citation['content'][:300] + '...' if len(citation['content']) > 300 else citation['content']
201208
except BaseException:
202209
answer = 'Details could not be retrieved. Please try again later.'
203210
return answer

0 commit comments

Comments
 (0)