主干Ai实验室后端项目

This commit is contained in:
BBIT-Kai
2025-09-05 09:37:47 +08:00
parent aa25f914ab
commit 4a0e79b35a
25 changed files with 628 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
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
})