Skip to content

Commit

Permalink
[Tracing] Change import path of trace (#2233)
Browse files Browse the repository at this point in the history
# Description

In this PR, we change the import path of trace to `promtpflow.tracing`,
in order to prepare for splitting the promptflow-tracing package from
promptflow.

# All Promptflow Contribution checklist:
- [x] **The pull request does not introduce [breaking changes].**
- [ ] **CHANGELOG is updated for new features, bug fixes or other
significant changes.**
- [x] **I have read the [contribution guidelines](../CONTRIBUTING.md).**
- [ ] **Create an issue and link to the pull request to get dedicated
review from promptflow team. Learn more: [suggested
workflow](../CONTRIBUTING.md#suggested-workflow).**

## General Guidelines and Best Practices
- [x] Title of the pull request is clear and informative.
- [x] There are a small number of commits, each of which have an
informative message. This means that previously merged commits do not
appear in the history of the PR. For more information on cleaning up the
commits in your PR, [see this
page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md).

### Testing Guidelines
- [x] Pull request includes test coverage for the included changes.

---------

Co-authored-by: Lina Tang <[email protected]>
  • Loading branch information
lumoslnt and Lina Tang authored Mar 7, 2024
1 parent d6f4666 commit b4573c9
Show file tree
Hide file tree
Showing 32 changed files with 263 additions and 226 deletions.
3 changes: 1 addition & 2 deletions src/promptflow/promptflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

# flake8: noqa
from promptflow._core.tool import ToolProvider, tool
from promptflow._core.tracer import trace

# control plane sdk functions
from promptflow._sdk._load_functions import load_flow, load_run
Expand All @@ -20,4 +19,4 @@

__version__ = VERSION

__all__ = ["PFClient", "load_flow", "load_run", "log_metric", "ToolProvider", "tool", "trace"]
__all__ = ["PFClient", "load_flow", "load_run", "log_metric", "ToolProvider", "tool"]
2 changes: 1 addition & 1 deletion src/promptflow/promptflow/_core/flow_execution_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
from promptflow.contracts.flow import Node
from promptflow.contracts.run_info import RunInfo
from promptflow.exceptions import PromptflowException
from promptflow.tracing._tracer import Tracer

from .run_tracker import RunTracker
from .thread_local_singleton import ThreadLocalSingleton
from .tracer import Tracer


class FlowExecutionContext(ThreadLocalSingleton):
Expand Down
4 changes: 2 additions & 2 deletions src/promptflow/promptflow/_core/openai_injector.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import openai

from promptflow._core.operation_context import OperationContext
from promptflow.contracts.trace import TraceType
from promptflow.tracing._trace import _traced_async, _traced_sync
from promptflow.tracing.contracts.trace import TraceType

from .tracer import _traced_async, _traced_sync

USER_AGENT_HEADER = "x-ms-useragent"
PROMPTFLOW_HEADER = "ms-azure-ai-promptflow"
Expand Down
4 changes: 2 additions & 2 deletions src/promptflow/promptflow/_core/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from enum import Enum
from typing import Callable, Dict, List, Optional, Union

from promptflow._core.tracer import _traced
from promptflow.contracts.trace import TraceType
from promptflow.tracing._trace import _traced
from promptflow.tracing.contracts.trace import TraceType

module_logger = logging.getLogger(__name__)
STREAMING_OPTION_PARAMETER_ATTR = "_streaming_option_parameter"
Expand Down
2 changes: 1 addition & 1 deletion src/promptflow/promptflow/_internal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
register_connections,
retrieve_tool_func_result,
)
from promptflow._core.tracer import Tracer
from promptflow._sdk._constants import LOCAL_MGMT_DB_PATH
from promptflow._sdk._serving.response_creator import ResponseCreator
from promptflow._sdk._serving.swagger import generate_swagger
Expand Down Expand Up @@ -112,3 +111,4 @@
from promptflow.executor._errors import InputNotFound
from promptflow.executor._tool_invoker import DefaultToolInvoker
from promptflow.storage._run_storage import DefaultRunStorage
from promptflow.tracing._tracer import Tracer
14 changes: 8 additions & 6 deletions src/promptflow/promptflow/_sdk/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@

import promptflow
from promptflow._constants import EXTENSION_UA, PF_NO_INTERACTIVE_LOGIN, PF_USER_AGENT, USER_AGENT
from promptflow._core.tool_meta_generator import (
generate_flow_meta_dict_by_file,
generate_tool_meta,
generate_tool_meta_in_subprocess,
)
from promptflow._core.tools_manager import gen_dynamic_list, retrieve_tool_func_result
from promptflow._sdk._constants import (
AZURE_WORKSPACE_REGEX_FORMAT,
DAG_FILE_NAME,
Expand Down Expand Up @@ -553,6 +547,8 @@ def _generate_tool_meta(
If set to False, will load tool meta in sync mode and timeout need to be handled outside current process.
:return: tool meta dict
"""
from promptflow._core.tool_meta_generator import generate_tool_meta, generate_tool_meta_in_subprocess

tools = _construct_tool_dict(tools)
if load_in_subprocess:
# use multiprocess generate to avoid system path disturb
Expand Down Expand Up @@ -603,6 +599,8 @@ def _retrieve_tool_func_result(func_call_scenario: str, function_config: Dict):
:param function_config: function config in tool meta. Should contain'func_path' and 'func_kwargs'.
:return: func call result according to func_call_scenario.
"""
from promptflow._core.tools_manager import retrieve_tool_func_result

func_path = function_config.get("func_path", "")
func_kwargs = function_config.get("func_kwargs", {})
# May call azure control plane api in the custom function to list Azure resources.
Expand All @@ -627,6 +625,8 @@ def _gen_dynamic_list(function_config: Dict) -> List:
:param function_config: function config in tool meta. Should contain'func_path' and 'func_kwargs'.
:return: a list of tool input dynamic enums.
"""
from promptflow._core.tools_manager import gen_dynamic_list

func_path = function_config.get("func_path", "")
func_kwargs = function_config.get("func_kwargs", {})
# May call azure control plane api in the custom function to list Azure resources.
Expand Down Expand Up @@ -1189,6 +1189,8 @@ def parse_otel_span_status_code(value: int) -> str:


def _generate_meta_from_file(working_dir, source_path, entry, meta_dict, exception_list):
from promptflow._core.tool_meta_generator import generate_flow_meta_dict_by_file

with _change_working_dir(working_dir), inject_sys_path(working_dir):
try:
result = generate_flow_meta_dict_by_file(
Expand Down
3 changes: 2 additions & 1 deletion src/promptflow/promptflow/executor/_script_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from promptflow._constants import LINE_NUMBER_KEY
from promptflow._core.run_tracker import RunTracker
from promptflow._core.tool_meta_generator import PythonLoadError
from promptflow._core.tracer import Tracer, _traced
from promptflow._utils.dataclass_serializer import convert_eager_flow_output_to_dict
from promptflow._utils.logger_utils import logger
from promptflow._utils.tool_utils import function_to_interface
Expand All @@ -17,6 +16,8 @@
from promptflow.executor._result import LineResult
from promptflow.storage import AbstractRunStorage
from promptflow.storage._run_storage import DefaultRunStorage
from promptflow.tracing._trace import _traced
from promptflow.tracing._tracer import Tracer

from .flow_executor import FlowExecutor

Expand Down
14 changes: 7 additions & 7 deletions src/promptflow/promptflow/executor/flow_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
from promptflow._core.run_tracker import RunTracker
from promptflow._core.tool import STREAMING_OPTION_PARAMETER_ATTR
from promptflow._core.tools_manager import ToolsManager
from promptflow._core.tracer import (
enrich_span_with_context,
enrich_span_with_input,
enrich_span_with_trace_type,
open_telemetry_tracer,
)
from promptflow._utils.context_utils import _change_working_dir
from promptflow._utils.execution_utils import (
apply_default_value_for_input,
Expand All @@ -50,7 +44,6 @@
from promptflow.contracts.flow import Flow, FlowInputDefinition, InputAssignment, InputValueType, Node
from promptflow.contracts.run_info import FlowRunInfo, Status
from promptflow.contracts.run_mode import RunMode
from promptflow.contracts.trace import TraceType
from promptflow.exceptions import PromptflowException
from promptflow.executor import _input_assignment_parser
from promptflow.executor._async_nodes_scheduler import AsyncNodesScheduler
Expand All @@ -65,6 +58,13 @@
from promptflow.executor.flow_validator import FlowValidator
from promptflow.storage import AbstractRunStorage
from promptflow.storage._run_storage import DefaultRunStorage
from promptflow.tracing._trace import (
enrich_span_with_context,
enrich_span_with_input,
enrich_span_with_trace_type,
open_telemetry_tracer,
)
from promptflow.tracing.contracts.trace import TraceType


class FlowExecutor:
Expand Down
3 changes: 2 additions & 1 deletion src/promptflow/promptflow/integrations/langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from langchain.callbacks.base import BaseCallbackHandler
from langchain.schema import AgentAction, AgentFinish, LLMResult

from promptflow._core.tracer import Trace, Tracer, TraceType
from promptflow.tracing._tracer import Tracer
from promptflow.tracing.contracts.trace import Trace, TraceType


class LangChainEventType(Enum):
Expand Down
3 changes: 2 additions & 1 deletion src/promptflow/promptflow/tracing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore

from ._start_trace import start_trace
from ._trace import trace

__all__ = ["start_trace"]
__all__ = ["start_trace", "trace"]
Loading

0 comments on commit b4573c9

Please sign in to comment.