Skip to content
代码片段 群组 项目
提交 a85b86de 编辑于 作者: Denys Mishunov's avatar Denys Mishunov
浏览文件

Merge branch 'remove-sources-from-content-field-part-2' into 'master'

Cleanup JSON parsing for TanukiBot responses

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/131294



Merged-by: default avatarDenys Mishunov <dmishunov@gitlab.com>
Approved-by: default avatarDenys Mishunov <dmishunov@gitlab.com>
Reviewed-by: default avatarDenys Mishunov <dmishunov@gitlab.com>
Co-authored-by: default avatarPavel Shutsin <pshutsin@gitlab.com>
无相关合并请求
......@@ -9,31 +9,12 @@ const proxyMessageContent = (message, propsToUpdate) => {
};
};
const parseRawContent = (msgContent) => {
try {
const parsedContent = JSON.parse(msgContent);
// JSON.parse does not throw when parsing Strings that are coerced to primary data types, like Number or Boolean.
// JSON.parse("1") would return 1 (Number), same as JSON.parse("false"), which returns false (Boolean).
// We therefore check if the parsed response is really an Object.
// This will be solved with https://gitlab.com/gitlab-org/gitlab/-/issues/423315 when we no longer receive
// potential JSON as a string.
if (typeof parsedContent === 'object') {
return parsedContent.content;
}
} catch {
// no-op
}
return msgContent;
};
export const addDuoChatMessage = async ({ commit }, messageData = { content: '' }) => {
const { errors = [], content = '' } = messageData || {};
const msgContent = content || errors.join('; ');
if (msgContent) {
const parsedContent = parseRawContent(msgContent);
const message = proxyMessageContent(messageData, { content: parsedContent });
const message = proxyMessageContent(messageData, { content: msgContent });
if (message.role.toLowerCase() === GENIE_CHAT_MODEL_ROLES.system) {
commit(types.ADD_TOOL_MESSAGE, message);
......
......@@ -24,11 +24,7 @@ describe('TanukiBot Store Actions', () => {
const aiContentResponse = {
content,
};
const oldDocumentationResponse = {
content: JSON.stringify({ content, sources: extras.sources }),
extras,
};
const newDocumentationResponse = {
const documentationResponse = {
content,
extras,
};
......@@ -37,8 +33,7 @@ describe('TanukiBot Store Actions', () => {
messageData | expectedPayload
${aiContentResponse} | ${{ content, role: GENIE_CHAT_MODEL_ROLES.user }}
${{ ...aiContentResponse, role: GENIE_CHAT_MODEL_ROLES.assistant }} | ${{ content, role: GENIE_CHAT_MODEL_ROLES.assistant }}
${oldDocumentationResponse} | ${{ content, extras, role: GENIE_CHAT_MODEL_ROLES.user }}
${newDocumentationResponse} | ${{ content, extras, role: GENIE_CHAT_MODEL_ROLES.user }}
${documentationResponse} | ${{ content, extras, role: GENIE_CHAT_MODEL_ROLES.user }}
`(
'should commit the correct mutations for "$messageData" response',
({ messageData, expectedPayload }) => {
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册