Skip to content

Commit d2c57e6

Browse files
committed
fix: prompt and typing
1 parent 06d2ba0 commit d2c57e6

File tree

7 files changed

+96
-83
lines changed

7 files changed

+96
-83
lines changed

src/agent/analysis_agent/prompt.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import textwrap
1+
import textwrap
2+
from utils.workflow_type import WorkflowType
23

34
AGENT_DESCRIPTION = """
45
你是一个热点信息捕捉专家,你现在要做这样的一个任务:
@@ -19,35 +20,34 @@
1920
3. 招笑瞳姐觉得自己穿过的衣服能卖2w一件🤣【星瞳】
2021
4. 瞳姐难绷互联网大厂员工不知道工作站电脑开机键在哪【星瞳】
2122
"""
23+
24+
2225
# 此处特别致谢恨也迷人,偷了几个标题,用来给LLM参考学习
2326

2427

25-
def get_analysis_prompt(query: str, introduction:str, key:str = 'easy'):
26-
easy_prompt = textwrap.dedent(
27-
f"""
28-
### 你的返回内容应该采取如下的形式
29-
```json
30-
[
31-
{{
32-
"start_time": "来自于输入的start_time字段,表示要切分的视频的开始,而且要讲清楚前因后果",
33-
"stop_time": "来自于输入的stop_time字段,表示要切分的的视频的结束"而且要讲清楚前因后果,
34-
"title": "表示这段切片视频的标题",
35-
}},
36-
// 如果你认为这一段录播有多个值得切片的地方,请你继续提出,并且要求前后切片不能有重叠,但你不要切太多,切片的精髓是关键!而不是堆数量!
37-
]
38-
```\n\n"""
39-
)
40-
41-
two_step_prompt = textwrap.dedent(
42-
"暂时我还没想明白咋搞这个,其实前面clip的那个也是我瞎编的,这部分没想好"
43-
)
44-
45-
prompt_dict = {
46-
'easy': easy_prompt,
47-
'two_step': two_step_prompt
48-
}
49-
if key not in prompt_dict:
50-
raise KeyError(f"Please set a usable key. I don't know what this '{key}' you found is.")
51-
52-
back_prompt = f"### 首先给你介绍一下主播的基本信息:\n{introduction}\n### 切片内容分别如下:\n{str(query)}"
53-
return prompt_dict[key] + back_prompt
28+
def get_analysis_prompt(content: str, introduction: str, key: str = 'easy'):
29+
match key:
30+
case WorkflowType.EASY:
31+
front_prompt = textwrap.dedent(
32+
f"""
33+
### 你的返回内容应该采取如下的形式
34+
```json
35+
[
36+
{{
37+
"start_time": "来自于输入的start_time字段,表示要切分的视频的开始,而且要讲清楚前因后果",
38+
"stop_time": "来自于输入的stop_time字段,表示要切分的的视频的结束"而且要讲清楚前因后果,
39+
"title": "表示这段切片视频的标题",
40+
}},
41+
// 如果你认为这一段录播有多个值得切片的地方,请你继续提出,并且要求前后切片不能有重叠,但你不要切太多,切片的精髓是关键!而不是堆数量!
42+
]
43+
```\n\n"""
44+
)
45+
case WorkflowType.TWO_STEP:
46+
front_prompt = textwrap.dedent(
47+
"暂时我还没想明白咋搞这个,其实前面clip的那个也是我瞎编的,这部分没想好"
48+
)
49+
case _:
50+
raise KeyError(f"Please set a usable key. I don't know what this '{key}' you found is.")
51+
52+
back_prompt = f"### 首先给你介绍一下主播的基本信息:\n{introduction}\n### 切片内容分别如下:\n{str(content)}"
53+
return front_prompt + back_prompt

