Files
AILab/bbit_ai/app/llm/chatLLM.py
T
2025-12-31 17:49:17 +08:00

27 lines
724 B
Python

from langchain_core.prompts import PromptTemplate
from config.llm import llm
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}
)