Skip to content

Commit

Permalink
fix: Linter
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-paliychuk committed Aug 23, 2024
1 parent 866f91f commit 2c04ab5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
62 changes: 62 additions & 0 deletions core/prompts/extract_edge_dates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from typing import Protocol, TypedDict

from .models import Message, PromptFunction, PromptVersion


class Prompt(Protocol):
v1: PromptVersion


class Versions(TypedDict):
v1: PromptFunction


def v1(context: dict[str, any]) -> list[Message]:

Check notice on line 14 in core/prompts/extract_edge_dates.py

View workflow job for this annotation

GitHub Actions / mypy

Note

Perhaps you meant "typing.Any" instead of "any"?
return [
Message(
role='system',
content='You are an AI assistant that extracts datetime information for graph edges, focusing only on dates directly related to the establishment or change of the relationship described in the edge fact.',
),
Message(
role='user',
content=f"""
Edge:
Source Node: {context['source_node']}
Edge Name: {context['edge_name']}
Target Node: {context['target_node']}
Fact: {context['edge_fact']}
Current Episode: {context['current_episode']}
Previous Episodes: {context['previous_episodes']}
Reference Timestamp: {context['reference_timestamp']}
IMPORTANT: Only extract dates that are part of the provided fact. Otherwise ignore the date.
Definitions:
- valid_at: The date and time when the relationship described by the edge fact became true or was established.
- invalid_at: The date and time when the relationship described by the edge fact stopped being true or ended.
Task:
Analyze the conversation and determine if there are dates that are part of the edge fact. Only set dates if they explicitly relate to the formation or alteration of the relationship itself.
Guidelines:
1. Use ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ) for datetimes.
2. Use the reference timestamp as the current time when determining the valid_at and invalid_at dates.
3. If no relevant dates are found that explicitly establish or change the relationship, leave the fields as null.
4. Do not infer dates from related events. Only use dates that are directly stated to establish or change the relationship.
5. For relative time mentions directly related to the relationship, calculate the actual datetime based on the reference timestamp.
6. If only a date is mentioned without a specific time, use 00:00:00 (midnight) for that date.
7. If only a year is mentioned, use January 1st of that year at 00:00:00.
9. Always include the time zone offset (use Z for UTC if no specific time zone is mentioned).
Respond with a JSON object:
{{
"valid_at": "YYYY-MM-DDTHH:MM:SSZ or null",
"invalid_at": "YYYY-MM-DDTHH:MM:SSZ or null",
"explanation": "Brief explanation of why these dates were chosen or why they were set to null"
}}
""",
),
]


versions: Versions = {'v1': v1}
1 change: 0 additions & 1 deletion core/utils/maintenance/temporal_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ async def extract_edge_dates(
'previous_episodes': [ep.content for ep in previous_episodes],
'reference_timestamp': reference_time.isoformat(),
}
test = prompt_library.extract_edge_dates.v1(context)
llm_response = await llm_client.generate_response(prompt_library.extract_edge_dates.v1(context))

valid_at = llm_response.get('valid_at')
Expand Down
2 changes: 1 addition & 1 deletion runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import os
import sys
from datetime import datetime, timedelta
from datetime import datetime

from dotenv import load_dotenv

Expand Down

0 comments on commit 2c04ab5

Please sign in to comment.