""" Simple graph nodes. - greeting_node: contextualized LLM response (greeting / thanks / goodbye) - default_node: static response for out-of-scope requests """ from langchain_core.messages import AIMessage, SystemMessage, HumanMessage from langchain_openai import ChatOpenAI from utils.config import LLM_MODEL_NAME from utils.i18n import t, greeting_prompt # Dedicated LLM for greetings with high temperature (variability in the responses). # The global LLM (temperature=0) is deterministic for classification/translation. _greeting_llm = ChatOpenAI(model=LLM_MODEL_NAME, temperature=0.9) def create_greeting_node(): """Creates the greetings node with a dedicated LLM (temperature=0.9) for varied responses.""" def greeting_node(state): greeting_type = state.get("greeting_type", "greeting") prompt = greeting_prompt(greeting_type) # localized via RESPONSE_LANG user_msg = state["messages"][-1].content try: response = _greeting_llm.invoke([ SystemMessage(content=prompt), HumanMessage(content=user_msg), ]) return {"messages": [AIMessage(content=response.content.strip())]} except Exception: return {"messages": [AIMessage(content=t("greeting_fallback"))]} return greeting_node def default_node(state): """Handles out-of-scope requests (returns, shipping, account, bugs). Refers to human support.""" return {"messages": [AIMessage(content=t("default_out_of_scope"))]}