Skip to content
Merged
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
20 changes: 16 additions & 4 deletions instill/clients/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,42 @@
import instill.protogen.model.model.v1alpha.model_public_service_pb2_grpc as model_service
import instill.protogen.vdp.pipeline.v1beta.pipeline_public_service_pb2_grpc as pipeline_service

MB = 1024**2


class InstillInstance:
def __init__(self, stub, url: str, token: str, secure: bool, async_enabled: bool):
self.url: str = url
self.token: str = token
self.async_enabled: bool = async_enabled
self.metadata: Union[str, tuple] = ""

channel_options = (
("grpc.max_send_message_length", 10 * MB),
("grpc.max_receive_message_length", 10 * MB),
)

if not secure:
channel = grpc.insecure_channel(url)
channel = grpc.insecure_channel(url, options=channel_options)
self.metadata = (
(
"authorization",
f"Bearer {token}",
),
)
if async_enabled:
async_channel = grpc.aio.insecure_channel(url)
async_channel = grpc.aio.insecure_channel(url, options=channel_options)
else:
ssl_creds = grpc.ssl_channel_credentials()
call_creds = grpc.access_token_call_credentials(token)
creds = grpc.composite_channel_credentials(ssl_creds, call_creds)
channel = grpc.secure_channel(target=url, credentials=creds)
channel = grpc.secure_channel(
target=url, credentials=creds, options=channel_options
)
if async_enabled:
async_channel = grpc.aio.secure_channel(target=url, credentials=creds)
async_channel = grpc.aio.secure_channel(
target=url, credentials=creds, options=channel_options
)
self.channel: grpc.Channel = channel
self.client: Union[
model_service.ModelPublicServiceStub,
Expand Down