Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions docs/openapi_generator/pyopenapi/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
is_generic_list,
is_type_optional,
is_type_union,
is_unwrapped_body_param,
unwrap_generic_list,
unwrap_optional_type,
unwrap_union_types,
Expand Down Expand Up @@ -769,24 +770,30 @@ def _build_operation(self, op: EndpointOperation) -> Operation:
first = next(iter(op.request_params))
request_name, request_type = first

op_name = "".join(word.capitalize() for word in op.name.split("_"))
request_name = f"{op_name}Request"
fields = [
(
name,
type_,
)
for name, type_ in op.request_params
]
request_type = make_dataclass(
request_name,
fields,
namespace={
"__doc__": create_docstring_for_request(
request_name, fields, doc_params
# Special case: if there's a single parameter with Body(embed=False) that's a BaseModel,
# unwrap it to show the flat structure in the OpenAPI spec
# Example: openai_chat_completion()
if (len(op.request_params) == 1 and is_unwrapped_body_param(request_type)):
pass
else:
op_name = "".join(word.capitalize() for word in op.name.split("_"))
request_name = f"{op_name}Request"
fields = [
(
name,
type_,
)
},
)
for name, type_ in op.request_params
]
request_type = make_dataclass(
request_name,
fields,
namespace={
"__doc__": create_docstring_for_request(
request_name, fields, doc_params
)
},
)

requestBody = RequestBody(
content={
Expand Down
13 changes: 11 additions & 2 deletions docs/openapi_generator/pyopenapi/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
import typing
import inspect
from pathlib import Path
from typing import TextIO
from typing import Any, List, Optional, Union, get_type_hints, get_origin, get_args
from typing import Any, List, Optional, TextIO, Union, get_type_hints, get_origin, get_args

from pydantic import BaseModel
from llama_stack.strong_typing.schema import object_to_json, StrictJsonType
from llama_stack.strong_typing.inspection import is_unwrapped_body_param
from llama_stack.core.resolver import api_protocol_map

from .generator import Generator
Expand Down Expand Up @@ -205,6 +206,14 @@ def _validate_has_return_in_docstring(method) -> str | None:
def _validate_has_params_in_docstring(method) -> str | None:
source = inspect.getsource(method)
sig = inspect.signature(method)

params_list = [p for p in sig.parameters.values() if p.name != "self"]
if len(params_list) == 1:
param = params_list[0]
param_type = param.annotation
if is_unwrapped_body_param(param_type):
return

# Only check if the method has more than one parameter
if len(sig.parameters) > 1 and ":param" not in source:
return "does not have a ':param' in its docstring"
Expand Down
20 changes: 12 additions & 8 deletions docs/static/deprecated-llama-stack-spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/OpenaiChatCompletionRequest"
"$ref": "#/components/schemas/OpenAIChatCompletionRequest"
}
}
},
Expand Down Expand Up @@ -1617,7 +1617,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/OpenaiCompletionRequest"
"$ref": "#/components/schemas/OpenAICompletionRequest"
}
}
},
Expand Down Expand Up @@ -7522,7 +7522,7 @@
"title": "OpenAIResponseFormatText",
"description": "Text response format for OpenAI-compatible chat completion requests."
},
"OpenaiChatCompletionRequest": {
"OpenAIChatCompletionRequest": {
"type": "object",
"properties": {
"model": {
Expand Down Expand Up @@ -7769,7 +7769,8 @@
"model",
"messages"
],
"title": "OpenaiChatCompletionRequest"
"title": "OpenAIChatCompletionRequest",
"description": "Request parameters for OpenAI-compatible chat completion endpoint."
},
"OpenAIChatCompletion": {
"type": "object",
Expand Down Expand Up @@ -7965,7 +7966,7 @@
],
"title": "OpenAICompletionWithInputMessages"
},
"OpenaiCompletionRequest": {
"OpenAICompletionRequest": {
"type": "object",
"properties": {
"model": {
Expand Down Expand Up @@ -8100,10 +8101,12 @@
"type": "array",
"items": {
"type": "string"
}
},
"description": "(Optional) vLLM-specific parameter for guided generation with a list of choices."
},
"prompt_logprobs": {
"type": "integer"
"type": "integer",
"description": "(Optional) vLLM-specific parameter for number of log probabilities to return for prompt tokens."
},
"suffix": {
"type": "string",
Expand All @@ -8115,7 +8118,8 @@
"model",
"prompt"
],
"title": "OpenaiCompletionRequest"
"title": "OpenAICompletionRequest",
"description": "Request parameters for OpenAI-compatible completion endpoint."
},
"OpenAICompletion": {
"type": "object",
Expand Down
22 changes: 16 additions & 6 deletions docs/static/deprecated-llama-stack-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/OpenaiChatCompletionRequest'
$ref: '#/components/schemas/OpenAIChatCompletionRequest'
required: true
deprecated: true
/v1/openai/v1/chat/completions/{completion_id}:
Expand Down Expand Up @@ -1167,7 +1167,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/OpenaiCompletionRequest'
$ref: '#/components/schemas/OpenAICompletionRequest'
required: true
deprecated: true
/v1/openai/v1/embeddings:
Expand Down Expand Up @@ -5575,7 +5575,7 @@ components:
title: OpenAIResponseFormatText
description: >-
Text response format for OpenAI-compatible chat completion requests.
OpenaiChatCompletionRequest:
OpenAIChatCompletionRequest:
type: object
properties:
model:
Expand Down Expand Up @@ -5717,7 +5717,9 @@ components:
required:
- model
- messages
title: OpenaiChatCompletionRequest
title: OpenAIChatCompletionRequest
description: >-
Request parameters for OpenAI-compatible chat completion endpoint.
OpenAIChatCompletion:
type: object
properties:
Expand Down Expand Up @@ -5883,7 +5885,7 @@ components:
- model
- input_messages
title: OpenAICompletionWithInputMessages
OpenaiCompletionRequest:
OpenAICompletionRequest:
type: object
properties:
model:
Expand Down Expand Up @@ -5975,8 +5977,14 @@ components:
type: array
items:
type: string
description: >-
(Optional) vLLM-specific parameter for guided generation with a list of
choices.
prompt_logprobs:
type: integer
description: >-
(Optional) vLLM-specific parameter for number of log probabilities to
return for prompt tokens.
suffix:
type: string
description: >-
Expand All @@ -5985,7 +5993,9 @@ components:
required:
- model
- prompt
title: OpenaiCompletionRequest
title: OpenAICompletionRequest
description: >-
Request parameters for OpenAI-compatible completion endpoint.
OpenAICompletion:
type: object
properties:
Expand Down
20 changes: 12 additions & 8 deletions docs/static/llama-stack-spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/OpenaiChatCompletionRequest"
"$ref": "#/components/schemas/OpenAIChatCompletionRequest"
}
}
},
Expand Down Expand Up @@ -243,7 +243,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/OpenaiCompletionRequest"
"$ref": "#/components/schemas/OpenAICompletionRequest"
}
}
},
Expand Down Expand Up @@ -5018,7 +5018,7 @@
"title": "OpenAIResponseFormatText",
"description": "Text response format for OpenAI-compatible chat completion requests."
},
"OpenaiChatCompletionRequest": {
"OpenAIChatCompletionRequest": {
"type": "object",
"properties": {
"model": {
Expand Down Expand Up @@ -5265,7 +5265,8 @@
"model",
"messages"
],
"title": "OpenaiChatCompletionRequest"
"title": "OpenAIChatCompletionRequest",
"description": "Request parameters for OpenAI-compatible chat completion endpoint."
},
"OpenAIChatCompletion": {
"type": "object",
Expand Down Expand Up @@ -5461,7 +5462,7 @@
],
"title": "OpenAICompletionWithInputMessages"
},
"OpenaiCompletionRequest": {
"OpenAICompletionRequest": {
"type": "object",
"properties": {
"model": {
Expand Down Expand Up @@ -5596,10 +5597,12 @@
"type": "array",
"items": {
"type": "string"
}
},
"description": "(Optional) vLLM-specific parameter for guided generation with a list of choices."
},
"prompt_logprobs": {
"type": "integer"
"type": "integer",
"description": "(Optional) vLLM-specific parameter for number of log probabilities to return for prompt tokens."
},
"suffix": {
"type": "string",
Expand All @@ -5611,7 +5614,8 @@
"model",
"prompt"
],
"title": "OpenaiCompletionRequest"
"title": "OpenAICompletionRequest",
"description": "Request parameters for OpenAI-compatible completion endpoint."
},
"OpenAICompletion": {
"type": "object",
Expand Down
22 changes: 16 additions & 6 deletions docs/static/llama-stack-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/OpenaiChatCompletionRequest'
$ref: '#/components/schemas/OpenAIChatCompletionRequest'
required: true
deprecated: false
/v1/chat/completions/{completion_id}:
Expand Down Expand Up @@ -167,7 +167,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/OpenaiCompletionRequest'
$ref: '#/components/schemas/OpenAICompletionRequest'
required: true
deprecated: false
/v1/conversations:
Expand Down Expand Up @@ -3824,7 +3824,7 @@ components:
title: OpenAIResponseFormatText
description: >-
Text response format for OpenAI-compatible chat completion requests.
OpenaiChatCompletionRequest:
OpenAIChatCompletionRequest:
type: object
properties:
model:
Expand Down Expand Up @@ -3966,7 +3966,9 @@ components:
required:
- model
- messages
title: OpenaiChatCompletionRequest
title: OpenAIChatCompletionRequest
description: >-
Request parameters for OpenAI-compatible chat completion endpoint.
OpenAIChatCompletion:
type: object
properties:
Expand Down Expand Up @@ -4132,7 +4134,7 @@ components:
- model
- input_messages
title: OpenAICompletionWithInputMessages
OpenaiCompletionRequest:
OpenAICompletionRequest:
type: object
properties:
model:
Expand Down Expand Up @@ -4224,8 +4226,14 @@ components:
type: array
items:
type: string
description: >-
(Optional) vLLM-specific parameter for guided generation with a list of
choices.
prompt_logprobs:
type: integer
description: >-
(Optional) vLLM-specific parameter for number of log probabilities to
return for prompt tokens.
suffix:
type: string
description: >-
Expand All @@ -4234,7 +4242,9 @@ components:
required:
- model
- prompt
title: OpenaiCompletionRequest
title: OpenAICompletionRequest
description: >-
Request parameters for OpenAI-compatible completion endpoint.
OpenAICompletion:
type: object
properties:
Expand Down
Loading
Loading