Skip to content

Commit

Permalink
feat(openai-protocol): allow extra fields in requests to openai compa…
Browse files Browse the repository at this point in the history
…tible server

Signed-off-by: Guillaume Calmettes <[email protected]>
  • Loading branch information
gcalmettes committed Nov 19, 2024
1 parent 803f37e commit 0873c44
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions tests/entrypoints/openai/test_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,19 +899,19 @@ async def test_response_format_json_schema(client: openai.AsyncOpenAI):


@pytest.mark.asyncio
async def test_extra_fields(client: openai.AsyncOpenAI):
with pytest.raises(BadRequestError) as exc_info:
await client.chat.completions.create(
model=MODEL_NAME,
messages=[{
"role": "system",
"content": "You are a helpful assistant.",
"extra_field": "0",
}], # type: ignore
temperature=0,
seed=0)

assert "extra_forbidden" in exc_info.value.message
async def test_extra_fields_allowed(client: openai.AsyncOpenAI):
resp = await client.chat.completions.create(
model=MODEL_NAME,
messages=[{
"role": "user",
"content": "what is 1+1?",
"extra_field": "0",
}], # type: ignore
temperature=0,
seed=0)

content = resp.choices[0].message.content
assert content is not None


@pytest.mark.asyncio
Expand Down
2 changes: 1 addition & 1 deletion vllm/entrypoints/openai/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

class OpenAIBaseModel(BaseModel):
# OpenAI API does not allow extra fields
model_config = ConfigDict(extra="forbid")
model_config = ConfigDict(extra="allow")


class ErrorResponse(OpenAIBaseModel):
Expand Down

0 comments on commit 0873c44

Please sign in to comment.