-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor prompt stack #861
Conversation
1767a83
to
a53762d
Compare
|
||
@classmethod | ||
def from_deltas(cls, deltas: Sequence[BaseDeltaPromptStackContent]) -> TextPromptStackContent: | ||
text_deltas = [delta for delta in deltas if isinstance(delta, TextDeltaPromptStackContent)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this silently fail if its not the right type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow -- this will not silently fail as it currently is.
if isinstance(content, str): | ||
content = [TextPromptStackContent(TextArtifact(value=content))] | ||
self.__attrs_init__(content, **kwargs) # pyright: ignore[reportAttributeAccessIssue] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could use an attrs converter
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's a good way to use a converter and get proper type hints. With a converter, you'll get yelled at for trying to pass in a string. And updating the field's type hints leads down a path of Union
s everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it
griptape/common/prompt_stack/messages/delta_prompt_stack_message.py
Outdated
Show resolved
Hide resolved
content = [TextPromptStackContent(TextArtifact(value=content))] | ||
self.__attrs_init__(content, **kwargs) # pyright: ignore[reportAttributeAccessIssue] | ||
|
||
content: list[BasePromptStackContent] = field(metadata={"serializable": True}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's stopping us from replacing this with artifacts: list[BaseArtifacts]
?
Is BasePromptStackContent
more than a wrapper for BaseArtifact
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went back and forth on this a million times. In this PR, yeah it's not much more. But the upcoming function calling PR, for instance, has an ActionResultPromptStackContent
that contains an artifact and some metadata about the action.
Additionally, to quote something @vasinov said:
I think the reason we wanted to keep it separate is because artifacts are a pretty clean abstraction for data passing. In the PromptStack inputs really are elements that currently somewhat match artifacts but we don't know if that's going to hold true in the future. It would also be much easier to add API-specific elements if an API requires it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way to avoid creating a PromptStackContent
for each type of Artifact
? Could there be like a Non-ActionResultPromptStackContent
that just contains any artifact?
griptape/common/prompt_stack/messages/base_prompt_stack_message.py
Outdated
Show resolved
Hide resolved
6dcf841
to
c725b94
Compare
a0a5391
to
032bc04
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments and a couple of topics for discussion
content = [TextPromptStackContent(TextArtifact(value=content))] | ||
self.__attrs_init__(content, **kwargs) # pyright: ignore[reportAttributeAccessIssue] | ||
|
||
content: list[BasePromptStackContent] = field(metadata={"serializable": True}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way to avoid creating a PromptStackContent
for each type of Artifact
? Could there be like a Non-ActionResultPromptStackContent
that just contains any artifact?
9611162
to
f3033bd
Compare
f3033bd
to
52ea784
Compare
17b59cc
to
29dfb0f
Compare
29dfb0f
to
7802c11
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
81afadb
to
44d54dc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥮
Added
Message
for storing messages in aMessageStack
. Messages consist of a role, content, and usage.DeltaMessage
for storing partial messages in aMessageStack
. MultipleDeltaMessage
can be combined to form aMessage
.TextMessageContent
for storing textual content in aMessage
.ImageMessageContent
for storing image content in aMessage
.TextArtifact
s,ImageArtifact
s, andListArtifact
s toMessageStack
.OpenAiChatPromptDriver
,AzureOpenAiChatPromptDriver
,AmazonBedrockPromptDriver
,AnthropicPromptDriver
, andGooglePromptDriver
.FinishPromptEvent.input_token_count
andFinishPromptEvent.output_token_count
.Agent.input
for passing Artifacts as input.PromptTask
s to takeTextArtifact
s,ImageArtifact
s, andListArtifact
s as input.Changed
griptape.utils.PromptStack
togriptape.common.MessageStack
.PromptStack.inputs
toPromptStack.messages
.PromptStack.USER_ROLE
,PromptStack.ASSISTANT_ROLE
, andPromptStack.SYSTEM_ROLE
toMessage
.PromptDriver.try_run
fromTextArtifact
toMessage
.PromptDriver.try_stream
fromIterator[TextArtifact]
toIterator[DeltaMessage]
.BasePromptEvent.token_count
in favor ofFinishPromptEvent.input_token_count
andFinishPromptEvent.output_token_count
.StartPromptEvent.prompt
. UseStartPromptEvent.message_stack
instead.Agent.input_template
in favor ofAgent.input
.GoogleStructureConfig
togemini-1.5-pro
.Closes #712
📚 Documentation preview 📚: https://griptape--861.org.readthedocs.build//861/