Skip to content

Commit

Permalink
[Tracing] Remove dependence of tracing on jinja2 (#2369)
Browse files Browse the repository at this point in the history
# Description

Since the promptflow-tracing package should only depend on openai and
opentelemetry, we should remove the dependence of tracing on jinja2.

# 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
- [ ] Pull request includes test coverage for the included changes.

---------

Co-authored-by: Lina Tang <linatang@microsoft.com>
  • Loading branch information
lumoslnt and Lina Tang authored Mar 15, 2024
1 parent a8bee4b commit 4cf6b54
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/promptflow/promptflow/tracing/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from dataclasses import fields, is_dataclass
from datetime import datetime
from enum import Enum
from jinja2 import Environment, meta
from typing import Callable, Dict

from .contracts.generator_proxy import GeneratorProxy
Expand Down Expand Up @@ -59,6 +58,13 @@ def serialize(value: object, remove_null: bool = False, serialization_funcs: Dic


def get_input_names_for_prompt_template(template_str):
try:
# We need to parse jinja template only when the promptflow is installed and run flow with PromptTemplate
# type input, so using try-catch to avoid the dependency of jinja2 when it's not needed.
from jinja2 import Environment, meta
except ImportError:
return []

input_names = []
env = Environment()
template = env.parse(template_str)
Expand Down

0 comments on commit 4cf6b54

Please sign in to comment.