-
Notifications
You must be signed in to change notification settings - Fork 18.3k
feat(core): add helpers to make content block shaped dicts #32072
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
CodSpeed WallTime Performance ReportMerging #32072 will not alter performanceComparing
|
CodSpeed Instrumentation Performance ReportMerging #32072 will not alter performanceComparing Summary
|
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.
Same with all of the below ones, want to get the return types right
@@ -69,6 +69,26 @@ class TextContentBlock(TypedDict): | |||
"""Citations and other annotations.""" | |||
|
|||
|
|||
def make_text_block( | |||
text: str, annotations: Optional[list[dict[str, Any]]] = None | |||
) -> dict[str, Any]: |
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.
) -> dict[str, Any]: | |
) -> TextContentBlock: |
@@ -83,6 +103,22 @@ class ToolCallContentBlock(TypedDict): | |||
"""Tool call ID.""" | |||
|
|||
|
|||
def make_tool_call_block( | |||
tool_call_id: str, | |||
) -> dict[str, Any]: |
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.
) -> dict[str, Any]: | |
) -> ToolCallContentBlock: |
@@ -93,6 +129,22 @@ class ReasoningContentBlock(TypedDict): | |||
"""Reasoning text.""" | |||
|
|||
|
|||
def make_reasoning_block( | |||
reasoning: Optional[str] = None, | |||
) -> dict[str, Any]: |
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.
) -> dict[str, Any]: | |
) -> ReasoningContentBlock: |
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.
Ignore me, this all makes sense. Thanks!
I envision these being used in partner packages to have a standard implementation for making content block dicts that conform to the expected shape that will eventually be needed for casting.
Without these, making the dicts would be more error-prone (e.g. forgetting required fields which might lead to future issues). Additionally, without these we'd need to constantly refer to the TypedDict definitions to remember the exact structure, required keys, and valid type literals for each block. These have intellisense autocomplete.
This also helps maintainability in case the schema of a block changes, e.g. renaming or nesting a key.