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
326 changes: 211 additions & 115 deletions src/utils/models_dumper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"""Function to dump the schema of all data models into OpenAPI-compatible format."""

from typing import Optional

from pydantic import BaseModel

import models.api.requests as r
import models.api.responses.error as e
import models.api.responses.successful as s
Expand All @@ -9,6 +13,137 @@
import models.compaction as models_compaction
from utils.openapi_schema_dumper import dump_openapi_schema

conversation_summary_models: list[type[BaseModel]] = [
models_compaction.ConversationSummary
]

requests_models: list[type[BaseModel]] = [
r.ConversationUpdateRequest,
r.FeedbackRequest,
r.FeedbackStatusUpdateRequest,
r.MCPServerRegistrationRequest,
r.ModelFilter,
r.PromptCreateRequest,
r.PromptUpdateRequest,
r.QueryRequest,
r.ResponsesRequest,
r.RlsapiV1Attachment,
r.RlsapiV1CLA,
r.RlsapiV1Context,
r.RlsapiV1InferRequest,
r.RlsapiV1SystemInfo,
r.RlsapiV1Terminal,
r.StreamingInterruptRequest,
r.VectorStoreCreateRequest,
r.VectorStoreFileCreateRequest,
r.VectorStoreUpdateRequest,
]

successful_responses_models: list[type[BaseModel]] = [
s.AuthorizedResponse,
s.ConfigurationResponse,
s.ConversationDeleteResponse,
s.ConversationResponse,
s.ConversationUpdateResponse,
s.ConversationsListResponse,
s.ConversationsListResponseV2,
s.FeedbackResponse,
s.FeedbackStatusUpdateResponse,
s.FileResponse,
s.InfoResponse,
s.LivenessResponse,
s.MCPClientAuthOptionsResponse,
s.MCPServerDeleteResponse,
s.MCPServerListResponse,
s.MCPServerRegistrationResponse,
s.ModelsResponse,
s.PromptDeleteResponse,
s.PromptResourceResponse,
s.PromptsListResponse,
s.ProviderResponse,
s.ProvidersListResponse,
s.QueryResponse,
s.RAGInfoResponse,
s.RAGListResponse,
s.ReadinessResponse,
s.ResponsesResponse,
s.RlsapiV1InferData,
s.RlsapiV1InferResponse,
s.ShieldsResponse,
s.StatusResponse,
s.StreamingInterruptResponse,
s.StreamingQueryResponse,
s.ToolsResponse,
s.VectorStoreDeleteResponse,
s.VectorStoreFileDeleteResponse,
s.VectorStoreFileResponse,
s.VectorStoreFilesListResponse,
s.VectorStoreResponse,
s.VectorStoresListResponse,
]

error_responses_models: list[type[BaseModel]] = [
e.AbstractErrorResponse,
e.BadRequestResponse,
e.ConflictResponse,
e.DetailModel,
e.FileTooLargeResponse,
e.ForbiddenResponse,
e.InternalServerErrorResponse,
e.NotFoundResponse,
e.PromptTooLongResponse,
e.QuotaExceededResponse,
e.ServiceUnavailableResponse,
e.UnauthorizedResponse,
e.UnprocessableEntityResponse,
]

common_models: list[type[BaseModel]] = [
c.Attachment,
c.ConversationData,
c.ConversationDetails,
c.ConversationTurn,
c.MCPListToolsSummary,
c.MCPServerAuthInfo,
c.MCPServerInfo,
c.Message,
c.ProviderHealthStatus,
c.RAGChunk,
c.RAGContext,
c.ReferencedDocument,
c.ShieldModerationBlocked,
c.ShieldModerationPassed,
c.SolrVectorSearchRequest,
c.ToolCallSummary,
c.ToolInfoSummary,
c.ToolResultSummary,
c.Transcript,
c.TranscriptMetadata,
c.TurnSummary,
]

agents_models: list[type[BaseModel]] = [
a.EndEventData,
a.EndStreamPayload,
a.ErrorEventData,
a.ErrorStreamPayload,
a.InterruptedEventData,
a.InterruptedStreamPayload,
a.StartEventData,
a.StartStreamPayload,
a.StreamPayloadBase,
a.TokenChunkData,
a.TokenStreamPayload,
a.ToolCallStreamPayload,
a.ToolResultStreamPayload,
a.TurnCompleteStreamPayload,
]

