Skip to content

Commit 9495778

Browse files
committed
refactor: reorder Langfuse import logic for improved clarity
Moved logger import before Langfuse block to fix NameError.
1 parent 626b42b commit 9495778

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

lightrag/llm/openai.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,6 @@
1010
if not pm.is_installed("openai"):
1111
pm.install("openai")
1212

13-
# Try to import Langfuse for LLM observability (optional)
14-
# Falls back to standard OpenAI client if not available
15-
try:
16-
from langfuse.openai import AsyncOpenAI
17-
LANGFUSE_ENABLED = True
18-
logger.info("Langfuse observability enabled for OpenAI client")
19-
except ImportError:
20-
from openai import AsyncOpenAI
21-
LANGFUSE_ENABLED = False
22-
logger.debug("Langfuse not available, using standard OpenAI client")
23-
2413
from openai import (
2514
APIConnectionError,
2615
RateLimitError,
@@ -37,6 +26,19 @@
3726
safe_unicode_decode,
3827
logger,
3928
)
29+
30+
# Try to import Langfuse for LLM observability (optional)
31+
# Falls back to standard OpenAI client if not available
32+
try:
33+
from langfuse.openai import AsyncOpenAI
34+
35+
LANGFUSE_ENABLED = True
36+
logger.info("Langfuse observability enabled for OpenAI client")
37+
except ImportError:
38+
from openai import AsyncOpenAI
39+
40+
LANGFUSE_ENABLED = False
41+
logger.debug("Langfuse not available, using standard OpenAI client")
4042
from lightrag.types import GPTKeywordExtractionFormat
4143
from lightrag.api import __api_version__
4244

0 commit comments

Comments
 (0)