[Bugfix] Pass json-schema to GuidedDecodingParams and make test stronger (#9530)
This commit is contained in:
@@ -851,14 +851,28 @@ async def test_response_format_json_object(client: openai.AsyncOpenAI):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_response_format_json_schema(client: openai.AsyncOpenAI):
|
||||
prompt = 'what is 1+1? The format is "result": 2'
|
||||
# Check that this prompt cannot lead to a valid JSON without json_schema
|
||||
for _ in range(2):
|
||||
resp = await client.chat.completions.create(
|
||||
model=MODEL_NAME,
|
||||
messages=[{
|
||||
"role":
|
||||
"user",
|
||||
"content": ('what is 1+1? please respond with a JSON object, '
|
||||
'the format is {"result": 2}')
|
||||
"role": "user",
|
||||
"content": prompt
|
||||
}],
|
||||
)
|
||||
content = resp.choices[0].message.content
|
||||
assert content is not None
|
||||
with pytest.raises((json.JSONDecodeError, AssertionError)):
|
||||
loaded = json.loads(content)
|
||||
assert loaded == {"result": 2}, loaded
|
||||
|
||||
for _ in range(2):
|
||||
resp = await client.chat.completions.create(
|
||||
model=MODEL_NAME,
|
||||
messages=[{
|
||||
"role": "user",
|
||||
"content": prompt
|
||||
}],
|
||||
response_format={
|
||||
"type": "json_schema",
|
||||
|
||||
Reference in New Issue
Block a user