chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
60158935f4
commit
6519682885
15831 files changed
+3063428
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import type {
|
||||
DocumentProcessRulesResponse,
|
||||
PreProcessingRule,
|
||||
Rule,
|
||||
} from '@dify/contracts/api/console/datasets/types.gen'
|
||||
import type { Rules } from '@/models/datasets'
|
||||
import { ProcessMode } from '@/models/datasets'
|
||||
|
||||
const PRE_PROCESSING_RULE_IDS = new Set<string>([
|
||||
'remove_extra_spaces',
|
||||
'remove_stopwords',
|
||||
'remove_urls_emails',
|
||||
] satisfies PreProcessingRule['id'][])
|
||||
|
||||
const isPreProcessingRule = (rule: { id: string; enabled: boolean }): rule is PreProcessingRule =>
|
||||
PRE_PROCESSING_RULE_IDS.has(rule.id)
|
||||
|
||||
export const isProcessMode = (mode: string): mode is ProcessMode =>
|
||||
Object.values<string>(ProcessMode).includes(mode)
|
||||
|
||||
type StoredRules = DocumentProcessRulesResponse | Rule
|
||||
|
||||
const toSegmentation = (segmentation: NonNullable<StoredRules['segmentation']>) => ({
|
||||
// The backend defaults an unspecified separator to a newline and overlap to zero.
|
||||
separator: segmentation.separator ?? '\n',
|
||||
max_tokens: segmentation.max_tokens,
|
||||
chunk_overlap: segmentation.chunk_overlap ?? 0,
|
||||
})
|
||||
|
||||
/**
|
||||
* Segmentation settings from a stored process rule. Automatic-mode rules store no segmentation,
|
||||
* so there is nothing to restore for them.
|
||||
*/
|
||||
export const toSegmentationRules = (rules: StoredRules): Rules | undefined => {
|
||||
if (!rules.segmentation) return undefined
|
||||
return {
|
||||
pre_processing_rules: (rules.pre_processing_rules ?? []).filter(isPreProcessingRule),
|
||||
segmentation: toSegmentation(rules.segmentation),
|
||||
parent_mode: rules.parent_mode ?? undefined,
|
||||
subchunk_segmentation: rules.subchunk_segmentation
|
||||
? toSegmentation(rules.subchunk_segmentation)
|
||||
: undefined,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user