diff --git a/rnd/autogpt_builder/src/components/CustomNode.tsx b/rnd/autogpt_builder/src/components/CustomNode.tsx index 5ef11b398..aa06a9b27 100644 --- a/rnd/autogpt_builder/src/components/CustomNode.tsx +++ b/rnd/autogpt_builder/src/components/CustomNode.tsx @@ -7,6 +7,7 @@ import { Button } from './ui/button'; import { Input } from './ui/input'; import { BlockSchema } from '@/lib/types'; import SchemaTooltip from './SchemaTooltip'; +import { beautifyString } from '@/lib/utils'; type CustomNodeData = { blockType: string; @@ -69,12 +70,12 @@ const CustomNode: FC> = ({ data, id }) => { id={key} style={{ background: '#555', borderRadius: '50%', width: '10px', height: '10px' }} /> - {key} + {schema.properties[key].title || beautifyString(key)} )} {type === 'source' && ( <> - {key} + {schema.properties[key].title || beautifyString(key)} > = ({ data, id }) => { setActiveKey(null); }; - const renderInputField = (key: string, schema: any, parentKey: string = ''): JSX.Element => { + const renderInputField = (key: string, schema: any, parentKey: string = '', displayKey: string = ''): JSX.Element => { const fullKey = parentKey ? `${parentKey}.${key}` : key; const error = errors[fullKey]; const value = getValue(fullKey); + if (displayKey === '') { + displayKey = key; + } if (isHandleConnected(fullKey)) { return
Connected
; @@ -167,10 +171,10 @@ const CustomNode: FC> = ({ data, id }) => { if (schema.type === 'object' && schema.properties) { return (
- {key}: + {displayKey}: {Object.entries(schema.properties).map(([propKey, propSchema]: [string, any]) => (
- {renderInputField(propKey, propSchema, fullKey)} + {renderInputField(propKey, propSchema, fullKey, propSchema.title || beautifyString(propKey))}
))}
@@ -181,11 +185,11 @@ const CustomNode: FC> = ({ data, id }) => { const objectValue = value || {}; return (
- {key}: + {displayKey}: {Object.entries(objectValue).map(([propKey, propValue]: [string, any]) => (
handleInputClick(`${fullKey}.${propKey}`)}> - {propKey}: {typeof propValue === 'object' ? JSON.stringify(propValue, null, 2) : propValue} + {beautifyString(propKey)}: {typeof propValue === 'object' ? JSON.stringify(propValue, null, 2) : propValue}
) : (
- {renderClickableInput(value, schema.placeholder || `Enter ${key}`)} + {renderClickableInput(value, schema.placeholder || `Enter ${displayKey}`)} {error && {error}}
); @@ -314,7 +318,7 @@ const CustomNode: FC> = ({ data, id }) => { onChange={(e) => handleInputChange(fullKey, e.target.value === 'true')} className="select-input" > - + @@ -363,7 +367,7 @@ const CustomNode: FC> = ({ data, id }) => { default: return (
- {renderClickableInput(value ? `${key} (Complex)` : null, `Enter ${key} (Complex)`)} + {renderClickableInput(value, schema.placeholder || `Enter ${beautifyString(displayKey)} (Complex)`)} {error && {error}}
); @@ -395,7 +399,7 @@ const CustomNode: FC> = ({ data, id }) => { return (
-
{data.blockType || data.title}
+
{beautifyString(data.blockType?.replace(/Block$/, '') || data.title)}
@@ -411,10 +415,10 @@ const CustomNode: FC> = ({ data, id }) => { id={key} style={{ background: '#555', borderRadius: '50%', width: '10px', height: '10px' }} /> - {key} + {schema.title || beautifyString(key)}
- {renderInputField(key, schema)} + {renderInputField(key, schema, '', schema.title || beautifyString(key))}
); })} diff --git a/rnd/autogpt_builder/src/components/Flow.tsx b/rnd/autogpt_builder/src/components/Flow.tsx index 64d78ba30..1b1bf6640 100644 --- a/rnd/autogpt_builder/src/components/Flow.tsx +++ b/rnd/autogpt_builder/src/components/Flow.tsx @@ -21,6 +21,7 @@ import { Button } from './ui/button'; import { Input } from './ui/input'; import { ChevronRight, ChevronLeft } from "lucide-react"; import { deepEquals } from '@/lib/utils'; +import { beautifyString } from '@/lib/utils'; type CustomNodeData = { @@ -59,7 +60,7 @@ const Sidebar: React.FC<{ isOpen: boolean, availableNodes: Block[], addNode: (id /> {filteredNodes.map((node) => (
- {node.name} + {beautifyString(node.name).replace(/Block$/, '')}
))} diff --git a/rnd/autogpt_builder/src/lib/utils.ts b/rnd/autogpt_builder/src/lib/utils.ts index 0c45fff84..97ff7fcb2 100644 --- a/rnd/autogpt_builder/src/lib/utils.ts +++ b/rnd/autogpt_builder/src/lib/utils.ts @@ -29,3 +29,34 @@ export function deepEquals(x: any, y: any): boolean { : (x === y) ); } + +export function beautifyString(name: string): string { + // Regular expression to identify places to split, considering acronyms + const result = name + .replace(/([a-z])([A-Z])/g, '$1 $2') // Add space before capital letters + .replace(/([A-Z])([A-Z][a-z])/g, '$1 $2') // Add space between acronyms and next word + .replace(/_/g, ' ') // Replace underscores with spaces + .replace(/\b\w/g, char => char.toUpperCase()); // Capitalize the first letter of each word + + return applyExceptions(result); +}; + +const exceptionMap: Record = { + 'Auto GPT': 'AutoGPT', + 'Gpt': 'GPT', + 'Creds': 'Credentials', + 'Id': 'ID', + 'Openai': 'OpenAI', + 'Api': 'API', + 'Url': 'URL', + 'Http': 'HTTP', + 'Json': 'JSON', +}; + +const applyExceptions = (str: string): string => { + Object.keys(exceptionMap).forEach(key => { + const regex = new RegExp(`\\b${key}\\b`, 'g'); + str = str.replace(regex, exceptionMap[key]); + }); + return str; +}; diff --git a/rnd/autogpt_server/autogpt_server/blocks/reddit.py b/rnd/autogpt_server/autogpt_server/blocks/reddit.py index f29c1c364..ec8f88c61 100644 --- a/rnd/autogpt_server/autogpt_server/blocks/reddit.py +++ b/rnd/autogpt_server/autogpt_server/blocks/reddit.py @@ -2,7 +2,7 @@ from datetime import datetime, timezone from typing import Iterator import praw -from pydantic import BaseModel, Field +from pydantic import BaseModel, ConfigDict, Field from autogpt_server.data.block import Block, BlockOutput, BlockSchema from autogpt_server.data.model import BlockSecret, SecretField @@ -16,6 +16,8 @@ class RedditCredentials(BaseModel): password: BlockSecret = SecretField(key="reddit_password") user_agent: str = "AutoGPT:1.0 (by /u/autogpt)" + model_config = ConfigDict(title="Reddit Credentials") + class RedditPost(BaseModel): id: str diff --git a/rnd/autogpt_server/autogpt_server/data/model.py b/rnd/autogpt_server/autogpt_server/data/model.py index 2179cedae..fdd9340eb 100644 --- a/rnd/autogpt_server/autogpt_server/data/model.py +++ b/rnd/autogpt_server/autogpt_server/data/model.py @@ -55,7 +55,6 @@ class BlockSecret: ) -> dict[str, Any]: return { "type": "string", - "title": "BlockSecret", } @classmethod