Skip to content

Commit dd7a25a

Browse files
authored
feat(http): add configurable request timeouts (#35)
* feat(http): add configurable request timeouts - Add timeout parameter to RequestSpec - Implement timeout hierarchy: 1. Request spec timeout 2. Parameter timeout 3. Generator default timeout - Add proper timeout forwarding to httpx client - Fix spacing in message trace formatting This change enables fine-grained control over HTTP request timeouts at multiple configuration levels while maintaining backward compatibility. * chore: added typing support
1 parent faafea5 commit dd7a25a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

rigging/generator/http.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class RequestSpec(BaseModel):
101101
url: str
102102
method: str = "POST"
103103
headers: dict[str, str] = {}
104+
timeout: int | None = None
104105
transforms: list[TransformStep[InputTransform]] = Field(min_length=1)
105106

106107

@@ -308,12 +309,22 @@ async def _generate_message(
308309
model=self.model,
309310
)
310311

312+
# Conditionally set the timeout to avoid overriding the default "unset" value
313+
kwargs: dict[str, t.Any] = {}
314+
if self.spec.request.timeout is not None:
315+
kwargs["timeout"] = self.spec.request.timeout
316+
elif params.timeout is not None:
317+
kwargs["timeout"] = params.timeout
318+
elif self.params.timeout is not None:
319+
kwargs["timeout"] = self.params.timeout
320+
311321
async with httpx.AsyncClient() as client:
312322
response = await client.request(
313323
self.spec.request.method,
314324
self.spec.make_url(context),
315325
content=self.spec.make_request_body(context),
316326
headers=self.spec.make_headers(context),
327+
**kwargs,
317328
)
318329

319330
content = response.text

0 commit comments

Comments
 (0)