Skip to content

Commit b8f543d

Browse files
authored
Merge pull request #1 from browserbase/main
merge to latest
2 parents b17e534 + 1a919ad commit b8f543d

5 files changed

Lines changed: 31 additions & 6 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"stagehand": patch
3+
---
4+
5+
Fix ability to pass raw JSON to Extract schema
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"stagehand": patch
3+
---
4+
5+
Pass api_timeout param to Stagehand API correctly

stagehand/api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ async def _create_session(self):
2727
else None
2828
)
2929

30+
# API requires timeout while python sdk uses api_timeout which is converted to apiTimeout
31+
if (
32+
browserbase_session_create_params
33+
and "apiTimeout" in browserbase_session_create_params
34+
):
35+
browserbase_session_create_params["timeout"] = (
36+
browserbase_session_create_params.pop("apiTimeout")
37+
)
38+
3039
payload = {
3140
"modelName": self.model_name,
3241
"verbose": 2 if self.verbose == 3 else self.verbose,

stagehand/handlers/extract_handler.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ async def extract(
151151

152152
processed_data_payload = raw_data_dict # Default to the raw dictionary
153153

154-
if schema and isinstance(
155-
raw_data_dict, dict
156-
): # schema is the Pydantic model type
154+
if schema and isinstance(schema, type) and issubclass(schema, BaseModel):
157155
# Try direct validation first
158156
try:
159157
validated_model_instance = schema.model_validate(raw_data_dict)

stagehand/llm/inference.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,19 @@ async def extract(
169169
start_time = time.time()
170170

171171
# Determine if we need to use schema-based response format
172-
# TODO: if schema is json, return json
173172
response_format = {"type": "json_object"}
174173
if schema:
175-
# If schema is a Pydantic model, use it directly
176-
response_format = schema
174+
if isinstance(schema, dict):
175+
response_format = {
176+
"type": "json_schema",
177+
"json_schema": {
178+
"name": "extraction_schema",
179+
"strict": False,
180+
"schema": schema,
181+
},
182+
}
183+
else:
184+
response_format = schema
177185

178186
# Call the LLM with appropriate parameters
179187
try:

0 commit comments

Comments
 (0)