-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into cjkindel/gtc_vector_store_driver
- Loading branch information
Showing
42 changed files
with
454 additions
and
128 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
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
9 changes: 4 additions & 5 deletions
9
griptape/common/prompt_stack/contents/base_message_content.py
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,14 @@ | ||
import uuid | ||
from typing import Optional | ||
from attrs import define, field, Factory | ||
from griptape.mixins import SerializableMixin | ||
|
||
|
||
@define(kw_only=True) | ||
class Reference(SerializableMixin): | ||
id: str = field(default=Factory(lambda: uuid.uuid4().hex), metadata={"serializable": True}) | ||
title: str = field(metadata={"serializable": True}) | ||
authors: list[str] = field(factory=list, metadata={"serializable": True}) | ||
source: Optional[str] = field(default=None, metadata={"serializable": True}) | ||
year: Optional[str] = field(default=None, metadata={"serializable": True}) | ||
url: Optional[str] = field(default=None, metadata={"serializable": True}) |
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
18 changes: 18 additions & 0 deletions
18
griptape/engines/rag/modules/response/footnote_prompt_response_rag_module.py
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,18 @@ | ||
from attrs import define | ||
|
||
from griptape import utils | ||
from griptape.artifacts import TextArtifact | ||
from griptape.engines.rag import RagContext | ||
from griptape.engines.rag.modules import PromptResponseRagModule | ||
from griptape.utils import J2 | ||
|
||
|
||
@define(kw_only=True) | ||
class FootnotePromptResponseRagModule(PromptResponseRagModule): | ||
def default_system_template_generator(self, context: RagContext, artifacts: list[TextArtifact]) -> str: | ||
return J2("engines/rag/modules/response/footnote_prompt/system.j2").render( | ||
text_chunk_artifacts=artifacts, | ||
references=utils.references_from_artifacts(artifacts), | ||
before_system_prompt="\n\n".join(context.before_query), | ||
after_system_prompt="\n\n".join(context.after_query), | ||
) |
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
41 changes: 41 additions & 0 deletions
41
griptape/engines/rag/modules/retrieval/text_loader_retrieval_rag_module.py
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,41 @@ | ||
from __future__ import annotations | ||
import uuid | ||
from typing import TYPE_CHECKING, Sequence, Any, Callable | ||
from attrs import define, field, Factory | ||
from griptape import utils | ||
from griptape.artifacts import TextArtifact, ErrorArtifact | ||
from griptape.engines.rag import RagContext | ||
from griptape.engines.rag.modules import BaseRetrievalRagModule | ||
|
||
if TYPE_CHECKING: | ||
from griptape.drivers import BaseVectorStoreDriver | ||
from griptape.loaders import BaseTextLoader | ||
|
||
|
||
@define(kw_only=True) | ||
class TextLoaderRetrievalRagModule(BaseRetrievalRagModule): | ||
loader: BaseTextLoader = field() | ||
vector_store_driver: BaseVectorStoreDriver = field() | ||
source: Any = field() | ||
query_params: dict[str, Any] = field(factory=dict) | ||
process_query_output_fn: Callable[[list[BaseVectorStoreDriver.Entry]], Sequence[TextArtifact]] = field( | ||
default=Factory(lambda: lambda es: [e.to_artifact() for e in es]) | ||
) | ||
|
||
def run(self, context: RagContext) -> Sequence[TextArtifact]: | ||
namespace = uuid.uuid4().hex | ||
context_source = self.get_context_param(context, "source") | ||
source = self.source if context_source is None else context_source | ||
|
||
query_params = utils.dict_merge(self.query_params, self.get_context_param(context, "query_params")) | ||
|
||
query_params["namespace"] = namespace | ||
|
||
loader_output = self.loader.load(source) | ||
|
||
if isinstance(loader_output, ErrorArtifact): | ||
raise Exception(loader_output.to_text() if loader_output.exception is None else loader_output.exception) | ||
else: | ||
self.vector_store_driver.upsert_text_artifacts({namespace: loader_output}) | ||
|
||
return self.process_query_output_fn(self.vector_store_driver.query(context.query, **query_params)) |
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.