common_responses_models: list[type[BaseModel]] = [
cr.InputToolMCP,
cr.ResponsesApiParams,
]


def dump_models(filename: str) -> None:
"""Dump the schema of all models into OpenAPI-compatible JSON file.
Expand All @@ -25,119 +160,80 @@ def dump_models(filename: str) -> None:
------
IOError: If the file cannot be written.
"""
models = [models_compaction.ConversationSummary]

# add all requests data models
for model in [
r.ConversationUpdateRequest,
r.FeedbackRequest,
r.FeedbackStatusUpdateRequest,
r.MCPServerRegistrationRequest,
r.ModelFilter,
r.PromptCreateRequest,
r.PromptUpdateRequest,
r.QueryRequest,
r.ResponsesRequest,
r.RlsapiV1Attachment,
r.RlsapiV1CLA,
r.RlsapiV1Context,
r.RlsapiV1InferRequest,
r.RlsapiV1SystemInfo,
r.RlsapiV1Terminal,
r.StreamingInterruptRequest,
r.VectorStoreCreateRequest,
r.VectorStoreFileCreateRequest,
r.VectorStoreUpdateRequest,
s.AuthorizedResponse,
s.ConfigurationResponse,
s.ConversationDeleteResponse,
s.ConversationResponse,
s.ConversationUpdateResponse,
s.ConversationsListResponse,
s.ConversationsListResponseV2,
s.FeedbackResponse,
s.FeedbackStatusUpdateResponse,
s.FileResponse,
s.InfoResponse,
s.LivenessResponse,
s.MCPClientAuthOptionsResponse,
s.MCPServerDeleteResponse,
s.MCPServerListResponse,
s.MCPServerRegistrationResponse,
s.ModelsResponse,
s.PromptDeleteResponse,
s.PromptResourceResponse,
s.PromptsListResponse,
s.ProviderResponse,
s.ProvidersListResponse,
s.QueryResponse,
s.RAGInfoResponse,
s.RAGListResponse,
s.ReadinessResponse,
s.ResponsesResponse,
s.RlsapiV1InferData,
s.RlsapiV1InferResponse,
s.ShieldsResponse,
s.StatusResponse,
s.StreamingInterruptResponse,
s.StreamingQueryResponse,
s.ToolsResponse,
s.VectorStoreDeleteResponse,
s.VectorStoreFileDeleteResponse,
s.VectorStoreFileResponse,
s.VectorStoreFilesListResponse,
s.VectorStoreResponse,
s.VectorStoresListResponse,
e.AbstractErrorResponse,
e.BadRequestResponse,
e.ConflictResponse,
e.DetailModel,
e.FileTooLargeResponse,
e.ForbiddenResponse,
e.InternalServerErrorResponse,
e.NotFoundResponse,
e.PromptTooLongResponse,
e.QuotaExceededResponse,
e.ServiceUnavailableResponse,
e.UnauthorizedResponse,
e.UnprocessableEntityResponse,
c.Attachment,
c.ConversationData,
c.ConversationDetails,
c.ConversationTurn,
c.MCPListToolsSummary,
c.MCPServerAuthInfo,
c.MCPServerInfo,
c.Message,
c.ProviderHealthStatus,
c.RAGChunk,
c.RAGContext,
c.ReferencedDocument,
c.ShieldModerationBlocked,
c.ShieldModerationPassed,
c.SolrVectorSearchRequest,
c.ToolCallSummary,
c.ToolInfoSummary,
c.ToolResultSummary,
c.Transcript,
c.TranscriptMetadata,
c.TurnSummary,
a.EndEventData,
a.EndStreamPayload,
a.ErrorEventData,
a.ErrorStreamPayload,
a.InterruptedEventData,
a.InterruptedStreamPayload,
a.StartEventData,
a.StartStreamPayload,
a.StreamPayloadBase,
a.TokenChunkData,
a.TokenStreamPayload,
a.ToolCallStreamPayload,
a.ToolResultStreamPayload,
a.TurnCompleteStreamPayload,
cr.InputToolMCP,
cr.ResponsesApiParams,
]:
models.append(model)
# construct a list with all models
models = (
conversation_summary_models
+ requests_models
+ successful_responses_models
+ error_responses_models
+ common_models
+ agents_models
+ common_responses_models
)

