问题生成

This commit is contained in:
IndieKKY
2024-05-27 11:20:03 +08:00
parent 4a6ebf0894
commit 975c524369
3 changed files with 66 additions and 2 deletions

View File

@@ -5,7 +5,7 @@ import classNames from 'classnames'
import {FaClipboardList} from 'react-icons/fa'
import {PAGE_MAIN, PAGE_SETTINGS, SUMMARIZE_THRESHOLD, SUMMARIZE_TYPES} from '../const'
import useTranslate from '../hooks/useTranslate'
import {BsDashSquare, BsPlusSquare, CgFileDocument, GrOverview, RiFileCopy2Line} from 'react-icons/all'
import {BsDashSquare, BsPlusSquare, CgFileDocument, FaQuestion, GrOverview, RiFileCopy2Line} from 'react-icons/all'
import toast from 'react-hot-toast'
import {getLastTime, getSummaryStr, isSummaryEmpty, parseStrTimeToSeconds} from '../util/biz_util'
import {useInViewport} from 'ahooks'
@@ -107,6 +107,13 @@ const Summarize = (props: {
<div className={classNames('font-medium max-w-[90%]', fontSize === 'large' ? 'text-sm' : 'text-xs')}>
{summary.content.summary}
</div>}
{summary?.type === 'question' && (summary.content != null) &&
<div className={classNames('font-medium max-w-[90%] flex flex-col gap-1', fontSize === 'large' ? 'text-sm' : 'text-xs')}>
{summary.content.map((question: any, idx: number) => <div key={idx}>
<h2 className={classNames('font-medium underline', fontSize === 'large' ? 'text-sm' : 'text-xs')}>{question.q}</h2>
<div className={classNames('font-normal', fontSize === 'large' ? 'text-sm' : 'text-xs')}>{question.a}</div>
</div>)}
</div>}
</div>
<div className='flex flex-col justify-center items-center'>
{segment.text.length < SUMMARIZE_THRESHOLD && <div className='desc-lighter text-xs'>.</div>}
@@ -189,6 +196,12 @@ const SegmentCard = (props: {
}))
}, [dispatch])
const onSelQuestion = useCallback(() => {
dispatch(setTempData({
curSummaryType: 'question'
}))
}, [dispatch])
return <div
className={classNames('border border-base-300 bg-base-200/25 rounded flex flex-col m-1.5 p-1.5 gap-1 shadow', showCurrent && 'shadow-primary')}>
<div className='relative flex justify-center min-h-[20px]'>
@@ -203,6 +216,7 @@ const SegmentCard = (props: {
<a className={classNames('tab tab-lifted tab-xs', curSummaryType === 'brief' && 'tab-active')} onClick={onSelBrief}><CgFileDocument/></a>
<a className={classNames('tab tab-lifted tab-xs', curSummaryType === 'overview' && 'tab-active')} onClick={onSelOverview}><GrOverview/></a>
<a className={classNames('tab tab-lifted tab-xs', curSummaryType === 'keypoint' && 'tab-active')} onClick={onSelKeypoint}><FaClipboardList/></a>
<a className={classNames('tab tab-lifted tab-xs', curSummaryType === 'question' && 'tab-active')} onClick={onSelQuestion}><FaQuestion/></a>
<a className="tab tab-lifted tab-xs tab-disabled cursor-default"></a>
</div>}
<div

View File

@@ -8,6 +8,7 @@ export const STORAGE_TEMP = 'bilibili-subtitle_temp'
export const PROMPT_TYPE_TRANSLATE = 'translate'
export const PROMPT_TYPE_SUMMARIZE_OVERVIEW = 'summarize_overview'
export const PROMPT_TYPE_SUMMARIZE_KEYPOINT = 'summarize_keypoint'
export const PROMPT_TYPE_SUMMARIZE_QUESTION = 'summarize_question'
export const PROMPT_TYPE_SUMMARIZE_BRIEF = 'summarize_brief'
export const PROMPT_TYPE_ASK = 'ask'
export const PROMPT_TYPES = [{
@@ -22,6 +23,9 @@ export const PROMPT_TYPES = [{
}, {
name: '总结',
type: PROMPT_TYPE_SUMMARIZE_BRIEF,
}, {
name: '问题',
type: PROMPT_TYPE_SUMMARIZE_QUESTION,
}, {
name: '提问',
type: PROMPT_TYPE_ASK,
@@ -46,6 +50,12 @@ export const SUMMARIZE_TYPES = {
downloadName: '💡视频要点💡',
promptType: PROMPT_TYPE_SUMMARIZE_KEYPOINT,
},
question: {
name: '问题',
desc: '常见问题',
downloadName: '💡常见问题💡',
promptType: PROMPT_TYPE_SUMMARIZE_QUESTION,
},
}
export const PROMPT_DEFAULTS = {
@@ -124,6 +134,46 @@ The video's subtitles:
'''
{{segment}}
'''`,
[PROMPT_TYPE_SUMMARIZE_QUESTION]: `You are a helpful assistant that skilled at extracting questions from video subtitle.
## Context
The video's title: '''{{title}}'''.
The video's subtitles:
'''
{{segment}}
'''
## Command
Accurately extract key questions and their corresponding answers from the video subtitles based on the actual content provided. The number of questions should be between 3 and 5.
- Identify questions as sentences starting with interrogative words (e.g., "What", "How", "Why") and extract the following sentences that directly answer these questions.
- Include only those questions and answers that are relevant to the main points of the video, and ensure they cover different aspects of the video's content.
- If an answer spans multiple non-consecutive parts of the subtitles, concatenate them into a coherent response without adding any information not present in the subtitles.
- In cases where the number of potential Q&As exceeds 5, prioritize the most informative and directly answered ones.
- If clear questions and answers are not available in the subtitles, refrain from creating them and instead note the absence of direct Q&As.
- Answer in language '{{language}}'.
- Format the output in markdown json format, as specified.
## Output format
Provide an example to illustrate the expected output:
\`\`\`json
[
{
"q": "What is the main theme of the video?",
"a": "The main theme of the video is explained as..."
},
{
"q": "How is the topic developed?",
"a": "The topic is developed through various examples, including..."
}
]
\`\`\`
`,
[PROMPT_TYPE_ASK]: `You are a helpful assistant who answers question related to video subtitles.
Answer in language '{{language}}'.

2
src/typings.d.ts vendored
View File

@@ -140,4 +140,4 @@ interface BriefSummary extends Summary {
}
type SummaryStatus = 'init' | 'pending' | 'done'
type SummaryType = 'overview' | 'keypoint' | 'brief'
type SummaryType = 'overview' | 'keypoint' | 'brief' | 'question'