20 lines
749 B
Python
20 lines
749 B
Python
|
|
from langchain.prompts import PromptTemplate
|
|
from config.llm import llm
|
|
|
|
titlePrompt = PromptTemplate(
|
|
input_variables=["userStr"],
|
|
template = """
|
|
请将用户的这句话总结成一个简短、精准的对话标题,要求:
|
|
1. 不超过10个字(可根据需要调整长度)。
|
|
2. 直接概括本次对话的核心内容。
|
|
3. 避免使用笼统或无意义的词语,如“讨论”、“聊天”等。
|
|
4. 保持自然、易懂、专业或有趣(可根据场景调整风格)。
|
|
5. 不能出现标点符号。
|
|
用户原话:"{userStr}"
|
|
"""
|
|
)
|
|
titleChain = titlePrompt | llm
|
|
|
|
def get_title(userInput: str):
|
|
return titleChain.invoke({"userStr": userInput}).content |