Exemplo n.º 1
0
    def test_perceive_action(self):
        gaia_ref = Gaia.connect("http://localhost:8080", "", "")
        impulse = PerceiveActionImpulse(False, str(uuid.uuid4()), "", {})

        on_next = lambda x: self.assertIsNotNone(x.id)
        on_error = lambda x: self.fail(x)
        gaia_ref.perceive_action(impulse).subscribe(on_next, on_error)
Exemplo n.º 2
0
def mock_gaia_ref(mock_response_handler):
    mock_client_factory = MockClientFactory()
    mock_client_factory.set_mock_response_handler(mock_response_handler)

    mock_stream_client_factory = MocktreamClientFactory()
    mock_stream_client_factory.set_mock_response_handler(mock_response_handler)

    Gaia._client_factory = mock_client_factory
    Gaia._stream_client_factory = mock_stream_client_factory

    return Gaia.connect("http://localhost:8080",
                        HMACCredentials("mockedApiKey", "mockedApiSecret"))
Exemplo n.º 3
0
    def test_preserve_delete_prompt(self):
        gaia_ref = Gaia.connect("http://localhost:8080", "", "")

        def on_next(x):
            self.assertIsNotNone(x.id)

        def on_error(x):
            print("ON_ERROR: " + str(x))
            self.fail(x)

        impulses = DeletePromptImpulse(str(uuid4()), str(uuid4()))
        gaia_ref.preserve_delete_prompts([impulses]).subscribe(on_next, on_error)
Exemplo n.º 4
0
    def test_preserve_update_intent(self):
        gaia_ref = Gaia.connect("http://localhost:8080", "", "")

        def on_next(x):
            self.assertIsNotNone(x.id)

        def on_error(x):
            print("ON_ERROR: " + str(x))
            self.fail(x)

        impulses = UpdateIntentImpulse(str(uuid4()), str(uuid4()), "", "", dict(), list(), "")
        gaia_ref.preserve_update_intents([impulses]).subscribe(on_next, on_error)
Exemplo n.º 5
0
    def test_import_identity_e2e(self):
        self.gaiaRef = Gaia.login("http://localhost:8080", UsernamePasswordCredentials("admin", "admin"))
        data = bytes("identity content", encoding="utf-8")
        result = pipe(ops.first())(
            self.gaiaRef.identity().import_identity('2fa4ff18-5c30-497b-9ad2-0d8eb51cd4da',
                                                    'identityName', data, True)).run()
        self.assertEqual(len(result.uri), 72)

        result = pipe(ops.first())(
            self.gaiaRef.data("gaia://2fa4ff18-5c30-497b-9ad2-0d8eb51cd4da/").list()).run()
        self.assertEqual(result[0].dictionary, {'filePath': 'identities/identityName',
                                                'tenant': '2fa4ff18-5c30-497b-9ad2-0d8eb51cd4da'})
        pass
    def test_retrieve_statement(self):
        gaia_ref = Gaia.connect("http://localhost:8080", "", "")

        def on_next(x):
            self.assertIsNotNone(x.identity_id)

        def on_error(x):
            print("ON_ERROR: " + str(x))
            self.fail(x)

        def config(x):
            x.identity_id()

        gaia_ref.retrieve_statements(config).subscribe(on_next, on_error)
    def test_retrieve_knowledge_edge(self):
        gaia_ref = Gaia.connect("http://localhost:8080", "", "")

        def on_next(x):
            self.assertIsNotNone(x.source)
            self.assertIsNotNone(x.target)

        def on_error(x):
            print("ON_ERROR: " + str(x))
            self.fail(x)

        def config(x):
            x.source()
            x.target()

        gaia_ref.retrieve_knowledge_edge(config).subscribe(on_next, on_error)
Exemplo n.º 8
0
    def test_perceive(self):
        gaia_ref = Gaia.connect("http://localhost:8080", "", "")
        impulse1 = PerceiveActionImpulse(False, str(uuid.uuid4()), "", {})
        impulse2 = PerceiveDataImpulse(str(uuid.uuid4()), "", {})

        def on_next(x):
            self.assertIsNotNone(x.perceive_action.id)
            self.assertIsNotNone(x.perceive_data.id)

        def on_error(x):
            self.fail(x)

        def perceive(p: Perception):
            p.perceive_action(impulse1, lambda x: x.id())
            p.perceive_data(impulse2, lambda x: x.id())

        gaia_ref.perceive(perceive).subscribe(on_next, on_error)
Exemplo n.º 9
0
    def test_export_identity_e2e(self):
        self.gaiaRef = Gaia.login("http://localhost:8080", UsernamePasswordCredentials("admin", "admin"))

        result = pipe(ops.first())(
            self.gaiaRef.identity().export("d32829c8-5900-4346-9577-25e8146d1e78")).run()
        self.assertEqual(len(result), 28311)
Exemplo n.º 10
0
import logging
import os

from gaia_sdk.api.GaiaCredentials import HMACCredentials
from gaia_sdk.gaia import Gaia
from src.adder import Adder
from src.intent_reader import IntentReader

api_key = os.environ["GAIA_API_KEY"]
api_secret = os.environ["GAIA_API_SECRET"]
url = os.environ["GAIA_URL"]

gaia_sdk = Gaia.connect(url, HMACCredentials(api_key, api_secret))

logging.basicConfig(level=logging.INFO)
log = logging.getLogger("skill")

intent_reader = IntentReader(gaia_sdk)


def evaluate(payload: dict, context: dict) -> dict:
    log.info(f"received a message: {payload}")
    log.info(f"context: {context}")

    if context["namespace"] == "intents.incoming":
        identity_id = payload["identityId"]
        return {'@intents': {'qualifiers': intent_reader.read(identity_id)}}
    elif context["namespace"] == "echo.incoming":
        return {'@echo': {'response': payload["text"]}}
    elif context["namespace"] == "adder.incoming":
        result = Adder.add(payload['a'], payload['b'])