-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
32 lines (27 loc) · 1.57 KB
/
Copy pathutils.py
File metadata and controls
32 lines (27 loc) · 1.57 KB
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
from langchain.prompts import ChatPromptTemplate
from langchain_community.chat_models import ChatTongyi
import os
def generate_script(subject, video_length, creativity, DASHSCOPE_API_KEY):
title_template = ChatPromptTemplate.from_messages(
[
("human", "请为'{subject}'这个主题的视频想一个吸引人的标题")
]
)
script_template = ChatPromptTemplate.from_messages(
[
("human",
"""你是一位短视频频道的博主。根据以下标题和相关信息,为短视频频道写一个视频脚本。
视频标题:{title},视频时长:{duration}分钟,生成的脚本的长度尽量遵循视频时长的要求。
要求开头抓住限球,中间提供干货内容,结尾有惊喜,脚本格式也请按照【开头、中间,结尾】分隔。
整体内容的表达方式要尽量轻松有趣,吸引年轻人。
脚本内容可以结合以下维基百科搜索出的信息,但仅作为参考,只结合相关的即可,对不相关的进行忽略:
""")
]
)
model = ChatTongyi(model="qwen-72b-chat",DASHSCOPE_API_KEY =DASHSCOPE_API_KEY,temperature=creativity)
title_chain = title_template | model
script_chain = script_template | model
title = title_chain.invoke({"subject": subject}).content
script = script_chain.invoke({"title": title, "duration": video_length}).content
return title , script
#print(generate_script("sora模型", 1, 0.7, os.getenv("DASHSCOPE_API_KEY")))