ÎncepețiÎncepe gratuit

Utilizarea faptelor extrase din conversație

Acum e momentul să aplici LLM-ul cu ieșiri structurate! llm_with_output, creat în exercițiul anterior, este în continuare disponibil, iar șablonul de prompt pentru acest LLM a fost deja furnizat.

Acest exercițiu face parte din cursul

Graph RAG cu LangChain și Neo4j

Vezi cursul

Instrucțiuni pentru exercițiu

  • Conectează șablonul de prompt pentru chat furnizat la LLM-ul cu ieșire structurată (llm_with_output).
  • Invocă lanțul folosind ID-ul de utilizator și ID-ul de sesiune furnizate, transmițând mesajele din istoric (history).

Exercițiu interactiv practic

Încearcă acest exercițiu completând acest cod de exemplu.

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": ____})
Editează și rulează codul