From 6f5c1886c4c47037db2f7ed9d4afc092cf59858f Mon Sep 17 00:00:00 2001 From: Mark Waddle Date: Wed, 20 Nov 2024 11:34:14 -0800 Subject: [PATCH 1/2] Fix circular imports in form_filler_skill (#257) --- .../form_filler_skill/guided_conversation/__init__.py | 4 ---- .../chat_drivers/fix_artifact_error.py | 11 +++++++++-- .../chat_drivers/generate_artifact_updates.py | 7 +------ 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/libraries/python/skills/skills/form-filler-skill/form_filler_skill/guided_conversation/__init__.py b/libraries/python/skills/skills/form-filler-skill/form_filler_skill/guided_conversation/__init__.py index 55ab367e..7a004fcc 100644 --- a/libraries/python/skills/skills/form-filler-skill/form_filler_skill/guided_conversation/__init__.py +++ b/libraries/python/skills/skills/form-filler-skill/form_filler_skill/guided_conversation/__init__.py @@ -1,9 +1,5 @@ -import logging - from .guided_conversation_skill import GuidedConversationSkill -logger = logging.getLogger(__name__) - __all__ = [ "GuidedConversationSkill", ] diff --git a/libraries/python/skills/skills/form-filler-skill/form_filler_skill/guided_conversation/chat_drivers/fix_artifact_error.py b/libraries/python/skills/skills/form-filler-skill/form_filler_skill/guided_conversation/chat_drivers/fix_artifact_error.py index 7fef2c38..b9cfcd20 100644 --- a/libraries/python/skills/skills/form-filler-skill/form_filler_skill/guided_conversation/chat_drivers/fix_artifact_error.py +++ b/libraries/python/skills/skills/form-filler-skill/form_filler_skill/guided_conversation/chat_drivers/fix_artifact_error.py @@ -1,3 +1,4 @@ +import logging from typing import Any from form_filler_skill.guided_conversation.message import Conversation, ConversationMessageType @@ -10,11 +11,12 @@ message_from_completion, validate_completion, ) +from pydantic import BaseModel from skill_library.types import LanguageModel -from .. import logger from ..artifact import Artifact -from .generate_artifact_updates import UpdateAttempt + +logger = logging.getLogger(__name__) ARTIFACT_ERROR_CORRECTION_SYSTEM_TEMPLATE = """You are a helpful, thoughtful, and meticulous assistant. @@ -36,6 +38,11 @@ """ +class UpdateAttempt(BaseModel): + field_value: str + error: str + + async def generate_artifact_field_update_error_fix( language_model: LanguageModel, artifact: Artifact, diff --git a/libraries/python/skills/skills/form-filler-skill/form_filler_skill/guided_conversation/chat_drivers/generate_artifact_updates.py b/libraries/python/skills/skills/form-filler-skill/form_filler_skill/guided_conversation/chat_drivers/generate_artifact_updates.py index a9e08a5d..18657355 100644 --- a/libraries/python/skills/skills/form-filler-skill/form_filler_skill/guided_conversation/chat_drivers/generate_artifact_updates.py +++ b/libraries/python/skills/skills/form-filler-skill/form_filler_skill/guided_conversation/chat_drivers/generate_artifact_updates.py @@ -14,7 +14,7 @@ from ..artifact import Artifact from ..message import Conversation -from .fix_artifact_error import generate_artifact_field_update_error_fix +from .fix_artifact_error import UpdateAttempt, generate_artifact_field_update_error_fix logger = logging.getLogger(__name__) @@ -61,11 +61,6 @@ class ArtifactUpdates(BaseModel): updates: list[ArtifactUpdate] -class UpdateAttempt(BaseModel): - field_value: str - error: str - - async def generate_artifact_updates( language_model: LanguageModel, definition: GCDefinition, From 004035352b2816467301dfb728f29cb401ad2824 Mon Sep 17 00:00:00 2001 From: Mark Waddle Date: Wed, 20 Nov 2024 11:39:01 -0800 Subject: [PATCH 2/2] Ping workbench with background task only (#258) To allow ctrl+c during startup --- .../assistant_service.py | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/libraries/python/semantic-workbench-assistant/semantic_workbench_assistant/assistant_service.py b/libraries/python/semantic-workbench-assistant/semantic_workbench_assistant/assistant_service.py index e326190b..7e6b63f0 100644 --- a/libraries/python/semantic-workbench-assistant/semantic_workbench_assistant/assistant_service.py +++ b/libraries/python/semantic-workbench-assistant/semantic_workbench_assistant/assistant_service.py @@ -74,26 +74,14 @@ def __init__( @asynccontextmanager async def lifespan() -> AsyncIterator[None]: - # connect to workbench on startup logger.info( - "connecting to semantic-workbench-service on startup; workbench_service_url: %s, assistant_service_id: %s, callback_url: %s", + "connecting to semantic-workbench-service; workbench_service_url: %s, assistant_service_id: %s, callback_url: %s", settings.workbench_service_url, self.service_id, settings.callback_url, ) async with self.workbench_client.for_service() as service_client: - try: - await self._ping_semantic_workbench(service_client) - logger.info( - "connected to semantic-workbench-service on startup; workbench_service_url: %s, assistant_service_id: %s, callback_url: %s", - settings.workbench_service_url, - self.service_id, - settings.callback_url, - ) - except httpx.HTTPError: - logger.warning("failed to connect workbench on startup", exc_info=True) - # start periodic pings to workbench ping_task = asyncio.create_task( self._periodically_ping_semantic_workbench(service_client), name="ping-workbench" @@ -116,16 +104,16 @@ async def _periodically_ping_semantic_workbench( ) -> NoReturn: while True: try: - jitter = random.uniform(0, settings.workbench_service_ping_interval_seconds / 2.0) - await asyncio.sleep(settings.workbench_service_ping_interval_seconds + jitter) - try: await self._ping_semantic_workbench(client) except httpx.HTTPError: - logger.error("ping to workbench failed", exc_info=True) + logger.exception("ping to workbench failed") + + jitter = random.uniform(0, settings.workbench_service_ping_interval_seconds / 2.0) + await asyncio.sleep(settings.workbench_service_ping_interval_seconds + jitter) except Exception: - logger.exception("unexpected error in ping loop", exc_info=True) + logger.exception("unexpected error in ping loop") @backoff.on_exception( backoff.expo,