Skip to content

Commit

Permalink
Don't run code during __import__, don't import LiteralDataLayer by de…
Browse files Browse the repository at this point in the history
…fault. (#1382)
  • Loading branch information
dokterbob authored Sep 30, 2024
1 parent 1c5098c commit dfa858b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions backend/chainlit/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@
from typing import Optional

from .base import BaseDataLayer
from .literalai import LiteralDataLayer
from .utils import (
queue_until_user_message as queue_until_user_message, # TODO: Consider deprecating re-export.; Redundant alias tells type checkers to STFU.
)

_data_layer: Optional[BaseDataLayer] = None


if api_key := os.environ.get("LITERAL_API_KEY"):
# support legacy LITERAL_SERVER variable as fallback
server = os.environ.get("LITERAL_API_URL") or os.environ.get("LITERAL_SERVER")
_data_layer = LiteralDataLayer(api_key=api_key, server=server)
def get_data_layer():
global _data_layer

if not _data_layer:
if api_key := os.environ.get("LITERAL_API_KEY"):
from .literalai import LiteralDataLayer

# support legacy LITERAL_SERVER variable as fallback
server = os.environ.get("LITERAL_API_URL") or os.environ.get(
"LITERAL_SERVER"
)
_data_layer = LiteralDataLayer(api_key=api_key, server=server)

def get_data_layer():
return _data_layer

0 comments on commit dfa858b

Please sign in to comment.