src/agent/clip_agent/prompt.py

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from utils.workflow_type import WorkflowType
2+
13
AGENT_DESCRIPTION = """
24
你是一个视频剪辑专家,你现在要做这样的一个任务:
35
现在有一整段视频,来自于一名主播的直播录像,你要担任视频切片员,根据提供的切片指令要求进行切分。
@@ -10,47 +12,41 @@
1012
"""
1113

1214

13-
1415
def get_clip_prompt(query: dict, key: str) -> str:
15-
# 使用 textwrap.dedent 去除公共缩进
16-
easy_prompt = (
17-
f"你需要对一段视频执行剪辑操作,要求如下\n" +
18-
f"在原素材上切分出一段视频,随后修改标题,要求全过程都使用工具完成。\n" +
19-
f"参数如下:\n" +
20-
f"1. origin_video_path: {query['origin_video_path']}\n" +
21-
f"2. task_id: {query['task_id']}\n" +
22-
f"3. start_time:{query['start_time']}\n" +
23-
f"4. stop_time:{query['stop_time']}\n" +
24-
f"5. title: {query['title']} \n" +
25-
f"请完成剪辑任务,注意,每次任务结束后,都要调用任务结束对应的工具。"
26-
)
27-
28-
two_step_prompt = (
29-
f"你需要对一段视频执行剪辑操作,要求如下\n" +
30-
f"先在原素材上切分出两段视频,随后按顺序合并。\n" +
31-
f"参数如下:\n" +
32-
f"1. origin_video_path: {query['origin_video_path']}\n" +
33-
f"2. 第一段视频\n" +
34-
f" 2.1 task_id: {query['clip'][0]['task_id']}\n" +
35-
f" 2.2. start_time:{query['clip'][0]['start_time']}\n" +
36-
f" 2.3. stop_time:{query['clip'][0]['stop_time']}\n" +
37-
f"3. 第二段视频\n" +
38-
f" 3.1 task_id: {query['clip'][1]['task_id']}\n" +
39-
f" 3.2 start_time:{query['clip'][1]['start_time']}\n" +
40-
f" 3.3 stop_time:{query['clip'][1]['stop_time']}\n" +
41-
f"4. 合并两段视频\n" +
42-
f" 4.1 task_id: {query['merge']['task_id']},\n" +
43-
f" 4.2 video_paths: 请你根据前两段视频合并操作的结果来决定\n" +
44-
f"5. 将视频重命名为\n" +
45-
f"请完成剪辑任务\n"
46-
)
47-
48-
49-
prompt_dict = {
50-
'easy': easy_prompt,
51-
'two_step': two_step_prompt
52-
}
53-
if key not in prompt_dict:
54-
raise KeyError(f"Please set a usable key. I don't know what this '{key}' you found is.")
55-
56-
return prompt_dict[key]
16+
match key:
17+
case WorkflowType.EASY:
18+
prompt = (
19+
f"你需要对一段视频执行剪辑操作,要求如下\n" +
20+
f"在原素材上切分出一段视频,随后修改标题,要求全过程都使用工具完成。\n" +
21+
f"参数如下:\n" +
22+
f"1. origin_video_path: {query['origin_video_path']}\n" +
23+
f"2. task_id: {query['task_id']}\n" +
24+
f"3. start_time:{query['start_time']}\n" +
25+
f"4. stop_time:{query['stop_time']}\n" +
26+
f"5. title: {query['title']} \n" +
27+
f"请完成剪辑任务,注意,每次任务结束后,都要调用任务结束对应的工具。"
28+
)
29+
case WorkflowType.TWO_STEP:
30+
prompt = (
31+
f"你需要对一段视频执行剪辑操作,要求如下\n" +
32+
f"先在原素材上切分出两段视频,随后按顺序合并。\n" +
33+
f"参数如下:\n" +
34+
f"1. origin_video_path: {query['origin_video_path']}\n" +
35+
f"2. 第一段视频\n" +
36+
f" 2.1 task_id: {query['clip'][0]['task_id']}\n" +
37+
f" 2.2. start_time:{query['clip'][0]['start_time']}\n" +
38+
f" 2.3. stop_time:{query['clip'][0]['stop_time']}\n" +
39+
f"3. 第二段视频\n" +
40+
f" 3.1 task_id: {query['clip'][1]['task_id']}\n" +
41+
f" 3.2 start_time:{query['clip'][1]['start_time']}\n" +
42+
f" 3.3 stop_time:{query['clip'][1]['stop_time']}\n" +
43+
f"4. 合并两段视频\n" +
44+
f" 4.1 task_id: {query['merge']['task_id']},\n" +
45+
f" 4.2 video_paths: 请你根据前两段视频合并操作的结果来决定\n" +
46+
f"5. 将视频重命名为\n" +
47+
f"请完成剪辑任务\n"
48+
)
49+
case _:
50+
raise KeyError(f"Please set a usable key. I don't know what this '{key}' you found is.")
51+
52+
return prompt

