-
Notifications
You must be signed in to change notification settings - Fork 46.2k
feat(blocks): add text encoder block #11313
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
Open
aryancodes1
wants to merge
12
commits into
Significant-Gravitas:dev
Choose a base branch
from
aryancodes1:fix/issue-#11111
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+53
−0
Open
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
41e8756
added-encoder
aryancodes1 e038b71
Merge branch 'dev' into fix/issue-#11111
aryancodes1 5436295
fixed-encoder
aryancodes1 8e743ee
added
aryancodes1 75fd130
add-feature
aryancodes1 c2d7af3
fix encoder
aryancodes1 af25f92
new-fix
aryancodes1 d4e99b9
made-changes
aryancodes1 2f73700
Merge branch 'dev' into fix/issue-#11111
aryancodes1 f16eedc
changed-uuid
aryancodes1 6373945
changed uuid
aryancodes1 68ef264
changed uuid
aryancodes1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,53 @@ | ||
| from backend.data.block import ( | ||
| Block, | ||
| BlockCategory, | ||
| BlockOutput, | ||
| BlockSchemaInput, | ||
| BlockSchemaOutput, | ||
| ) | ||
| from backend.data.model import SchemaField | ||
|
|
||
|
|
||
| class TextEncoderBlock(Block): | ||
| class Input(BlockSchemaInput): | ||
| text: str = SchemaField( | ||
| description="A string to be encoded with escape sequences", | ||
| placeholder='Your text with newlines and "quotes" to be escaped', | ||
| ) | ||
|
|
||
| class Output(BlockSchemaOutput): | ||
| encoded_text: str = SchemaField( | ||
| description="The encoded text with escape sequences added" | ||
| ) | ||
|
|
||
| def __init__(self): | ||
| super().__init__( | ||
| id="a1b2c3d4-e5f6-4789-a012-3456789abcde", | ||
| description="Encodes a string by adding escape sequences for special characters", | ||
This comment was marked as outdated.
Sorry, something went wrong. |
||
| categories={BlockCategory.TEXT}, | ||
| input_schema=TextEncoderBlock.Input, | ||
| output_schema=TextEncoderBlock.Output, | ||
| test_input={ | ||
| "text": """Hello | ||
| World! | ||
| This is a "quoted" string.""" | ||
| }, | ||
| test_output=[ | ||
| ( | ||
| "encoded_text", | ||
| """Hello\\nWorld!\\nThis is a \\"quoted\\" string.""", | ||
| ) | ||
| ], | ||
| ) | ||
|
|
||
| async def run(self, input_data: Input, **kwargs) -> BlockOutput: | ||
| # Escape only common special characters, preserving unicode characters | ||
| encoded_text = ( | ||
| input_data.text.replace("\\", "\\\\") # Escape backslashes first | ||
| .replace("\n", "\\n") # Escape newlines | ||
| .replace("\r", "\\r") # Escape carriage returns | ||
| .replace("\t", "\\t") # Escape tabs | ||
| .replace('"', '\\"') # Escape double quotes | ||
| .replace("'", "\\'") # Escape single quotes | ||
| ) | ||
| yield "encoded_text", encoded_text | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@cursor regenrate this block id using python's uuid function for a v4 uuid
Uh oh!
There was an error while loading. Please reload this page.
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.
@ntindle I updated the block ID with a v4 uuid