2024-08-20 16:29:19 -04:00
|
|
|
from typing import Protocol, TypedDict
|
2024-08-22 12:26:13 -07:00
|
|
|
|
|
|
|
from .models import Message, PromptFunction, PromptVersion
|
2024-08-20 16:29:19 -04:00
|
|
|
|
|
|
|
|
|
|
|
class Prompt(Protocol):
|
2024-08-22 13:06:42 -07:00
|
|
|
v1: PromptVersion
|
2024-08-20 16:29:19 -04:00
|
|
|
|
|
|
|
|
|
|
|
class Versions(TypedDict):
|
2024-08-22 13:06:42 -07:00
|
|
|
v1: PromptFunction
|
2024-08-20 16:29:19 -04:00
|
|
|
|
|
|
|
|
|
|
|
def v1(context: dict[str, any]) -> list[Message]:
|
2024-08-22 13:06:42 -07:00
|
|
|
return [
|
|
|
|
Message(
|
|
|
|
role='system',
|
|
|
|
content='You are an AI assistant that helps determine which relationships in a knowledge graph should be invalidated based on newer information.',
|
|
|
|
),
|
|
|
|
Message(
|
|
|
|
role='user',
|
|
|
|
content=f"""
|
2024-08-20 16:29:19 -04:00
|
|
|
Based on the provided existing edges and new edges with their timestamps, determine which existing relationships, if any, should be invalidated due to contradictions or updates in the new edges.
|
|
|
|
Only mark a relationship as invalid if there is clear evidence from new edges that the relationship is no longer true.
|
|
|
|
Do not invalidate relationships merely because they weren't mentioned in new edges.
|
|
|
|
|
|
|
|
Existing Edges (sorted by timestamp, newest first):
|
|
|
|
{context['existing_edges']}
|
|
|
|
|
|
|
|
New Edges:
|
|
|
|
{context['new_edges']}
|
|
|
|
|
|
|
|
Each edge is formatted as: "UUID | SOURCE_NODE - EDGE_NAME - TARGET_NODE (TIMESTAMP)"
|
|
|
|
|
|
|
|
For each existing edge that should be invalidated, respond with a JSON object in the following format:
|
|
|
|
{{
|
|
|
|
"invalidated_edges": [
|
|
|
|
{{
|
|
|
|
"edge_uuid": "The UUID of the edge to be invalidated (the part before the | character)",
|
|
|
|
"reason": "Brief explanation of why this edge is being invalidated"
|
|
|
|
}}
|
|
|
|
]
|
|
|
|
}}
|
|
|
|
|
|
|
|
If no relationships need to be invalidated, return an empty list for "invalidated_edges".
|
|
|
|
""",
|
2024-08-22 13:06:42 -07:00
|
|
|
),
|
|
|
|
]
|
2024-08-20 16:29:19 -04:00
|
|
|
|
|
|
|
|
2024-08-22 13:06:42 -07:00
|
|
|
versions: Versions = {'v1': v1}
|