# dump all the models into one OpenAPI-compatible JSON file
dump_openapi_schema(models, filename)


def get_models_for_group(model_group: str) -> list[type[BaseModel]]:
"""Return the list of Pydantic model classes for the given model group.

Supported groups:
- "requests"
- "successful_responses"
- "error_responses"
- "common"
- "agents"
- "common_responses"

Parameters:
----------
model_group: The name of the model group to look up.

Returns:
-------
A list of Pydantic model classes belonging to the requested group.

Raises:
------
Exception: If model_group is not a recognized group name.
"""
match model_group:
case "requests":
return requests_models
case "successful_responses":
return successful_responses_models
case "error_responses":
return error_responses_models
case "common":
return common_models
case "agents":
return agents_models
case "common_responses":
return common_responses_models
case _:
raise ValueError(f"Unknown model group provided: {model_group}")


def dump_models_group(model_group: str, filename: Optional[str] = None) -> None:
"""Dump the schema of selected models group into OpenAPI-compatible JSON file.

Parameters:
----------
- model_group: str - name of model group to export the schema to

Returns:
-------
- None

Raises:
------
IOError: If the file cannot be written.
"""
Comment on lines +218 to +232

@coderabbitai coderabbitai Bot Jul 26, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Document the filename parameter.

The public function accepts filename, but its docstring omits it and does not describe the default <model_group>.json behavior. As per coding guidelines, document all function parameters. Based on learnings, use the repository’s Parameters: header format.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/utils/models_dumper.py` around lines 216 - 230, Update the docstring for
dump_models_group to document the filename parameter using the existing
Parameters: format, including that it is an optional string and defaults to
<model_group>.json when omitted.

Sources: Coding guidelines, Learnings

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai create issue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

repo="lightspeed-core/lightspeed-stack"
title="Document filename behavior in dump_models_group"
body=$(cat <<'EOF'
## Summary

Document the `filename` parameter of `dump_models_group` in `src/utils/models_dumper.py`.

## Required changes

Update the `dump_models_group(model_group: str, filename: Optional[str] = None)` docstring to describe:

- `filename` as an optional output filename.
- The default behavior: when omitted, the schema is written to `<model_group>.json`.

Use the repository's established `Parameters:` docstring format.

## Rationale

The function is public and accepts `filename`, but its current docstring does not document that parameter or the default output-filename behavior.

## Affected area

- `src/utils/models_dumper.py`
- `dump_models_group`

## Acceptance criteria

- The docstring documents both `model_group` and `filename`.
- The `filename` documentation states that it is optional and defaults to `<model_group>.json` when omitted.
- The documentation follows the repository's `Parameters:` format.

## Backlinks

- Pull request: https://github.com/lightspeed-core/lightspeed-stack/pull/2250
- Review comment: https://github.com/lightspeed-core/lightspeed-stack/pull/2250#discussion_r3653271291

Requested by: `@tisnik`
EOF
)

issue_url=$(gh issue create \
  --repo "$repo" \
  --title "$title" \
  --body "$body" \
  --assignee tisnik)

printf '%s\n' "$issue_url"

Length of output: 1633


@tisnik, created follow-up issue #2251: Document filename behavior in dump_models_group. It is assigned to you and links back to this PR and review comment.


🧠 Learnings used
Learnt from: Jdubrick
Repo: lightspeed-core/lightspeed-stack PR: 1971
File: src/utils/markdown_repair.py:31-36
Timestamp: 2026-06-24T13:45:37.249Z
Learning: In the lightspeed-stack repository, docstrings must use the section header name "Parameters:" (not "Args:") for function arguments, even if the project references Google Python docstring conventions. Ensure docstrings follow the project’s established "Parameters:" header format for any documented function parameters.

models = get_models_for_group(model_group)

if filename is None:
filename = f"{model_group}.json"

# dump all selected models into one OpenAPI-compatible JSON file
dump_openapi_schema(models, filename)
Loading
Loading