2024-08-18 13:22:31 -04:00
|
|
|
import json
|
|
|
|
from typing import TypedDict, Protocol
|
|
|
|
|
|
|
|
from .models import Message, PromptVersion, PromptFunction
|
|
|
|
|
|
|
|
|
|
|
|
class Prompt(Protocol):
|
|
|
|
v1: PromptVersion
|
2024-08-21 12:03:32 -04:00
|
|
|
edge_list: PromptVersion
|
2024-08-18 13:22:31 -04:00
|
|
|
|
|
|
|
|
|
|
|
class Versions(TypedDict):
|
|
|
|
v1: PromptFunction
|
2024-08-21 12:03:32 -04:00
|
|
|
edge_list: PromptFunction
|
2024-08-18 13:22:31 -04:00
|
|
|
|
|
|
|
|
|
|
|
def v1(context: dict[str, any]) -> list[Message]:
|
|
|
|
return [
|
|
|
|
Message(
|
|
|
|
role="system",
|
|
|
|
content="You are a helpful assistant that de-duplicates relationship from edge lists.",
|
|
|
|
),
|
|
|
|
Message(
|
|
|
|
role="user",
|
|
|
|
content=f"""
|
|
|
|
Given the following context, deduplicate edges from a list of new edges given a list of existing edges:
|
|
|
|
|
|
|
|
Existing Edges:
|
|
|
|
{json.dumps(context['existing_edges'], indent=2)}
|
|
|
|
|
|
|
|
New Edges:
|
|
|
|
{json.dumps(context['extracted_edges'], indent=2)}
|
|
|
|
|
|
|
|
Task:
|
|
|
|
1. start with the list of edges from New Edges
|
|
|
|
2. If any edge in New Edges is a duplicate of an edge in Existing Edges, replace the new edge with the existing
|
|
|
|
edge in the list
|
|
|
|
3. Respond with the resulting list of edges
|
|
|
|
|
|
|
|
Guidelines:
|
|
|
|
1. Use both the name and fact of edges to determine if they are duplicates,
|
|
|
|
duplicate edges may have different names
|
|
|
|
|
|
|
|
Respond with a JSON object in the following format:
|
|
|
|
{{
|
|
|
|
"new_edges": [
|
|
|
|
{{
|
|
|
|
"fact": "one sentence description of the fact"
|
|
|
|
}}
|
|
|
|
]
|
|
|
|
}}
|
|
|
|
""",
|
|
|
|
),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2024-08-21 12:03:32 -04:00
|
|
|
def edge_list(context: dict[str, any]) -> list[Message]:
|
|
|
|
return [
|
|
|
|
Message(
|
|
|
|
role="system",
|
|
|
|
content="You are a helpful assistant that de-duplicates edges from edge lists.",
|
|
|
|
),
|
|
|
|
Message(
|
|
|
|
role="user",
|
|
|
|
content=f"""
|
|
|
|
Given the following context, find all of the duplicates in a list of edges:
|
|
|
|
|
|
|
|
Edges:
|
|
|
|
{json.dumps(context['edges'], indent=2)}
|
|
|
|
|
|
|
|
Task:
|
|
|
|
If any edge in Edges is a duplicate of another edge, return the fact of only one of the duplicate edges
|
|
|
|
|
|
|
|
Guidelines:
|
|
|
|
1. Use both the name and fact of edges to determine if they are duplicates,
|
|
|
|
edges with the same name may not be duplicates
|
|
|
|
2. The final list should have only unique facts. If 3 edges are all duplicates of each other, only one of their
|
|
|
|
facts should be in the response
|
|
|
|
|
|
|
|
Respond with a JSON object in the following format:
|
|
|
|
{{
|
|
|
|
"unique_edges": [
|
|
|
|
{{
|
|
|
|
"fact": "fact of a unique edge",
|
|
|
|
}}
|
|
|
|
]
|
|
|
|
}}
|
|
|
|
""",
|
|
|
|
),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
versions: Versions = {"v1": v1, "edge_list": edge_list}
|