diff --git a/api/core/model_runtime/entities/message_entities.py b/api/core/model_runtime/entities/message_entities.py index 3ac83b4c96..9e46d72893 100644 --- a/api/core/model_runtime/entities/message_entities.py +++ b/api/core/model_runtime/entities/message_entities.py @@ -251,10 +251,7 @@ class AssistantPromptMessage(PromptMessage): :return: True if prompt message is empty, False otherwise """ - if not super().is_empty() and not self.tool_calls: - return False - - return True + return super().is_empty() and not self.tool_calls class SystemPromptMessage(PromptMessage): diff --git a/web/app/components/base/amplitude/AmplitudeProvider.tsx b/web/app/components/base/amplitude/AmplitudeProvider.tsx index 87ef516835..0f083a4a7d 100644 --- a/web/app/components/base/amplitude/AmplitudeProvider.tsx +++ b/web/app/components/base/amplitude/AmplitudeProvider.tsx @@ -54,7 +54,7 @@ const pageNameEnrichmentPlugin = (): amplitude.Types.EnrichmentPlugin => { } const AmplitudeProvider: FC = ({ - sessionReplaySampleRate = 1, + sessionReplaySampleRate = 0.5, }) => { useEffect(() => { // Only enable in Saas edition with valid API key diff --git a/web/utils/format.spec.ts b/web/utils/format.spec.ts index 0fde0ccbe8..3a1709dbdc 100644 --- a/web/utils/format.spec.ts +++ b/web/utils/format.spec.ts @@ -19,6 +19,28 @@ describe('formatNumber', () => { it('should correctly handle empty input', () => { expect(formatNumber('')).toBe('') }) + it('should format very small numbers without scientific notation', () => { + expect(formatNumber(0.0000008)).toBe('0.0000008') + expect(formatNumber(0.0000001)).toBe('0.0000001') + expect(formatNumber(0.000001)).toBe('0.000001') + expect(formatNumber(0.00001)).toBe('0.00001') + }) + it('should format negative small numbers without scientific notation', () => { + expect(formatNumber(-0.0000008)).toBe('-0.0000008') + expect(formatNumber(-0.0000001)).toBe('-0.0000001') + }) + it('should handle small numbers from string input', () => { + expect(formatNumber('0.0000008')).toBe('0.0000008') + expect(formatNumber('8E-7')).toBe('0.0000008') + expect(formatNumber('1e-7')).toBe('0.0000001') + }) + it('should handle small numbers with multi-digit mantissa in scientific notation', () => { + expect(formatNumber(1.23e-7)).toBe('0.000000123') + expect(formatNumber(1.234e-7)).toBe('0.0000001234') + expect(formatNumber(12.34e-7)).toBe('0.000001234') + expect(formatNumber(0.0001234)).toBe('0.0001234') + expect(formatNumber('1.23e-7')).toBe('0.000000123') + }) }) describe('formatFileSize', () => { it('should return the input if it is falsy', () => { diff --git a/web/utils/format.ts b/web/utils/format.ts index d087d690a2..0c81b339a3 100644 --- a/web/utils/format.ts +++ b/web/utils/format.ts @@ -26,11 +26,39 @@ import 'dayjs/locale/zh-tw' * Formats a number with comma separators. * @example formatNumber(1234567) will return '1,234,567' * @example formatNumber(1234567.89) will return '1,234,567.89' + * @example formatNumber(0.0000008) will return '0.0000008' */ export const formatNumber = (num: number | string) => { if (!num) return num - const parts = num.toString().split('.') + const n = typeof num === 'string' ? Number(num) : num + + let numStr: string + + // Force fixed decimal for small numbers to avoid scientific notation + if (Math.abs(n) < 0.001 && n !== 0) { + const str = n.toString() + const match = str.match(/e-(\d+)$/) + let precision: number + if (match) { + // Scientific notation: precision is exponent + decimal digits in mantissa + const exponent = Number.parseInt(match[1], 10) + const mantissa = str.split('e')[0] + const mantissaDecimalPart = mantissa.split('.')[1] + precision = exponent + (mantissaDecimalPart?.length || 0) + } + else { + // Decimal notation: count decimal places + const decimalPart = str.split('.')[1] + precision = decimalPart?.length || 0 + } + numStr = n.toFixed(precision) + } + else { + numStr = n.toString() + } + + const parts = numStr.split('.') parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',') return parts.join('.') }