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

new: serialize to json inside pydantic #224

Merged
merged 1 commit into from
Jul 21, 2023
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
12 changes: 7 additions & 5 deletions qdrant_client/http/api/cluster_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# flake8: noqa E501
from typing import TYPE_CHECKING, Any, Dict, Set, Union

from qdrant_client._pydantic_compat import to_dict
from qdrant_client._pydantic_compat import to_json
from qdrant_client.http.models import *
from qdrant_client.http.models import models as m

Expand All @@ -18,8 +18,8 @@ def jsonable_encoder(
skip_defaults: bool = None,
exclude_unset: bool = False,
):
if hasattr(obj, "dict") or hasattr(obj, "model_dump"):
return to_dict(
if hasattr(obj, "json") or hasattr(obj, "model_dump_json"):
return to_json(
obj,
include=include,
exclude=exclude,
Expand Down Expand Up @@ -115,15 +115,17 @@ def _build_for_update_collection_cluster(
if timeout is not None:
query_params["timeout"] = str(timeout)

headers = {}
body = jsonable_encoder(cluster_operations)

if "Content-Type" not in headers:
headers["Content-Type"] = "application/json"
return self.api_client.request(
type_=m.InlineResponse2003,
method="POST",
url="/collections/{collection_name}/cluster",
path_params=path_params,
params=query_params,
json=body,
data=body,
)


Expand Down
42 changes: 27 additions & 15 deletions qdrant_client/http/api/collections_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# flake8: noqa E501
from typing import IO, TYPE_CHECKING, Any, Dict, Set, Union

from qdrant_client._pydantic_compat import to_dict
from qdrant_client._pydantic_compat import to_json
from qdrant_client.http.models import *
from qdrant_client.http.models import models as m

Expand All @@ -18,8 +18,8 @@ def jsonable_encoder(
skip_defaults: bool = None,
exclude_unset: bool = False,
):
if hasattr(obj, "dict") or hasattr(obj, "model_dump"):
return to_dict(
if hasattr(obj, "json") or hasattr(obj, "model_dump_json"):
return to_json(
obj,
include=include,
exclude=exclude,
Expand Down Expand Up @@ -73,15 +73,17 @@ def _build_for_create_collection(
if timeout is not None:
query_params["timeout"] = str(timeout)

headers = {}
body = jsonable_encoder(create_collection)

if "Content-Type" not in headers:
headers["Content-Type"] = "application/json"
return self.api_client.request(
type_=m.InlineResponse2003,
method="PUT",
url="/collections/{collection_name}",
path_params=path_params,
params=query_params,
json=body,
data=body,
)

def _build_for_create_field_index(
Expand All @@ -104,15 +106,17 @@ def _build_for_create_field_index(
if ordering is not None:
query_params["ordering"] = str(ordering)

headers = {}
body = jsonable_encoder(create_field_index)

if "Content-Type" not in headers:
headers["Content-Type"] = "application/json"
return self.api_client.request(
type_=m.InlineResponse2006,
method="PUT",
url="/collections/{collection_name}/index",
path_params=path_params,
params=query_params,
json=body,
data=body,
)

def _build_for_create_snapshot(
Expand Down Expand Up @@ -333,15 +337,17 @@ def _build_for_recover_from_snapshot(
if wait is not None:
query_params["wait"] = str(wait).lower()

headers = {}
body = jsonable_encoder(snapshot_recover)

if "Content-Type" not in headers:
headers["Content-Type"] = "application/json"
return self.api_client.request(
type_=m.InlineResponse2003,
method="PUT",
url="/collections/{collection_name}/snapshots/recover",
path_params=path_params,
params=query_params,
json=body,
data=body,
)

def _build_for_recover_from_uploaded_snapshot(
Expand Down Expand Up @@ -388,10 +394,12 @@ def _build_for_update_aliases(
if timeout is not None:
query_params["timeout"] = str(timeout)

headers = {}
body = jsonable_encoder(change_aliases_operation)

if "Content-Type" not in headers:
headers["Content-Type"] = "application/json"
return self.api_client.request(
type_=m.InlineResponse2003, method="POST", url="/collections/aliases", params=query_params, json=body
type_=m.InlineResponse2003, method="POST", url="/collections/aliases", params=query_params, data=body
)

def _build_for_update_collection(
Expand All @@ -411,15 +419,17 @@ def _build_for_update_collection(
if timeout is not None:
query_params["timeout"] = str(timeout)

headers = {}
body = jsonable_encoder(update_collection)

if "Content-Type" not in headers:
headers["Content-Type"] = "application/json"
return self.api_client.request(
type_=m.InlineResponse2003,
method="PATCH",
url="/collections/{collection_name}",
path_params=path_params,
params=query_params,
json=body,
data=body,
)

def _build_for_update_collection_cluster(
Expand All @@ -436,15 +446,17 @@ def _build_for_update_collection_cluster(
if timeout is not None:
query_params["timeout"] = str(timeout)

headers = {}
body = jsonable_encoder(cluster_operations)

if "Content-Type" not in headers:
headers["Content-Type"] = "application/json"
return self.api_client.request(
type_=m.InlineResponse2003,
method="POST",
url="/collections/{collection_name}/cluster",
path_params=path_params,
params=query_params,
json=body,
data=body,
)


Expand Down
Loading