2024-08-23 13:01:33 -07:00
|
|
|
"""
|
|
|
|
Copyright 2024, Zep Software, Inc.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
"""
|
|
|
|
|
2024-08-23 08:15:44 -07:00
|
|
|
from typing import Any, Protocol, TypedDict
|
2024-08-15 12:03:41 -04:00
|
|
|
|
2024-08-22 12:26:13 -07:00
|
|
|
from .dedupe_edges import (
|
2024-08-23 14:18:45 -04:00
|
|
|
Prompt as DedupeEdgesPrompt,
|
2024-08-22 12:26:13 -07:00
|
|
|
)
|
|
|
|
from .dedupe_edges import (
|
2024-08-23 14:18:45 -04:00
|
|
|
Versions as DedupeEdgesVersions,
|
2024-08-22 12:26:13 -07:00
|
|
|
)
|
|
|
|
from .dedupe_edges import (
|
2024-08-23 14:18:45 -04:00
|
|
|
versions as dedupe_edges_versions,
|
2024-08-22 12:26:13 -07:00
|
|
|
)
|
2024-08-18 13:22:31 -04:00
|
|
|
from .dedupe_nodes import (
|
2024-08-23 14:18:45 -04:00
|
|
|
Prompt as DedupeNodesPrompt,
|
2024-08-22 12:26:13 -07:00
|
|
|
)
|
|
|
|
from .dedupe_nodes import (
|
2024-08-23 14:18:45 -04:00
|
|
|
Versions as DedupeNodesVersions,
|
2024-08-22 12:26:13 -07:00
|
|
|
)
|
|
|
|
from .dedupe_nodes import (
|
2024-08-23 14:18:45 -04:00
|
|
|
versions as dedupe_nodes_versions,
|
|
|
|
)
|
|
|
|
from .extract_edge_dates import (
|
|
|
|
Prompt as ExtractEdgeDatesPrompt,
|
|
|
|
)
|
|
|
|
from .extract_edge_dates import (
|
|
|
|
Versions as ExtractEdgeDatesVersions,
|
|
|
|
)
|
|
|
|
from .extract_edge_dates import (
|
|
|
|
versions as extract_edge_dates_versions,
|
2024-08-18 13:22:31 -04:00
|
|
|
)
|
2024-08-15 12:03:41 -04:00
|
|
|
from .extract_edges import (
|
2024-08-23 14:18:45 -04:00
|
|
|
Prompt as ExtractEdgesPrompt,
|
2024-08-22 12:26:13 -07:00
|
|
|
)
|
|
|
|
from .extract_edges import (
|
2024-08-23 14:18:45 -04:00
|
|
|
Versions as ExtractEdgesVersions,
|
2024-08-22 12:26:13 -07:00
|
|
|
)
|
|
|
|
from .extract_edges import (
|
2024-08-23 14:18:45 -04:00
|
|
|
versions as extract_edges_versions,
|
2024-08-15 12:03:41 -04:00
|
|
|
)
|
2024-08-22 12:26:13 -07:00
|
|
|
from .extract_nodes import (
|
2024-08-23 14:18:45 -04:00
|
|
|
Prompt as ExtractNodesPrompt,
|
2024-08-22 12:26:13 -07:00
|
|
|
)
|
|
|
|
from .extract_nodes import (
|
2024-08-23 14:18:45 -04:00
|
|
|
Versions as ExtractNodesVersions,
|
2024-08-22 12:26:13 -07:00
|
|
|
)
|
|
|
|
from .extract_nodes import (
|
2024-08-23 14:18:45 -04:00
|
|
|
versions as extract_nodes_versions,
|
2024-08-18 13:22:31 -04:00
|
|
|
)
|
2024-08-20 16:29:19 -04:00
|
|
|
from .invalidate_edges import (
|
2024-08-23 14:18:45 -04:00
|
|
|
Prompt as InvalidateEdgesPrompt,
|
2024-08-22 12:26:13 -07:00
|
|
|
)
|
|
|
|
from .invalidate_edges import (
|
2024-08-23 14:18:45 -04:00
|
|
|
Versions as InvalidateEdgesVersions,
|
2024-08-22 12:26:13 -07:00
|
|
|
)
|
|
|
|
from .invalidate_edges import (
|
2024-08-23 14:18:45 -04:00
|
|
|
versions as invalidate_edges_versions,
|
2024-08-20 16:29:19 -04:00
|
|
|
)
|
2024-08-22 12:26:13 -07:00
|
|
|
from .models import Message, PromptFunction
|
2024-08-20 16:29:19 -04:00
|
|
|
|
2024-08-15 12:03:41 -04:00
|
|
|
|
|
|
|
class PromptLibrary(Protocol):
|
2024-08-23 14:18:45 -04:00
|
|
|
extract_nodes: ExtractNodesPrompt
|
|
|
|
dedupe_nodes: DedupeNodesPrompt
|
|
|
|
extract_edges: ExtractEdgesPrompt
|
|
|
|
dedupe_edges: DedupeEdgesPrompt
|
|
|
|
invalidate_edges: InvalidateEdgesPrompt
|
|
|
|
extract_edge_dates: ExtractEdgeDatesPrompt
|
2024-08-15 12:03:41 -04:00
|
|
|
|
|
|
|
|
|
|
|
class PromptLibraryImpl(TypedDict):
|
2024-08-23 14:18:45 -04:00
|
|
|
extract_nodes: ExtractNodesVersions
|
|
|
|
dedupe_nodes: DedupeNodesVersions
|
|
|
|
extract_edges: ExtractEdgesVersions
|
|
|
|
dedupe_edges: DedupeEdgesVersions
|
|
|
|
invalidate_edges: InvalidateEdgesVersions
|
|
|
|
extract_edge_dates: ExtractEdgeDatesVersions
|
2024-08-15 12:03:41 -04:00
|
|
|
|
|
|
|
|
|
|
|
class VersionWrapper:
|
2024-08-23 14:18:45 -04:00
|
|
|
def __init__(self, func: PromptFunction):
|
|
|
|
self.func = func
|
2024-08-15 12:03:41 -04:00
|
|
|
|
2024-08-23 14:18:45 -04:00
|
|
|
def __call__(self, context: dict[str, Any]) -> list[Message]:
|
|
|
|
return self.func(context)
|
2024-08-15 12:03:41 -04:00
|
|
|
|
|
|
|
|
|
|
|
class PromptTypeWrapper:
|
2024-08-23 14:18:45 -04:00
|
|
|
def __init__(self, versions: dict[str, PromptFunction]):
|
|
|
|
for version, func in versions.items():
|
|
|
|
setattr(self, version, VersionWrapper(func))
|
2024-08-15 12:03:41 -04:00
|
|
|
|
|
|
|
|
|
|
|
class PromptLibraryWrapper:
|
2024-08-23 14:18:45 -04:00
|
|
|
def __init__(self, library: PromptLibraryImpl):
|
|
|
|
for prompt_type, versions in library.items():
|
|
|
|
setattr(self, prompt_type, PromptTypeWrapper(versions)) # type: ignore[arg-type]
|
2024-08-15 12:03:41 -04:00
|
|
|
|
|
|
|
|
|
|
|
PROMPT_LIBRARY_IMPL: PromptLibraryImpl = {
|
2024-08-23 14:18:45 -04:00
|
|
|
'extract_nodes': extract_nodes_versions,
|
|
|
|
'dedupe_nodes': dedupe_nodes_versions,
|
|
|
|
'extract_edges': extract_edges_versions,
|
|
|
|
'dedupe_edges': dedupe_edges_versions,
|
|
|
|
'invalidate_edges': invalidate_edges_versions,
|
|
|
|
'extract_edge_dates': extract_edge_dates_versions,
|
2024-08-15 12:03:41 -04:00
|
|
|
}
|
2024-08-23 08:15:44 -07:00
|
|
|
prompt_library: PromptLibrary = PromptLibraryWrapper(PROMPT_LIBRARY_IMPL) # type: ignore[assignment]
|