Skip to content

Commit 635fa7a

Browse files
committed
fix: limit prompts to 1000 characters
1 parent 6d5a63c commit 635fa7a

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

decart/models.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,29 @@ class ModelDefinition(DecartBaseModel):
3232

3333

3434
class TextToVideoInput(BaseModel):
35-
prompt: str = Field(..., min_length=1)
35+
prompt: str = Field(..., min_length=1, max_length=1000)
3636
seed: Optional[int] = None
3737
resolution: Optional[str] = None
3838
orientation: Optional[str] = None
3939

4040

4141
class ImageToVideoInput(DecartBaseModel):
42-
prompt: str = Field(..., min_length=1)
42+
prompt: str = Field(
43+
...,
44+
min_length=1,
45+
max_length=1000,
46+
)
4347
data: FileInput
4448
seed: Optional[int] = None
4549
resolution: Optional[str] = None
4650

4751

4852
class VideoToVideoInput(DecartBaseModel):
49-
prompt: str = Field(..., min_length=1)
53+
prompt: str = Field(
54+
...,
55+
min_length=1,
56+
max_length=1000,
57+
)
5058
data: FileInput
5159
seed: Optional[int] = None
5260
resolution: Optional[str] = None
@@ -55,7 +63,11 @@ class VideoToVideoInput(DecartBaseModel):
5563

5664

5765
class FirstLastFrameInput(DecartBaseModel):
58-
prompt: str = Field(..., min_length=1)
66+
prompt: str = Field(
67+
...,
68+
min_length=1,
69+
max_length=1000,
70+
)
5971
start: FileInput
6072
end: FileInput
6173
seed: Optional[int] = None
@@ -70,14 +82,22 @@ class ImageToMotionVideoInput(DecartBaseModel):
7082

7183

7284
class TextToImageInput(BaseModel):
73-
prompt: str = Field(..., min_length=1)
85+
prompt: str = Field(
86+
...,
87+
min_length=1,
88+
max_length=1000,
89+
)
7490
seed: Optional[int] = None
7591
resolution: Optional[str] = None
7692
orientation: Optional[str] = None
7793

7894

7995
class ImageToImageInput(DecartBaseModel):
80-
prompt: str = Field(..., min_length=1)
96+
prompt: str = Field(
97+
...,
98+
min_length=1,
99+
max_length=1000,
100+
)
81101
data: FileInput
82102
seed: Optional[int] = None
83103
resolution: Optional[str] = None

tests/test_process.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,22 @@ async def test_process_video_to_video() -> None:
8787
assert result == b"fake video data"
8888

8989

90+
@pytest.mark.asyncio
91+
async def test_process_max_prompt_length() -> None:
92+
client = DecartClient(api_key="test-key")
93+
prompt = "a" * 1001
94+
with pytest.raises(DecartSDKError) as exception:
95+
await client.process(
96+
{
97+
"model": models.image("lucy-pro-t2i"),
98+
"prompt": prompt,
99+
}
100+
)
101+
assert f"Invalid inputs for lucy-pro-t2i: 1 validation error for TextToImageInput" in str(
102+
exception
103+
)
104+
105+
90106
@pytest.mark.asyncio
91107
async def test_process_image_to_motion_video() -> None:
92108
client = DecartClient(api_key="test-key")

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)