28 lines
985 B
Python
28 lines
985 B
Python
|
|
from langchain_core.prompts import PromptTemplate
|
|||
|
|
|
|||
|
|
from src.server.deep_agent.agents.init_llm import title_llm
|
|||
|
|
|
|||
|
|
|
|||
|
|
def conversation_title(full_conversation):
|
|||
|
|
title_prompt = PromptTemplate(
|
|||
|
|
input_variables=["full_conversation"],
|
|||
|
|
template="""
|
|||
|
|
请严格按照以下要求生成对话标题:
|
|||
|
|
1. 标题长度:8-15个字,纯中文,无标点、无特殊符号、无换行
|
|||
|
|
2. 标题内容:基于完整对话,精准概括核心主题(兼顾用户需求和助手回复)
|
|||
|
|
3. 标题风格:自然口语化,符合中文表达习惯,不冗余
|
|||
|
|
|
|||
|
|
完整对话内容:
|
|||
|
|
{full_conversation}
|
|||
|
|
|
|||
|
|
仅输出标题,不要输出任何额外解释、说明或标点符号。
|
|||
|
|
"""
|
|||
|
|
)
|
|||
|
|
title_chain = title_prompt | title_llm
|
|||
|
|
response = title_chain.invoke({"full_conversation": full_conversation})
|
|||
|
|
return response
|
|||
|
|
|
|||
|
|
|
|||
|
|
if __name__ == '__main__':
|
|||
|
|
print(conversation_title("你好"))
|