From a87071220b8b67c141391d873b8868a300384da2 Mon Sep 17 00:00:00 2001 From: ramnes Date: Wed, 26 Jul 2023 17:07:38 +0200 Subject: [PATCH] Handle variables that could be None --- src/chainlit/client/local.py | 4 ++-- src/chainlit/config.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/chainlit/client/local.py b/src/chainlit/client/local.py index 12baff12d3..d9cd52ad18 100644 --- a/src/chainlit/client/local.py +++ b/src/chainlit/client/local.py @@ -95,11 +95,11 @@ async def get_conversation(self, conversation_id: str): where={"id": conversation_id}, include={"messages": True, "elements": True} ) - for m in c.messages: + for m in c.messages or []: if m.llmSettings: m.llmSettings = json.loads(m.llmSettings) - for e in c.elements: + for e in c.elements or []: if e.forIds: e.forIds = json.loads(e.forIds) diff --git a/src/chainlit/config.py b/src/chainlit/config.py index 29652b0421..128cb1f0bf 100644 --- a/src/chainlit/config.py +++ b/src/chainlit/config.py @@ -225,7 +225,13 @@ def load_module(target: str): sys.path.insert(0, target_dir) spec = util.spec_from_file_location(target, target) + if not spec or not spec.loader: + return + module = util.module_from_spec(spec) + if not module: + return + spec.loader.exec_module(module) sys.modules[target] = module