コード例 #1
0
 def _instantiate_config(self, grpc_cert: Optional[str] = None) -> None:
     if not self.config:
         self._log_default_config()
         self.config: ClientConfig = ClientConfig(
             host=CAI_HOST,
             port=CAI_PORT,
             http_token=HTTP_AUTH_TOKEN,
             user_name=USER_NAME,
             password=USER_PASS,
             grpc_cert=grpc_cert
         )
コード例 #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 typing import Optional

import polling
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,
コード例 #4
0
from typing import Optional

import polling
from google.longrunning.operations_pb2 import GetOperationRequest, Operation

from ondewo.nlu.agent_pb2 import ImportAgentRequest
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()

    import_operation: Operation = client.services.agents.import_agent(
        ImportAgentRequest(parent=parent, agent_content=byte_object)
    )

    polling.poll(
        target=client.services.operations.get_operation,
        step=1,
コード例 #5
0
    config_file = "ondewo_client/python/.env.production.json"

    with open(config_file) as f:
        config_ = json.load(f)

    host: str = config_["host"]
    port: str = config_["port"]
    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'
コード例 #6
0
import ondewo.nlu.agent_pb2 as agent
import ondewo.s2t.speech_to_text_pb2 as s2t
import ondewo.t2s.text_to_speech_pb2 as t2s
from ondewo.nlu.client import Client as NluClient
from ondewo.nlu.client_config import ClientConfig as NluClientConfig
from ondewo.s2t.client.client import Client as S2tClient
from ondewo.t2s.client.client import Client as T2sClient

from ondewo.csi.client.client import Client as CsiClient
from ondewo.csi.client.client_config import ClientConfig

with open("csi.json") as fi:
    config = ClientConfig.from_json(fi.read())
with open("csi.json") as fi:
    nlu_config = NluClientConfig.from_json(fi.read())

csi_client = CsiClient(config=config)
s2t_client = S2tClient(config=config)
t2s_client = T2sClient(config=config)
nlu_client = NluClient(config=nlu_config)

s2t_pipelines = s2t_client.services.speech_to_text.list_s2t_pipelines(request=s2t.ListS2tPipelinesRequest())
t2s_pipelines = t2s_client.services.text_to_speech.list_t2s_pipelines(request=t2s.ListT2sPipelinesRequest())

print(f"Speech to text pipelines: {[pipeline.id for pipeline in s2t_pipelines.pipeline_configs]}")
print(f"Text to speech pipelines: {[pipeline.id for pipeline in t2s_pipelines.pipelines]}")

agents = nlu_client.services.agents.list_agents(request=agent.ListAgentsRequest())

print(f"Nlu agents: {[agent.agent.parent for agent in agents.agents_with_owners]}")
コード例 #7
0
            f.write(f'{i.display_name},')
            f.write(str(response_count.value))
            f.write('\n')


if __name__ == '__main__':
    project_id: str = '<Your project ID>'
    parent: str = f'projects/{project_id}/agent'
    language_code: str = 'de'
    config_file: str = 'local_client.json'

    with open(config_file) as f:
        config_ = json.load(f)

    config = ClientConfig(
        host=config_["host"],
        port=config_["port"],
        user_name=config_["user_name"],
        password=config_["password"],
        http_token=config_["http_token"],
        grpc_cert=config_.get("grpc_cert", ''),
    )

    client: Client = Client(config=config, use_secure_channel=False)
    print('Client created!')

    get_agent_stats(client=client, parent=parent, language_code=language_code)
    get_responses_per_intent(client=client,
                             parent=parent,
                             language_code=language_code)