Skip to content

Commit

Permalink
refactor: move import statement inside function to avoid unnecessary …
Browse files Browse the repository at this point in the history
…imports (#3505)

* fix: Add exception handling for missing langchain_anthropic package

* refactor: Move import statement for get_starter_projects_dump in get_starter_projects

* chore: Modify logger to use error level for exception in directory_reader
  • Loading branch information
ogabrielluiz authored Aug 22, 2024
1 parent b5116e6 commit 2eca4d9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/backend/base/langflow/api/v1/starter_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
from loguru import logger

from langflow.graph.graph.schema import GraphDump
from langflow.services.database.models.user.model import User
from langflow.services.auth.utils import get_current_active_user
from langflow.initial_setup.load import get_starter_projects_dump

from langflow.services.database.models.user.model import User

router = APIRouter(prefix="/starter-projects", tags=["Flows"])

Expand All @@ -18,6 +16,8 @@ def get_starter_projects(
current_user: User = Depends(get_current_active_user),
):
"""Get a list of starter projects."""
from langflow.initial_setup.load import get_starter_projects_dump

try:
flows = get_starter_projects_dump()
return flows
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from langchain_anthropic.chat_models import ChatAnthropic
from pydantic.v1 import SecretStr

from langflow.base.models.model import LCModelComponent
Expand Down Expand Up @@ -53,6 +52,12 @@ class AnthropicModelComponent(LCModelComponent):
]

def build_model(self) -> LanguageModel: # type: ignore[type-var]
try:
from langchain_anthropic.chat_models import ChatAnthropic
except ImportError:
raise ImportError(
"langchain_anthropic is not installed. Please install it with `pip install langchain_anthropic`."
)
model = self.model
anthropic_api_key = self.anthropic_api_key
max_tokens = self.max_tokens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ async def abuild_component_menu_list(self, file_paths):
try:
output_types = await self.get_output_types_from_code_async(result_content)
except Exception as exc:
logger.exception(f"Error while getting output types from code: {str(exc)}")
logger.error(f"Error while getting output types from code: {str(exc)}")
output_types = [component_name_camelcase]
else:
output_types = [component_name_camelcase]
Expand Down

0 comments on commit 2eca4d9

Please sign in to comment.