Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary workaround for generating unique model names #47

Merged
merged 10 commits into from
Oct 17, 2023

Conversation

eyurtsev
Copy link
Collaborator

@eyurtsev eyurtsev commented Oct 16, 2023

If two schema different schemas share the same name, fastapi openapi documentation fails.

This is a temporary work-around for openapi spec generation purposes. It will work only for top level model names.

We've bumped into this issue while hosting 2 runnables that start with a PromptTemplate (same name for the schema), but have different template variables (so the schema are different).

We'll need to find a better solution to handle nested models. This should be good for now as it'll allow users to deploy the common case correctly.

langserve/server.py Outdated Show resolved Hide resolved
@@ -85,8 +107,17 @@ def _resolve_model(type_: Union[Type, BaseModel], default_name: str) -> Type[Bas

hash_ = model.schema_json()

if model.__name__ in _SEEN_NAMES and hash_ not in _MODEL_REGISTRY:
# If the model name has been seen before, but the model itself is different
Copy link
Member

Choose a reason for hiding this comment

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

is the order models get loaded in deterministic? Could this result in an indeterministic openapi spec depending on that order?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Depends on order of add_routes invocation so I think deterministic in this case. [This is because we're only registering top level model names (which is also why we can't resolve the full issue)]

@@ -192,18 +208,22 @@ def add_routes(
"Use `pip install sse_starlette` to install."
)

namespace = path or ""

model_namespace = path.strip("/").replace("/", "_")
Copy link
Member

Choose a reason for hiding this comment

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

Are there restrictions on pydantic names?

  • if so, there are more characters in paths that we might need to handle
  • if not, can we skip this and pass around the path instead? Might be more straightforward than a new namespace concept

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good points. Will check wasn't being methodlogical here

@eyurtsev eyurtsev marked this pull request as ready for review October 17, 2023 01:47
@eyurtsev eyurtsev changed the title Workaround for unique names Temporary workaround for generating unique model names Oct 17, 2023
@eyurtsev eyurtsev merged commit 972b99d into main Oct 17, 2023
6 checks passed
@eyurtsev eyurtsev deleted the eugene/add_unique_names branch October 17, 2023 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants