from config.llm import llm from langchain.prompts import PromptTemplate chatPrompt = PromptTemplate( input_variables=["aiRole", "history", "userInput"], template = """ 你的用户画像为:{aiRole}。 你需要基于你的角色性格,使用中文回答用户。 聊天历史: {history} 用户最新输入: {userInput} 最后,请注意,不要编造数据,不知道就说不知道,现在,请生成你的回复: """ ) chatChain = chatPrompt | llm def get_chat_response(aiRole: str,history: str, userInput: str) -> str: return chatChain.invoke({ "aiRole": aiRole, "history": history, "userInput": userInput })