Skip to content

Commit

Permalink
Merge branch 'main' into mengla/copilot_sample
Browse files Browse the repository at this point in the history
  • Loading branch information
melionel authored May 8, 2024
2 parents 0d3e4a1 + d987920 commit c81e30d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/promptflow-core/promptflow/core/_serving/app_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ def init_app(self, **kwargs):
self.logger = logger
# default to local, can be override when creating the app
self.extension = ExtensionFactory.create_extension(logger, **kwargs)

# make sure pfserving exporters initiated before any customer code loading
self.flow_monitor = self.extension.get_flow_monitor(self.get_context_data_provider())
self.flow_invoker: AsyncFlowInvoker = None

# parse promptflow project path
self.project_path = self.extension.get_flow_project_path()
logger.info(f"Project path: {self.project_path}")
Expand All @@ -48,8 +50,6 @@ def init_app(self, **kwargs):
self.connections_override = conn_data_override
self.connections_name_override = conn_name_override

self.flow_monitor = self.extension.get_flow_monitor(self.get_context_data_provider())

self.connection_provider = self.extension.get_connection_provider()
self.credential = self.extension.get_credential()
self.sample = get_sample_json(self.project_path, logger)
Expand Down
2 changes: 2 additions & 0 deletions src/promptflow-core/promptflow/core/_serving/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

FEEDBACK_TRACE_FIELD_NAME = "feedback"
FEEDBACK_TRACE_SPAN_NAME = "promptflow-feedback"

PF_BUILTIN_TRACE_EXPORTERS_DISABLE = "PF_BUILTIN_TRACE_EXPORTERS_DISABLE"
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _get_common_dimensions_from_env(self):
common_dimensions = json.loads(common_dimensions_str)
return common_dimensions
except Exception as ex:
self.logger.warn(f"Failed to parse common dimensions with value={common_dimensions_str}: {ex}")
self.logger.warning(f"Failed to parse common dimensions with value={common_dimensions_str}: {ex}")
return {}

def _get_default_blueprints(self, flow_monitor, static_folder=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def _init_executor(self, flow_path, working_dir):
raise_ex=self.raise_ex,
storage=storage,
init_kwargs=self._init_kwargs,
env_exporter_setup=False,
)
self.executor.enable_streaming_for_llm_flow(self.streaming)
self.logger.info("Promptflow executor initiated successfully.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------

import os
from typing import Dict

from promptflow._utils.exception_utils import ErrorResponse
from promptflow.core._serving.constants import PF_BUILTIN_TRACE_EXPORTERS_DISABLE
from promptflow.core._serving.monitor.context_data_provider import ContextDataProvider
from promptflow.core._serving.monitor.data_collector import FlowDataCollector
from promptflow.core._serving.monitor.metrics import MetricsRecorder, ResponseType
Expand Down Expand Up @@ -48,7 +50,10 @@ def setup_metrics_recorder(self, custom_dimensions, metric_exporters):
return None

def setup_trace_exporters(self, trace_exporters):
if not trace_exporters:
# This is to support customer customize their own spanprocessor, in that case customer can disable the built-in
# trace exporters by setting the environment variable PF_BUILTIN_TRACE_EXPORTERS_DISABLE to true.
disable_builtin_trace_exporters = os.environ.get(PF_BUILTIN_TRACE_EXPORTERS_DISABLE, "false").lower() == "true"
if not trace_exporters or disable_builtin_trace_exporters:
self.logger.warning("No trace exporter enabled.")
return
try:
Expand Down
5 changes: 4 additions & 1 deletion src/promptflow-core/promptflow/executor/flow_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ def create(
:return: A new instance of FlowExecutor.
:rtype: ~promptflow.executor.flow_executor.FlowExecutor
"""
setup_exporter_from_environ()
env_exporter_setup = kwargs.get("env_exporter_setup", True)
if env_exporter_setup:
setup_exporter_from_environ()

if hasattr(flow_file, "__call__") or inspect.isfunction(flow_file):
from ._script_executor import ScriptExecutor

Expand Down

0 comments on commit c81e30d

Please sign in to comment.