This commit is contained in:
2025-09-01 06:43:11 +02:00
parent bde3fc0df9
commit 45eb2b8bc5
38 changed files with 3424 additions and 915 deletions

View File

@@ -23,8 +23,11 @@ This is a multi-agent roleplay system implementing Stanford's "Generative Agents
### UI Framework
- **NiceGUI** for web interface (async components)
- **AsyncElement base class**: Never override __init__, use create() factory method and implement build()
- **Dialog support**: Can create elements as dialogs with as_dialog()
- **AsyncElement base class**: Simplified async UI component pattern
- Constructor accepts element_type (default: ui.column) and element args/kwargs
- Implement build() method for async initialization logic
- Use create() factory method which returns the NiceGUI element directly
- Supports method chaining on the returned element
- Pages are created in pages/ directory, main page is MainPage
## Development Commands
@@ -48,10 +51,36 @@ uv python pin 3.12 # Pin to Python 3.12
### AsyncElement Usage
When creating UI components that extend AsyncElement:
- NEVER override the __init__ method
- Always use the `create()` factory method: `await MyComponent.create(params)`
- Implement the `build()` method for initialization logic
- Pass parameters through build(), not __init__
```python
class MyComponent(AsyncElement):
async def build(self, param1: str, param2: int, *args, **kwargs) -> None:
# Build content directly in self.element
with self.element:
ui.label(f'{param1}: {param2}')
# Add more UI elements...
# Usage - create() returns the NiceGUI element directly, supports method chaining
(await MyComponent.create(element_type=ui.card, param1="test", param2=123)).classes('w-full')
# Can specify different element types
(await MyComponent.create(element_type=ui.row, param1="test", param2=456)).classes('gap-4')
# Pass element constructor args/kwargs via special keys
await MyComponent.create(
element_type=ui.column,
element_args=(), # Positional args for element constructor
element_kwargs={'classes': 'p-4'}, # Kwargs for element constructor
param1="test", # Build method parameters
param2=789
)
```
Key points:
- Constructor accepts element_type (default: ui.column) and element args/kwargs
- build() method receives component-specific parameters
- create() factory method returns the NiceGUI element directly (not the AsyncElement instance)
- Supports method chaining on the returned element
- Use `with self.element:` context manager to add content in build()
### LLM Integration
The project has two LLM integration approaches: