-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d987f1a
commit 8fa35a5
Showing
64 changed files
with
2,930 additions
and
575 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from __future__ import annotations | ||
|
||
from attrs import define, field | ||
from typing import TYPE_CHECKING | ||
|
||
from griptape.artifacts import BaseArtifact | ||
from griptape.mixins import SerializableMixin | ||
|
||
if TYPE_CHECKING: | ||
from griptape.common import ToolAction | ||
|
||
|
||
@define() | ||
class ActionArtifact(BaseArtifact, SerializableMixin): | ||
value: ToolAction = field(metadata={"serializable": True}) | ||
|
||
def __add__(self, other: BaseArtifact) -> ActionArtifact: | ||
raise NotImplementedError |
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
Empty 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from griptape.mixins import SerializableMixin | ||
from abc import ABC | ||
|
||
|
||
class BaseAction(SerializableMixin, ABC): ... |
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,54 @@ | ||
from __future__ import annotations | ||
import json | ||
from typing import TYPE_CHECKING, Optional | ||
|
||
from attrs import define, field | ||
|
||
from griptape.artifacts import BaseArtifact | ||
from griptape.common import BaseAction | ||
|
||
if TYPE_CHECKING: | ||
from griptape.tools import BaseTool | ||
|
||
|
||
@define(kw_only=True) | ||
class ToolAction(BaseAction): | ||
"""Represents an instance of an LLM using a Tool. | ||
Attributes: | ||
tag: The tag (unique identifier) of the action. | ||
name: The name (Tool name) of the action. | ||
path: The path (Tool activity name) of the action. | ||
input: The input (Tool params) of the action. | ||
tool: The matched Tool of the action. | ||
output: The output (Tool result) of the action. | ||
""" | ||
|
||
tag: str = field(metadata={"serializable": True}) | ||
name: str = field(metadata={"serializable": True}) | ||
path: Optional[str] = field(default=None, metadata={"serializable": True}) | ||
input: dict = field(factory=dict, metadata={"serializable": True}) | ||
tool: Optional[BaseTool] = field(default=None) | ||
output: Optional[BaseArtifact] = field(default=None) | ||
|
||
def __str__(self) -> str: | ||
return json.dumps(self.to_dict()) | ||
|
||
def to_native_tool_name(self) -> str: | ||
parts = [self.name] | ||
|
||
if self.path is not None: | ||
parts.append(self.path) | ||
|
||
return "_".join(parts) | ||
|
||
@classmethod | ||
def from_native_tool_name(cls, native_tool_name: str) -> tuple[str, Optional[str]]: | ||
parts = native_tool_name.split("_", 1) | ||
|
||
if len(parts) == 1: | ||
name, path = parts[0], None | ||
else: | ||
name, path = parts | ||
|
||
return name, path |
31 changes: 31 additions & 0 deletions
31
griptape/common/prompt_stack/contents/action_call_delta_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from __future__ import annotations | ||
from attrs import define, field | ||
from typing import Optional | ||
|
||
from griptape.common import BaseDeltaMessageContent | ||
|
||
|
||
@define | ||
class ActionCallDeltaMessageContent(BaseDeltaMessageContent): | ||
tag: Optional[str] = field(default=None, metadata={"serializable": True}) | ||
name: Optional[str] = field(default=None, metadata={"serializable": True}) | ||
path: Optional[str] = field(default=None, metadata={"serializable": True}) | ||
partial_input: Optional[str] = field(default=None, metadata={"serializable": True}) | ||
|
||
def __str__(self) -> str: | ||
parts = [] | ||
|
||
if self.name: | ||
parts.append(self.name) | ||
if self.path: | ||
parts.append(f".{self.path}") | ||
if self.tag: | ||
parts.append(f" ({self.tag})") | ||
|
||
if self.partial_input: | ||
if parts: | ||
parts.append(f" {self.partial_input}") | ||
else: | ||
parts.append(self.partial_input) | ||
|
||
return "".join(parts) |
47 changes: 47 additions & 0 deletions
47
griptape/common/prompt_stack/contents/action_call_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
from collections.abc import Sequence | ||
|
||
from attrs import define, field | ||
|
||
from griptape.common import ToolAction | ||
from griptape.artifacts import ActionArtifact | ||
from griptape.common import BaseDeltaMessageContent, BaseMessageContent, ActionCallDeltaMessageContent | ||
|
||
|
||
@define | ||
class ActionCallMessageContent(BaseMessageContent): | ||
artifact: ActionArtifact = field(metadata={"serializable": True}) | ||
|
||
@classmethod | ||
def from_deltas(cls, deltas: Sequence[BaseDeltaMessageContent]) -> ActionCallMessageContent: | ||
action_call_deltas = [delta for delta in deltas if isinstance(delta, ActionCallDeltaMessageContent)] | ||
|
||
tag = None | ||
name = None | ||
path = None | ||
input = "" | ||
|
||
for delta in action_call_deltas: | ||
if delta.tag is not None: | ||
tag = delta.tag | ||
if delta.name is not None: | ||
name = delta.name | ||
if delta.path is not None: | ||
path = delta.path | ||
if delta.partial_input is not None: | ||
input += delta.partial_input | ||
|
||
if tag is not None and name is not None and path is not None: | ||
try: | ||
parsed_input = json.loads(input) | ||
except json.JSONDecodeError as exc: | ||
raise ValueError("Invalid JSON input for ToolAction") from exc | ||
action = ToolAction(tag=tag, name=name, path=path, input=parsed_input) | ||
else: | ||
raise ValueError("Missing required fields for ToolAction") | ||
|
||
artifact = ActionArtifact(value=action) | ||
|
||
return cls(artifact=artifact) |
18 changes: 18 additions & 0 deletions
18
griptape/common/prompt_stack/contents/action_result_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from __future__ import annotations | ||
|
||
from collections.abc import Sequence | ||
|
||
from attrs import define, field | ||
|
||
from griptape.artifacts import BaseArtifact | ||
from griptape.common import BaseDeltaMessageContent, BaseMessageContent, ToolAction | ||
|
||
|
||
@define | ||
class ActionResultMessageContent(BaseMessageContent): | ||
artifact: BaseArtifact = field(metadata={"serializable": True}) | ||
action: ToolAction = field(metadata={"serializable": True}) | ||
|
||
@classmethod | ||
def from_deltas(cls, deltas: Sequence[BaseDeltaMessageContent]) -> ActionResultMessageContent: | ||
raise NotImplementedError |
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Optional | ||
|
||
from attrs import define, field | ||
|
||
from griptape.common.prompt_stack.contents.text_delta_message_content import TextDeltaMessageContent | ||
|
||
from griptape.common import BaseDeltaMessageContent | ||
|
||
from .base_message import BaseMessage | ||
|
||
|
||
@define | ||
class DeltaMessage(BaseMessage): | ||
role: Optional[str] = field(kw_only=True, default=None, metadata={"serializable": True}) | ||
content: Optional[TextDeltaMessageContent] = field(kw_only=True, default=None, metadata={"serializable": True}) | ||
content: Optional[BaseDeltaMessageContent] = field(kw_only=True, default=None, metadata={"serializable": True}) |
Oops, something went wrong.