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
|
|
|
|
Gemini support (#324)
* first cut
* Update dependencies and enhance README for optional LLM providers
- Bump aiohttp version from 3.11.14 to 3.11.16
- Update yarl version from 1.18.3 to 1.19.0
- Modify pyproject.toml to include optional extras for Anthropic, Groq, and Google Gemini
- Revise README.md to reflect new optional LLM provider installation instructions and clarify API key requirements
* Remove deprecated packages from poetry.lock and update content hash
- Removed cachetools, google-auth, google-genai, pyasn1, pyasn1-modules, rsa, and websockets from the lock file.
- Added new extras for anthropic, google-genai, and groq.
- Updated content hash to reflect changes.
* Refactor import paths for GeminiClient in README and __init__.py
- Updated import statement in README.md to reflect the new module structure for GeminiClient.
- Removed GeminiClient from the __all__ list in __init__.py as it is no longer directly imported.
* Refactor import paths for GeminiEmbedder in README and __init__.py
- Updated import statement in README.md to reflect the new module structure for GeminiEmbedder.
- Removed GeminiEmbedder and GeminiEmbedderConfig from the __all__ list in __init__.py as they are no longer directly imported.
2025-04-06 09:27:04 -07:00
|
|
|
from .dedupe_edges import Prompt as DedupeEdgesPrompt
|
|
|
|
from .dedupe_edges import Versions as DedupeEdgesVersions
|
|
|
|
from .dedupe_edges import versions as dedupe_edges_versions
|
|
|
|
from .dedupe_nodes import Prompt as DedupeNodesPrompt
|
|
|
|
from .dedupe_nodes import Versions as DedupeNodesVersions
|
|
|
|
from .dedupe_nodes import versions as dedupe_nodes_versions
|
2024-09-26 16:12:38 -04:00
|
|
|
from .eval import Prompt as EvalPrompt
|
|
|
|
from .eval import Versions as EvalVersions
|
|
|
|
from .eval import versions as eval_versions
|
Gemini support (#324)
* first cut
* Update dependencies and enhance README for optional LLM providers
- Bump aiohttp version from 3.11.14 to 3.11.16
- Update yarl version from 1.18.3 to 1.19.0
- Modify pyproject.toml to include optional extras for Anthropic, Groq, and Google Gemini
- Revise README.md to reflect new optional LLM provider installation instructions and clarify API key requirements
* Remove deprecated packages from poetry.lock and update content hash
- Removed cachetools, google-auth, google-genai, pyasn1, pyasn1-modules, rsa, and websockets from the lock file.
- Added new extras for anthropic, google-genai, and groq.
- Updated content hash to reflect changes.
* Refactor import paths for GeminiClient in README and __init__.py
- Updated import statement in README.md to reflect the new module structure for GeminiClient.
- Removed GeminiClient from the __all__ list in __init__.py as it is no longer directly imported.
* Refactor import paths for GeminiEmbedder in README and __init__.py
- Updated import statement in README.md to reflect the new module structure for GeminiEmbedder.
- Removed GeminiEmbedder and GeminiEmbedderConfig from the __all__ list in __init__.py as they are no longer directly imported.
2025-04-06 09:27:04 -07:00
|
|
|
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
|
|
|
|
from .extract_edges import Prompt as ExtractEdgesPrompt
|
|
|
|
from .extract_edges import Versions as ExtractEdgesVersions
|
|
|
|
from .extract_edges import versions as extract_edges_versions
|
|
|
|
from .extract_nodes import Prompt as ExtractNodesPrompt
|
|
|
|
from .extract_nodes import Versions as ExtractNodesVersions
|
|
|
|
from .extract_nodes import versions as extract_nodes_versions
|
|
|
|
from .invalidate_edges import Prompt as InvalidateEdgesPrompt
|
|
|
|
from .invalidate_edges import Versions as InvalidateEdgesVersions
|
|
|
|
from .invalidate_edges import versions as invalidate_edges_versions
|
2024-08-22 12:26:13 -07:00
|
|
|
from .models import Message, PromptFunction
|
2024-12-03 11:52:49 -05:00
|
|
|
from .prompt_helpers import DO_NOT_ESCAPE_UNICODE
|
2024-09-11 12:06:35 -04:00
|
|
|
from .summarize_nodes import Prompt as SummarizeNodesPrompt
|
|
|
|
from .summarize_nodes import Versions as SummarizeNodesVersions
|
|
|
|
from .summarize_nodes import versions as summarize_nodes_versions
|
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-09-11 12:06:35 -04:00
|
|
|
summarize_nodes: SummarizeNodesPrompt
|
2024-09-26 16:12:38 -04:00
|
|
|
eval: EvalPrompt
|
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-09-11 12:06:35 -04:00
|
|
|
summarize_nodes: SummarizeNodesVersions
|
2024-09-26 16:12:38 -04:00
|
|
|
eval: EvalVersions
|
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]:
|
2024-12-03 11:52:49 -05:00
|
|
|
messages = self.func(context)
|
|
|
|
for message in messages:
|
|
|
|
message.content += DO_NOT_ESCAPE_UNICODE if message.role == 'system' else ''
|
|
|
|
return messages
|
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-09-11 12:06:35 -04:00
|
|
|
'summarize_nodes': summarize_nodes_versions,
|
2024-09-26 16:12:38 -04:00
|
|
|
'eval': eval_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]
|