mirror of
https://github.com/getzep/graphiti.git
synced 2025-07-03 07:05:16 +00:00

* chore: Initial draft of stubs * chore: Add comments and mock implementation of the add_episode method * chore: Add success and error callbacks * chore: Add success and error callbacks * refactor: Fix conflicts with the latest merge
54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
from typing import TypedDict, Protocol
|
|
from .models import Message, PromptFunction
|
|
from typing import TypedDict, Protocol
|
|
from .models import Message, PromptFunction
|
|
from .extract_nodes import (
|
|
Prompt as ExtractNodesPrompt,
|
|
Versions as ExtractNodesVersions,
|
|
versions as extract_nodes_versions,
|
|
)
|
|
|
|
from .extract_edges import (
|
|
Prompt as ExtractEdgesPrompt,
|
|
Versions as ExtractEdgesVersions,
|
|
versions as extract_edges_versions,
|
|
)
|
|
|
|
|
|
class PromptLibrary(Protocol):
|
|
extract_nodes: ExtractNodesPrompt
|
|
extract_edges: ExtractEdgesPrompt
|
|
|
|
|
|
class PromptLibraryImpl(TypedDict):
|
|
extract_nodes: ExtractNodesVersions
|
|
extract_edges: ExtractEdgesVersions
|
|
|
|
|
|
class VersionWrapper:
|
|
def __init__(self, func: PromptFunction):
|
|
self.func = func
|
|
|
|
def __call__(self, context: dict[str, any]) -> list[Message]:
|
|
return self.func(context)
|
|
|
|
|
|
class PromptTypeWrapper:
|
|
def __init__(self, versions: dict[str, PromptFunction]):
|
|
for version, func in versions.items():
|
|
setattr(self, version, VersionWrapper(func))
|
|
|
|
|
|
class PromptLibraryWrapper:
|
|
def __init__(self, library: PromptLibraryImpl):
|
|
for prompt_type, versions in library.items():
|
|
setattr(self, prompt_type, PromptTypeWrapper(versions))
|
|
|
|
|
|
PROMPT_LIBRARY_IMPL: PromptLibraryImpl = {
|
|
"extract_nodes": extract_nodes_versions,
|
|
"extract_edges": extract_edges_versions,
|
|
}
|
|
|
|
prompt_library: PromptLibrary = PromptLibraryWrapper(PROMPT_LIBRARY_IMPL)
|