BaşlayınÜcretsiz başlayın

Konuşma geçmişlerinden olguları çıkarma

Şimdi konuşma geçmişini bir üst seviyeye taşıyalım! Konuşma geçmişlerinden olguları yapılandırılmış bir şekilde çıkarmak için pydantic sınıfları tanımlayacaksın.

Bu, kursun sonraki ve son egzersizinde gerçek çıkarımı yapabilmen için zemin hazırlayacak.

Gerekli pydantic sınıfları zaten içe aktarıldı ve bir llm de tanımlandı.

Bu egzersiz, kursun bir parçasıdır

LangChain ve Neo4j ile Graph RAG

Kursa Göz Atın

Egzersiz talimatları

  • Bir konuşmadan olguları çıkarmak için pydantic tabanlı bir ConversationFact sınıfı tanımla; açıklamalarla uyumlu object, subject, relationship ve session_id alanlarını ekle.
  • ConversationFact nesnelerinden listeler oluşturmak için pydantic tabanlı bir ConversationFacts sınıfı tanımla.
  • Sağlanan llm ile yapılandırılmış çıktı formatını bağla.

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

# Define the ConversationFact with the correct fields
class ____(____):
    """
    A class that holds the facts from a conversation in a format of object, subject, predicate.

    For example, if the conversation includes the fact that the user likes ice creamthe facts would be:
    - object: "Adam"
    - subject: "ice cream"
    - relationship: "LIKES"
    The class also includes a session ID to identify the conversation.
    """
    ____: str = Field(description="The session ID of the conversation.")
    ____: str = Field(description="The object of the fact. For example, 'Adam' ")
    ____: str = Field(description="The subject of the fact. For example, 'Ice cream'")
    ____: str = Field(description="The relationship between the object and the subject.  This should be a single word verb in upper case. For example, 'LIKES' or 'OWNS'")

# Define a ConversationFacts class for creating lists of ConversationFact objects
class ____(____):
    """A class that holds a list of ConversationFact objects."""
    facts: list[____] = Field(description="A list of ConversationFact objects.")

# Bind the output to the llm provided
llm_with_output = llm.____(____) 
Kodu Düzenle ve Çalıştır