diff --git a/nanobot/providers/openai_compat_provider.py b/nanobot/providers/openai_compat_provider.py index a06bfa237..7149b95e1 100644 --- a/nanobot/providers/openai_compat_provider.py +++ b/nanobot/providers/openai_compat_provider.py @@ -4,7 +4,7 @@ from __future__ import annotations import asyncio import hashlib -import importlib +import importlib.util import os import secrets import string @@ -14,13 +14,15 @@ from typing import TYPE_CHECKING, Any import json_repair -if os.environ.get("LANGFUSE_SECRET_KEY"): - LANGFUSE_AVAILABLE = importlib.util.find_spec("langfuse") is not None - if not LANGFUSE_AVAILABLE: - raise ImportError("Langfuse is not available; please install it with `pip install langfuse`") - +if os.environ.get("LANGFUSE_SECRET_KEY") and importlib.util.find_spec("langfuse"): from langfuse.openai import AsyncOpenAI else: + if os.environ.get("LANGFUSE_SECRET_KEY"): + import logging + logging.getLogger(__name__).warning( + "LANGFUSE_SECRET_KEY is set but langfuse is not installed; " + "install with `pip install langfuse` to enable tracing" + ) from openai import AsyncOpenAI from nanobot.providers.base import LLMProvider, LLMResponse, ToolCallRequest