Пример #1
0
    def _instantiate_client(self) -> Client:

        if SECURE == "True":
            with open(CONFIG_PATH, "r") as fi:
                json_dict: Dict = json.load(fi)

            logger.info("configuring secure connection")
            self._instantiate_config(grpc_cert=json_dict["grpc_cert"])
            self.client = Client(config=self.config)
        else:
            logger.info("configuring INSECURE connection")
            self._instantiate_config()
            self.client = Client(config=self.config, use_secure_channel=False)
        return self.client
Пример #2
0
def main():
    parser = argparse.ArgumentParser(description="Streaming example.")
    parser.add_argument("--config", type=str)
    parser.add_argument("--secure", default=False, action="store_true")
    args = parser.parse_args()

    with open(args.config) as f:
        config: ClientConfig = ClientConfig.from_json(f.read())

    client: Client = Client(config=config, use_secure_channel=args.secure)
    sessions_service: Sessions = client.services.sessions

    # Get audio stream (iterator of audio chunks)
    audio_stream: Iterator[bytes] = get_streaming_audio(AUDIO_FILE)

    # Create streaming request
    streaming_request: Iterator[StreamingDetectIntentRequest] = create_streaming_request(audio_stream)

    # get back responses
    for i, response in enumerate(sessions_service.streaming_detect_intent(streaming_request)):
        print(response.query_result.fulfillment_messages)
        with open(f"response_{i + 1}.wav", "wb") as f:
            f.write(response.audio)
Пример #3
0
from google.longrunning.operations_pb2 import Operation, GetOperationRequest

from ondewo.nlu.agent_pb2 import RestoreAgentRequest
from ondewo.nlu.client import Client
from ondewo.nlu.client_config import ClientConfig

if __name__ == '__main__':
    parent: str = '<PUT_YOUR_AGENT_PARENT_HERE>'
    zip_path: str = '<the path of your zip file>'
    config: ClientConfig = ClientConfig(host='<host>',
                                        port='<port>',
                                        http_token='<http/root token>',
                                        user_name='<e-mail of user>',
                                        password='******')

    client: Client = Client(config=config, use_secure_channel=False)

    with open(zip_path, 'rb') as file:
        byte_object = file.read()

    restore_operation: Operation = client.services.agents.restore_agent(
        RestoreAgentRequest(parent=parent, agent_content=byte_object))

    polling.poll(
        target=client.services.operations.get_operation,
        step=1,
        args=(GetOperationRequest(name=restore_operation.name), ),
        check_success=lambda op: op.done,
        timeout=600,  # wait 10 minutes until training is finished
    )
Пример #4
0
import polling
from google.longrunning.operations_pb2 import Operation, GetOperationRequest

from ondewo.nlu.agent_pb2 import TrainAgentRequest
from ondewo.nlu.client import Client
from ondewo.nlu.client_config import ClientConfig

if __name__ == '__main__':
    parent: str = '<PUT_YOUR_AGENT_PARENT_HERE>'
    config: ClientConfig = ClientConfig(host='<host>',
                                        port='<port>',
                                        http_token='<http/root token>',
                                        user_name='<e-mail of user>',
                                        password='******')

    client: Client = Client(config=config, use_secure_channel=True)

    train_operation: Operation = client.services.agents.train_agent(
        TrainAgentRequest(parent=parent))

    polling.poll(
        target=client.services.operations.get_operation,
        step=1,
        args=(GetOperationRequest(name=train_operation.name), ),
        check_success=lambda op: op.done,
        timeout=60 * 60 * 1,  # wait 1 hour until training is finished
    )

    training_operation_update: Operation = client.services.operations.get_operation(
        GetOperationRequest(name=train_operation.name))
    assert training_operation_update.done
Пример #5
0
    user_name: str = config_["user_name"]
    password: str = config_["password"]
    http_token: str = config_["http_token"]
    grpc_cert: bytes = str(config_.get("grpc_cert", '')).encode()

    config = ClientConfig(
        host=host,
        port=port,
        user_name=user_name,
        password=password,
        http_token=http_token,
        grpc_cert=grpc_cert,  # type: ignore
    )

    # 2. instantiate the client...
    client = Client(config=config)

    # 3. play...
    project_parent: str = config_["project_parent"]
    session_uuid: str = config_["session_uuid"]
    session_id: str = f'{project_parent}/sessions/{session_uuid}'

    # detect an intent
    request: Any = DetectIntentRequest()
    request.query_input.text.text = 'Hi'
    request.query_input.text.language_code = 'en'
    request.session = session_id
    response: Any = client.services.sessions.detect_intent(request)
    print(response.query_result.fulfillment_messages[0].text)

    # list all intents