mirror of
https://github.com/labring/FastGPT.git
synced 2025-12-25 20:02:47 +00:00
Some checks are pending
Document deploy / sync-images (push) Waiting to run
Document deploy / generate-timestamp (push) Blocked by required conditions
Document deploy / build-images (map[domain:https://fastgpt.cn suffix:cn]) (push) Blocked by required conditions
Document deploy / build-images (map[domain:https://fastgpt.io suffix:io]) (push) Blocked by required conditions
Document deploy / update-images (map[deployment:fastgpt-docs domain:https://fastgpt.cn kube_config:KUBE_CONFIG_CN suffix:cn]) (push) Blocked by required conditions
Document deploy / update-images (map[deployment:fastgpt-docs domain:https://fastgpt.io kube_config:KUBE_CONFIG_IO suffix:io]) (push) Blocked by required conditions
Build FastGPT images in Personal warehouse / get-vars (push) Waiting to run
Build FastGPT images in Personal warehouse / build-fastgpt-images (map[arch:amd64 runs-on:ubuntu-24.04]) (push) Blocked by required conditions
Build FastGPT images in Personal warehouse / build-fastgpt-images (map[arch:arm64 runs-on:ubuntu-24.04-arm]) (push) Blocked by required conditions
Build FastGPT images in Personal warehouse / release-fastgpt-images (push) Blocked by required conditions
* perf: faq * index * delete dataset * delete dataset * perf: delete dataset * init * fix: outLink UID (#6048) * perf: query extension * fix: s3 configs (#6050) * fix: s3 configs * s3 --------- Co-authored-by: archer <545436317@qq.com> * s3 valid string check * perf: completion api * fix: model test * perf: init * fix: init * fix: init shell * fix: faq --------- Co-authored-by: Roy <whoeverimf5@gmail.com>
81 lines
2.2 KiB
TypeScript
81 lines
2.2 KiB
TypeScript
import { replaceS3KeyToPreviewUrl } from '../../../core/dataset/utils';
|
|
import { addEndpointToImageUrl } from '../../../common/file/image/utils';
|
|
import type { DatasetDataSchemaType } from '@fastgpt/global/core/dataset/type';
|
|
import { addDays } from 'date-fns';
|
|
import { isS3ObjectKey, jwtSignS3ObjectKey } from '../../../common/s3/utils';
|
|
|
|
export const formatDatasetDataValue = ({
|
|
q,
|
|
a,
|
|
imageId,
|
|
imageDescMap
|
|
}: {
|
|
q: string;
|
|
a?: string;
|
|
imageId?: string;
|
|
imageDescMap?: Record<string, string>;
|
|
}): {
|
|
q: string;
|
|
a?: string;
|
|
imagePreivewUrl?: string;
|
|
} => {
|
|
// Add image description to image markdown
|
|
if (imageDescMap) {
|
|
// Helper function to replace image markdown with description
|
|
const replaceImageMarkdown = (text: string): string => {
|
|
return text.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, (match, altText, url) => {
|
|
const description = imageDescMap[url];
|
|
if (description) {
|
|
// Add description to alt text, keeping original if exists
|
|
const newAltText = altText ? `${altText} - ${description}` : description;
|
|
return ``;
|
|
}
|
|
return match; // Return original if no description found
|
|
});
|
|
};
|
|
|
|
// Apply replacement to both q and a
|
|
q = replaceImageMarkdown(q);
|
|
if (a) {
|
|
a = replaceImageMarkdown(a);
|
|
}
|
|
}
|
|
|
|
// Add image base url
|
|
q = addEndpointToImageUrl(q);
|
|
if (a) {
|
|
a = addEndpointToImageUrl(a);
|
|
}
|
|
|
|
if (!imageId) {
|
|
return {
|
|
q: replaceS3KeyToPreviewUrl(q, addDays(new Date(), 90)),
|
|
a: a ? replaceS3KeyToPreviewUrl(a, addDays(new Date(), 90)) : undefined
|
|
};
|
|
}
|
|
|
|
const imagePreivewUrl = isS3ObjectKey(imageId, 'dataset')
|
|
? jwtSignS3ObjectKey(imageId, addDays(new Date(), 90))
|
|
: imageId;
|
|
|
|
return {
|
|
q: ``,
|
|
a,
|
|
imagePreivewUrl
|
|
};
|
|
};
|
|
|
|
export const getFormatDatasetCiteList = (list: DatasetDataSchemaType[]) => {
|
|
return list.map((item) => ({
|
|
_id: item._id,
|
|
...formatDatasetDataValue({
|
|
q: item.q,
|
|
a: item.a,
|
|
imageId: item.imageId
|
|
}),
|
|
history: item.history,
|
|
updateTime: item.updateTime,
|
|
index: item.chunkIndex
|
|
}));
|
|
};
|