ComenzarEmpieza gratis

Using extracted entities

The Dramatis Personæ section of the text describes the characters in the play and can be considered a comprehensive source of truth. This information also holds rich information on the personal relationships between the characters.

 Dramatis Personæ

ESCALUS, Prince of Verona.
MERCUTIO, kinsman to the Prince, and friend to Romeo.
PARIS, a young Nobleman, kinsman to the Prince.
Page to Paris.

Complete the code to extract the characters from the personae text using the character_chain, and then use the list of characters to build a list of relationships from the text using relationship_chain.

The visualize_families() function will display the resulting relationships in a graph.

Este ejercicio forma parte del curso

Graph RAG with LangChain and Neo4j

Ver curso

Instrucciones del ejercicio

  • Invoke character_chain, passing it personae to extract the character entities.
  • Invoke the relationship_chain on the character name, personae, and the extracted characters in JSON format (character_json) to extract the relationships between the three characters listed and the characters listed in personae.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# Extract characters from the personae variable
output = character_chain.____({"personae": ____})

character_json = dumps([dict(character) for character in output.characters])

# Extract the relationships
for character_name in ["Romeo", "Juliet", "Friar Lawrence"]:
    relationship_output = relationship_chain.invoke({
        "character_name": character_name, 
        "personae": ____, 
        "characters": ____
    })
    
    for relationship in relationship_output.relationships:
        all_relationships.append(relationship)

visualize_families(all_relationships, output)
Editar y ejecutar código