EmpezarEmpieza gratis

Usar los hechos extraídos de la conversación

¡Hora de aplicar tu LLM con salidas estructuradas! El llm_with_output que creaste en el ejercicio anterior sigue disponible, y la plantilla de prompt para este LLM ya está proporcionada.

Este ejercicio forma parte del curso

Graph RAG con LangChain y Neo4j

Ver curso

Instrucciones del ejercicio

  • Encadena la plantilla de chat prompt proporcionada con el LLM con salida estructurada (llm_with_output).
  • Invoca la cadena con el ID de usuario y de sesión indicados, pasándole los mensajes del historial (history).

ejercicio interactivo práctico

Prueba este ejercicio completando este código de ejemplo.

chain = ChatPromptTemplate.from_messages([
    SystemMessagePromptTemplate.from_template("""
    	You are talking to {user}, the user of the application. 
        Any facts in the first person relate to {user}.
        The Session ID is {session_id}.
    	Extract the facts from the conversation and return them in the format of object, subject, predicate.
    """),
    # Pipe the chat prompt template into the LLM with structured output
    MessagesPlaceholder(variable_name="history")
]) | ____

# Invoke the chain, passing it the messages from the history
chain.invoke({"user": USER, "session_id": SESSION_ID, "history": ____})
Editar y ejecutar código