Skip to content

feat(realtime): add unified set() method for prompt + image#24

Open
AdirAmsalem wants to merge 5 commits intomainfrom
feat/unified-set-method
Open

feat(realtime): add unified set() method for prompt + image#24
AdirAmsalem wants to merge 5 commits intomainfrom
feat/unified-set-method

Conversation

@AdirAmsalem
Copy link
Contributor

Summary

  • Adds a unified set() method to RealtimeClient that atomically sends prompt and/or image in a single wire message (type: "set" / set_ack)
  • Uses a sentinel pattern (_Unset) to distinguish "not provided" (omit from wire) from None (clear the value)
  • Uses Pydantic's exclude_unset=True serialization so only explicitly set fields are sent on the wire
  • Keeps existing set_prompt() and set_image() for backward compatibility

API

# Prompt only
await client.set(prompt="a cat in space")

# Prompt + enhance
await client.set(prompt="a cat", enhance=True)

# Image only (bytes, Path, URL, or file-like)
await client.set(image=Path("ref.png"))

# Prompt + image together (atomic)
await client.set(prompt="a cat", image=b"...")

# Clear image
await client.set(image=None)

Wire Protocol

→ {"type": "set", "prompt": "a cat", "enhance_prompt": true, "image_data": "base64..."}
← {"type": "set_ack", "success": true, "error": null}

Omitted fields = no change. null = clear.

Changes

  • decart/realtime/messages.py — Added SetParamsMessage, SetAckMessage, updated message unions, exclude_unset serialization
  • decart/realtime/webrtc_connection.py — Added set_ack handling, register_set_wait/unregister_set_wait
  • decart/realtime/webrtc_manager.py — Pass-through for set wait registration
  • decart/realtime/client.py — Added set() method with sentinel pattern, validation, image conversion
  • tests/test_realtime_unit.py — 11 new tests (93 total passing)
  • examples/ — Updated to use set() as primary API

Companion to JS SDK PR: DecartAI/sdk#76

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant