Spaces:
Build error
Build error
File size: 2,744 Bytes
84d2a97 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
use tonic::Status;
use crate::conversions::json::{dict_to_proto, json_to_proto, proto_dict_to_json, proto_to_json};
use crate::grpc::qdrant as grpc;
use crate::rest::{schema as rest, Options};
impl From<rest::Document> for grpc::Document {
fn from(document: rest::Document) -> Self {
Self {
text: document.text,
model: document.model,
options: document
.options
.options
.map(dict_to_proto)
.unwrap_or_default(),
}
}
}
impl TryFrom<grpc::Document> for rest::Document {
type Error = Status;
fn try_from(document: grpc::Document) -> Result<Self, Self::Error> {
Ok(Self {
text: document.text,
model: document.model,
options: Options {
options: Some(proto_dict_to_json(document.options)?),
},
})
}
}
impl From<rest::Image> for grpc::Image {
fn from(image: rest::Image) -> Self {
Self {
image: Some(json_to_proto(image.image)),
model: image.model,
options: image.options.options.map(dict_to_proto).unwrap_or_default(),
}
}
}
impl TryFrom<grpc::Image> for rest::Image {
type Error = Status;
fn try_from(image: grpc::Image) -> Result<Self, Self::Error> {
let grpc::Image {
image,
model,
options,
} = image;
let image = image.ok_or_else(|| Status::invalid_argument("Empty image is not allowed"))?;
Ok(Self {
image: proto_to_json(image)?,
model,
options: Options {
options: Some(proto_dict_to_json(options)?),
},
})
}
}
impl From<rest::InferenceObject> for grpc::InferenceObject {
fn from(object: rest::InferenceObject) -> Self {
Self {
object: Some(json_to_proto(object.object)),
model: object.model,
options: object
.options
.options
.map(dict_to_proto)
.unwrap_or_default(),
}
}
}
impl TryFrom<grpc::InferenceObject> for rest::InferenceObject {
type Error = Status;
fn try_from(object: grpc::InferenceObject) -> Result<Self, Self::Error> {
let grpc::InferenceObject {
object,
model,
options,
} = object;
let object =
object.ok_or_else(|| Status::invalid_argument("Empty object is not allowed"))?;
Ok(Self {
object: proto_to_json(object)?,
model,
options: Options {
options: Some(proto_dict_to_json(options)?),
},
})
}
}
|