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)
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"))
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)
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)
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)
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)
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'])