forked from CherryHQ/cherry-studio-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract.ts
More file actions
34 lines (30 loc) · 817 Bytes
/
extract.ts
File metadata and controls
34 lines (30 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { XMLParser } from 'fast-xml-parser'
export interface ExtractResults {
websearch?: WebsearchExtractResults
knowledge?: KnowledgeExtractResults
}
export interface WebsearchExtractResults {
question: string[]
links?: string[]
}
export interface KnowledgeExtractResults {
rewrite: string
question: string[]
}
/**
* 从带有XML标签的文本中提取信息
* @public
* @param {string} text 包含XML标签的文本
* @returns {ExtractResults} 提取的信息对象
* @throws
*/
export const extractInfoFromXML = (text: string): ExtractResults => {
// Logger.log('extract text', text)
const parser = new XMLParser({
isArray: name => {
return name === 'question' || name === 'links'
}
})
// Logger.log('Extracted results:', extractResults)
return parser.parse(text)
}