-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Initial version of temporal invalidation + tests (#8)
* feat: Initial version of temporal invalidation + tests * fix: dont run int tests on CI * fix: dont run int tests on CI * fix: dont run int tests on CI * fix: time of day issue * fix: running non int tests in ci * fix: running non int tests in ci * fix: running non int tests in ci * fix: running non int tests in ci * fix: running non int tests in ci * fix: running non int tests in ci * fix: running non int tests in ci * revert: Tests structural changes * chore: Remove idea file * chore: Get rid of NodesWithEdges class and define a triplet type instead
- Loading branch information
1 parent
40e74a2
commit a6fd0dd
Showing
21 changed files
with
895 additions
and
3,091 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Unit Tests | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
- name: Load cached Poetry installation | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.local | ||
key: poetry-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} | ||
- name: Install Poetry | ||
uses: snok/install-poetry@v1 | ||
with: | ||
virtualenvs-create: true | ||
virtualenvs-in-project: true | ||
- name: Load cached dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: .venv | ||
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} | ||
- name: Install dependencies | ||
run: poetry install --no-interaction --no-root | ||
- name: Run non-integration tests | ||
env: | ||
PYTHONPATH: ${{ github.workspace }} | ||
run: | | ||
poetry run pytest -m "not integration" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import sys | ||
import os | ||
|
||
# This code adds the project root directory to the Python path, allowing imports to work correctly when running tests. | ||
# Without this file, you might encounter ModuleNotFoundError when trying to import modules from your project, especially when running tests. | ||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from typing import Protocol, TypedDict | ||
from .models import Message, PromptVersion, PromptFunction | ||
|
||
|
||
class Prompt(Protocol): | ||
v1: PromptVersion | ||
|
||
|
||
class Versions(TypedDict): | ||
v1: PromptFunction | ||
|
||
|
||
def v1(context: dict[str, any]) -> list[Message]: | ||
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""" | ||
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". | ||
""", | ||
), | ||
] | ||
|
||
|
||
versions: Versions = {"v1": v1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.