Korzystanie z wyodrębnionych faktów z rozmowy
Czas zastosować LLM ze strukturyzowanymi wynikami! llm_with_output utworzony w poprzednim ćwiczeniu jest nadal dostępny, a szablon promptu dla tego LLM został już przygotowany.
To ćwiczenie jest częścią kursu
Graph RAG z LangChain i Neo4j
Instrukcje do ćwiczenia
- Podłącz dostarczony szablon promptu do LLM ze strukturyzowanym wyjściem (
llm_with_output). - Wywołaj łańcuch dla podanego użytkownika i identyfikatora sesji, przekazując mu wiadomości z historii (
history).
Interaktywne ćwiczenie praktyczne
Spróbuj tego ćwiczenia, uzupełniając ten przykładowy kod.
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": ____})