add summarize_story
				
					
				
			This commit is contained in:
		
							parent
							
								
									5cb8755a00
								
							
						
					
					
						commit
						986f273006
					
				
							
								
								
									
										20
									
								
								tool_core.js
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								tool_core.js
									
									
									
									
									
								
							@ -349,6 +349,26 @@ module.exports = {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  summarize_story (story = []) {
 | 
				
			||||||
 | 
					    // story is an array of objects, each object could either be {text:'some string'}, {image: url} or {video:url}. Please construct a summary object as result: { textLength, imageCount, VideoCount }
 | 
				
			||||||
 | 
					    return story.reduce(
 | 
				
			||||||
 | 
					      (summary, { text, image, video, file } = {}) => {
 | 
				
			||||||
 | 
					        if (text) {
 | 
				
			||||||
 | 
					          summary.textLength += text.length
 | 
				
			||||||
 | 
					          summary.wordCount += text.split(/\s+/).length
 | 
				
			||||||
 | 
					        } else if (image) {
 | 
				
			||||||
 | 
					          summary.imageCount++
 | 
				
			||||||
 | 
					        } else if (video) {
 | 
				
			||||||
 | 
					          summary.videoCount++
 | 
				
			||||||
 | 
					        } else if (file) {
 | 
				
			||||||
 | 
					          summary.fileCount++
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return summary
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      { textLength: 0, wordCount: 0, imageCount: 0, videoCount: 0 }
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  is_empty (data) {
 | 
					  is_empty (data) {
 | 
				
			||||||
    // empty: undefined, null, false, 0, NaN, '', '空格,tab, \n等', [], {}
 | 
					    // empty: undefined, null, false, 0, NaN, '', '空格,tab, \n等', [], {}
 | 
				
			||||||
    if (data) {
 | 
					    if (data) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user