@@ -33,14 +33,17 @@ def __init__(
33
33
endpoint : str = "localhost:9140" ,
34
34
hitl_handler : hitl .HITLHandler = None ,
35
35
npi_token : str = None ,
36
+ insecure : bool = True ,
36
37
):
37
38
self .__app_name = app_name
38
39
if endpoint is None :
39
40
endpoint = "localhost:9140"
40
41
self .__npi_endpoint = endpoint
41
42
self .__app_type = app_type
42
-
43
- channel = grpc .secure_channel (target = self .__npi_endpoint , credentials = grpc .ssl_channel_credentials ())
43
+ if insecure :
44
+ channel = grpc .insecure_channel (self .__npi_endpoint )
45
+ else :
46
+ channel = grpc .secure_channel (target = self .__npi_endpoint , credentials = grpc .ssl_channel_credentials ())
44
47
self .stub = api_pb2_grpc .AppServerStub (channel )
45
48
self .hitl_handler = hitl_handler
46
49
self .__npi_token = npi_token
@@ -104,15 +107,24 @@ def chat(self, msg: str) -> str:
104
107
case api_pb2 .ResponseCode .ACTION_REQUIRED :
105
108
resp = self .stub .Chat (request = self .__call_human (resp ), metadata = self .__get_metadata ())
106
109
case _:
110
+ logger .error (f'[{ self .__app_name } ]: Error: failed to call function, unknown response code { resp .code } ' )
107
111
raise Exception ("Error: failed to call function" )
108
112
109
113
def hitl (self , handler : hitl .HITLHandler ):
110
114
self .hitl_handler = handler
111
115
112
- # @abstractmethod
113
- def authorize (self , ** kwargs ):
116
+ def authorize (self ):
114
117
pass
115
118
119
+ def _authorize (self , credentials : dict [str , str ]):
120
+ self .stub .Authorize (
121
+ request = api_pb2 .AuthorizeRequest (
122
+ type = self .__app_type ,
123
+ credentials = credentials ,
124
+ ),
125
+ )
126
+ logger .info (f'[{ self .__app_name } ]: Authorized' )
127
+
116
128
def __call_human (self , resp : api_pb2 .Response ) -> api_pb2 .Request :
117
129
human_resp = self .hitl_handler .handle (
118
130
hitl .convert_to_hitl_request (
0 commit comments