@@ -1354,19 +1354,33 @@ def with_structured_output(
1354
1354
)
1355
1355
is_pydantic_schema = _is_pydantic_class (schema )
1356
1356
1357
- # Check for Pydantic BaseModel V1
1358
- if (
1359
- method == "json_schema"
1360
- and is_pydantic_schema
1361
- and issubclass (schema , BaseModelV1 ) # type: ignore[arg-type]
1362
- ):
1363
- warnings .warn (
1364
- "Received a Pydantic BaseModel V1 schema. This is not supported by "
1365
- 'method="json_schema". Please use method="function_calling" '
1366
- "or specify schema via JSON Schema or Pydantic V2 BaseModel. "
1367
- 'Overriding to method="function_calling".'
1368
- )
1369
- method = "function_calling"
1357
+ if method == "json_schema" :
1358
+ # Check for Pydantic BaseModel V1
1359
+ if (
1360
+ is_pydantic_schema and issubclass (schema , BaseModelV1 ) # type: ignore[arg-type]
1361
+ ):
1362
+ warnings .warn (
1363
+ "Received a Pydantic BaseModel V1 schema. This is not supported by "
1364
+ 'method="json_schema". Please use method="function_calling" '
1365
+ "or specify schema via JSON Schema or Pydantic V2 BaseModel. "
1366
+ 'Overriding to method="function_calling".'
1367
+ )
1368
+ method = "function_calling"
1369
+ # Check for incompatible model
1370
+ if self .model_name and (
1371
+ self .model_name .startswith ("gpt-3" )
1372
+ or self .model_name .startswith ("gpt-4-" )
1373
+ or self .model_name == "gpt-4"
1374
+ ):
1375
+ warnings .warn (
1376
+ f"Cannot use method='json_schema' with model { self .model_name } "
1377
+ f"since it doesn't support OpenAI's Structured Output API. You can "
1378
+ f"see supported models here: "
1379
+ f"https://platform.openai.com/docs/guides/structured-outputs#supported-models. " # noqa: E501
1380
+ "To fix this warning, set `method='function_calling'. "
1381
+ "Overriding to method='function_calling'."
1382
+ )
1383
+ method = "function_calling"
1370
1384
1371
1385
if method == "function_calling" :
1372
1386
if schema is None :
0 commit comments