Skip to content

Commit

Permalink
chore: use DEBUG in dify_config instead of parsing raw system environ…
Browse files Browse the repository at this point in the history
…ment variable in place (langgenius#10437)
  • Loading branch information
bowenliang123 authored and jiangzhijie committed Nov 14, 2024
1 parent 1d28cce commit 0d9fc99
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from configs import dify_config

if os.environ.get("DEBUG", "false").lower() != "true":
if dify_config.DEBUG:
from gevent import monkey

monkey.patch_all()
Expand Down
4 changes: 3 additions & 1 deletion api/app_factory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os

if os.environ.get("DEBUG", "false").lower() != "true":
from configs import dify_config

if dify_config.DEBUG:
from gevent import monkey

monkey.patch_all()
Expand Down
4 changes: 2 additions & 2 deletions api/core/app/apps/advanced_chat/app_generator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import contextvars
import logging
import os
import threading
import uuid
from collections.abc import Generator
Expand All @@ -10,6 +9,7 @@
from pydantic import ValidationError

import contexts
from configs import dify_config
from constants import UUID_NIL
from core.app.app_config.features.file_upload.manager import FileUploadConfigManager
from core.app.apps.advanced_chat.app_config_manager import AdvancedChatAppConfigManager
Expand Down Expand Up @@ -317,7 +317,7 @@ def _generate_worker(
logger.exception("Validation Error when generating")
queue_manager.publish_error(e, PublishFrom.APPLICATION_MANAGER)
except (ValueError, InvokeError) as e:
if os.environ.get("DEBUG", "false").lower() == "true":
if dify_config.DEBUG:
logger.exception("Error when generating")
queue_manager.publish_error(e, PublishFrom.APPLICATION_MANAGER)
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions api/core/app/apps/agent_chat/app_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import os
import threading
import uuid
from collections.abc import Generator
Expand All @@ -8,6 +7,7 @@
from flask import Flask, current_app
from pydantic import ValidationError

from configs import dify_config
from constants import UUID_NIL
from core.app.app_config.easy_ui_based_app.model_config.converter import ModelConfigConverter
from core.app.app_config.features.file_upload.manager import FileUploadConfigManager
Expand Down Expand Up @@ -230,7 +230,7 @@ def _generate_worker(
logger.exception("Validation Error when generating")
queue_manager.publish_error(e, PublishFrom.APPLICATION_MANAGER)
except (ValueError, InvokeError) as e:
if os.environ.get("DEBUG") and os.environ.get("DEBUG").lower() == "true":
if dify_config.DEBUG:
logger.exception("Error when generating")
queue_manager.publish_error(e, PublishFrom.APPLICATION_MANAGER)
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions api/core/app/apps/chat/app_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import os
import threading
import uuid
from collections.abc import Generator
Expand All @@ -8,6 +7,7 @@
from flask import Flask, current_app
from pydantic import ValidationError

from configs import dify_config
from constants import UUID_NIL
from core.app.app_config.easy_ui_based_app.model_config.converter import ModelConfigConverter
from core.app.app_config.features.file_upload.manager import FileUploadConfigManager
Expand Down Expand Up @@ -227,7 +227,7 @@ def _generate_worker(
logger.exception("Validation Error when generating")
queue_manager.publish_error(e, PublishFrom.APPLICATION_MANAGER)
except (ValueError, InvokeError) as e:
if os.environ.get("DEBUG") and os.environ.get("DEBUG").lower() == "true":
if dify_config.DEBUG:
logger.exception("Error when generating")
queue_manager.publish_error(e, PublishFrom.APPLICATION_MANAGER)
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions api/core/app/apps/completion/app_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import os
import threading
import uuid
from collections.abc import Generator
Expand All @@ -8,6 +7,7 @@
from flask import Flask, current_app
from pydantic import ValidationError

from configs import dify_config
from core.app.app_config.easy_ui_based_app.model_config.converter import ModelConfigConverter
from core.app.app_config.features.file_upload.manager import FileUploadConfigManager
from core.app.apps.base_app_queue_manager import AppQueueManager, GenerateTaskStoppedError, PublishFrom
Expand Down Expand Up @@ -203,7 +203,7 @@ def _generate_worker(
logger.exception("Validation Error when generating")
queue_manager.publish_error(e, PublishFrom.APPLICATION_MANAGER)
except (ValueError, InvokeError) as e:
if os.environ.get("DEBUG") and os.environ.get("DEBUG").lower() == "true":
if dify_config.DEBUG:
logger.exception("Error when generating")
queue_manager.publish_error(e, PublishFrom.APPLICATION_MANAGER)
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions api/core/app/apps/workflow/app_generator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import contextvars
import logging
import os
import threading
import uuid
from collections.abc import Generator, Mapping, Sequence
Expand All @@ -10,6 +9,7 @@
from pydantic import ValidationError

import contexts
from configs import dify_config
from core.app.app_config.features.file_upload.manager import FileUploadConfigManager
from core.app.apps.base_app_generator import BaseAppGenerator
from core.app.apps.base_app_queue_manager import AppQueueManager, GenerateTaskStoppedError, PublishFrom
Expand Down Expand Up @@ -261,7 +261,7 @@ def _generate_worker(
logger.exception("Validation Error when generating")
queue_manager.publish_error(e, PublishFrom.APPLICATION_MANAGER)
except (ValueError, InvokeError) as e:
if os.environ.get("DEBUG") and os.environ.get("DEBUG", "false").lower() == "true":
if dify_config.DEBUG:
logger.exception("Error when generating")
queue_manager.publish_error(e, PublishFrom.APPLICATION_MANAGER)
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions api/core/model_manager.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
import os
from collections.abc import Callable, Generator, Iterable, Sequence
from typing import IO, Any, Optional, Union, cast

from configs import dify_config
from core.entities.embedding_type import EmbeddingInputType
from core.entities.provider_configuration import ProviderConfiguration, ProviderModelBundle
from core.entities.provider_entities import ModelLoadBalancingConfiguration
Expand Down Expand Up @@ -473,7 +473,7 @@ def fetch_next(self) -> Optional[ModelLoadBalancingConfiguration]:

continue

if bool(os.environ.get("DEBUG", "False").lower() == "true"):
if dify_config.DEBUG:
logger.info(
f"Model LB\nid: {config.id}\nname:{config.name}\n"
f"tenant_id: {self._tenant_id}\nprovider: {self._provider}\n"
Expand Down

0 comments on commit 0d9fc99

Please sign in to comment.