Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibuildthecloud/fd689b7f153a3151f277ed57fe8d0af5 to your computer and use it in GitHub Desktop.
Save ibuildthecloud/fd689b7f153a3151f277ed57fe8d0af5 to your computer and use it in GitHub Desktop.
tools: sys.http.html2text
json: true
Download the wikipedia article for "Walt Disney" and then process the output according to the following rules
# Knowledge Graph Instructions for GPT-4
## 1. Overview
You are a top-tier algorithm designed for extracting information in structured formats to build a knowledge graph.
- **Nodes** represent entities and concepts. They're akin to Wikipedia nodes.
- The aim is to achieve simplicity and clarity in the knowledge graph, making it accessible for a vast audience.
## 2. Labeling Nodes
- **Consistency**: Ensure you use basic or elementary types for node labels.
- For example, when you identify an entity representing a person, always label it as **"person"**. Avoid using more specific terms like "mathematician" or "scientist".
- **Node IDs**: Never utilize integers as node IDs. Node IDs should be names or human-readable identifiers found in the text.
## 3. Handling Numerical Data and Dates
- Numerical data, like age or other related information, should be incorporated as attributes or properties of the respective nodes.
- **No Separate Nodes for Dates/Numbers**: Do not create separate nodes for dates or numerical values. Always attach them as attributes or properties of nodes.
- **Property Format**: Properties must be in a key-value format.
- **Quotation Marks**: Never use escaped single or double quotes within property values.
- **Naming Convention**: Use camelCase for property keys, e.g., `birthDate`.
## 4. Coreference Resolution
- **Maintain Entity Consistency**: When extracting entities, it's vital to ensure consistency.
If an entity, such as "John Doe", is mentioned multiple times in the text but is referred to by different names or pronouns (e.g., "Joe", "he"),
always use the most complete identifier for that entity throughout the knowledge graph. In this example, use "John Doe" as the entity ID.
Remember, the knowledge graph should be coherent and easily understandable, so maintaining consistency in entity references is crucial.
## 5. Strict Compliance
Adhere to the rules strictly. Non-compliance will result in termination.
## 6. Output Format
Structure the output to look like
```json
{
"nodes": [
{
id: "node id"
properties: [
{
key: "property key",
value: "property value"
}
]
}
],
"relationships": [
{
id: "relationship id"
sourceNodeId: "source node id",
targetNodeId: "target node id",
relationshipType: "relationshipType",
properties: [
{
key: "property key",
value: "property value"
}
]
}
]
}
```
@ibuildthecloud
Copy link
Author

Each time you run this you will get a different output. The first time I ran it I got

{
    "nodes": [
        {
            "id": "Walt Disney",
            "properties": [
                {
                    "key": "birthDate",
                    "value": "December 5, 1901"
                },
                {
                    "key": "deathDate",
                    "value": "December 15, 1966"
                },
                {
                    "key": "occupations",
                    "value": "Animator, film producer, voice actor, entrepreneur"
                },
                {
                    "key": "awards",
                    "value": "26 Academy Awards, 3 Golden Globe Awards, 1 Emmy Award"
                }
            ]
        },
        {
            "id": "Mickey Mouse",
            "properties": [
                {
                    "key": "creationDate",
                    "value": "1928"
                },
                {
                    "key": "creators",
                    "value": "Walt Disney, Ub Iwerks"
                }
            ]
        },
        {
            "id": "Disneyland",
            "properties": [
                {
                    "key": "openingDate",
                    "value": "July 1955"
                },
                {
                    "key": "location",
                    "value": "Anaheim, California"
                }
            ]
        },
        {
            "id": "Walt Disney World",
            "properties": [
                {
                    "key": "planningStartYear",
                    "value": "1965"
                },
                {
                    "key": "location",
                    "value": "Orlando, Florida"
                }
            ]
        }
    ],
    "relationships": [
        {
            "id": "creatorOf",
            "sourceNodeId": "Walt Disney",
            "targetNodeId": "Mickey Mouse",
            "relationshipType": "creatorOf",
            "properties": []
        },
        {
            "id": "founderOf",
            "sourceNodeId": "Walt Disney",
            "targetNodeId": "Disneyland",
            "relationshipType": "founderOf",
            "properties": []
        },
        {
            "id": "plannerOf",
            "sourceNodeId": "Walt Disney",
            "targetNodeId": "Walt Disney World",
            "relationshipType": "plannerOf",
            "properties": []
        }
    ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment