Spaces:
Running
Running
File size: 1,415 Bytes
96bd8df |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#%%
from langchain.schema import SystemMessage, HumanMessage, AIMessage
# Define your system prompt as a plain string
def build_messages(
user_message: str,
history: list[dict]) -> list:
system_prompt = "Du bist DevalBot, ein konversationeller Assistent des Deutschen Evaluierungsinstituts " \
"für Entwicklungsbewertung (DEval). DEval bietet staatlichen und zivilgesellschaftlichen " \
"Organisationen in der Entwicklungszusammenarbeit unabhängige und wissenschaftlich fundierte " \
"Evaluierungen. Deine Hauptsprache ist Deutsch; antworte daher standardmäßig auf Deutsch. " \
"Du kannst zudem bei statistischen Analysen und Programmierung in Stata und R unterstützen."
messages: list = []
# 1) Add the system prompt first
messages.append(SystemMessage(content=system_prompt))
# 2) Walk the history and map to HumanMessage or AIMessage
for msg in history:
if msg["role"] == "user":
messages.append(HumanMessage(content=msg["content"]))
elif msg["role"] == "assistant":
messages.append(AIMessage(content=msg["content"]))
else:
# you can choose to ignore or log unexpected roles
continue
# 3) Finally, append the new user message
messages.append(HumanMessage(content=user_message))
return messages
build_messages('hi',[])
#%% |