src/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import os
3+
import secrets
34
from dotenv import load_dotenv
45
# 加载.env文件中的环境变量
56
load_dotenv()
@@ -11,8 +12,8 @@
1112
introduction= json2dict("introduction.json")
1213

1314
query = {
14-
"task_id":"007",
15-
"raw_video":"raw/【直播回放】不动如山 2025年01月06日20点场.mp4",
15+
"task_id":secrets.token_hex(4),
16+
"raw_video":"raw/test.mp4",
1617
"introduction":introduction["雫るる_Official"]
1718
}
1819

src/processor/analysis_processor.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ def __init__(self):
2525

2626
pass
2727

28-
async def run(self, query: str, introduction:str, prompt_key: str='easy') -> str:
28+
async def run(self, query: dict, prompt_key: str='easy') -> str:
29+
asr_content = query['content']
30+
introduction = query['introduction']
31+
2932
agent = get_analysis_agent()
3033
runner = Runner(
3134
app_name=self.app_name,
3235
agent=agent,
3336
session_service=self.session_service
3437
)
35-
prompt=get_analysis_prompt(query, introduction, prompt_key)
38+
prompt=get_analysis_prompt(asr_content, introduction, prompt_key)
3639
content = types.Content(role='user', parts=[types.Part(text=prompt)])
3740
events_async = runner.run_async(
3841
session_id=self.session_id,

src/processor/root_processor.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ def _get_video_path(self, task_id_list: list[str]) -> list[dict]:
3434
dir_path = os.path.join(os.getenv("KB_BASE_PATH"), "result", task_id)
3535
v_list = find_video_files(dir_path)
3636
res_list.extend(v_list)
37-
38-
3937
return res_list
4038

4139

@@ -52,14 +50,21 @@ async def run(self, query: dict) -> dict:
5250
query={
5351
"input_audio": raw_video,
5452
"task_id": asr_task_id
55-
})
53+
}
54+
)
5655

5756
# 分析阶段 ---------------------------------------------------------
5857
aly_pcr = AnalysisProcessor()
59-
aly_task_id_group = [f"{task_id}_aly_{i}" for i in range(len(asr_results['batch']))]
58+
# aly_task_id_group = [f"{task_id}_aly_{i}" for i in range(len(asr_results['batch']))]
6059
aly_results = []
61-
for i, aly_task_id in enumerate(aly_task_id_group):
62-
aly = await aly_pcr.run(asr_results['batch'][i], introduction)
60+
for i in range(len(asr_results['batch'])):
61+
aly = await aly_pcr.run(
62+
query={
63+
'content': str(asr_results['batch'][i]),
64+
'introduction': introduction
65+
},
66+
prompt_key=self.prompt_key
67+
)
6368
aly_results.append(aly)
6469
pass
6570

src/utils/__init__.py

Whitespace-only changes.

src/utils/workflow_type.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from enum import StrEnum
2+
3+
# must python 3.11 +
4+
class WorkflowType(StrEnum):
5+
EASY = 'easy'
6+
TWO_STEP = 'two_step'
7+
8+

0 commit comments

Comments
 (0)