Skip to content

Commit

Permalink
[Bugfix] Fix the bug that generator in subflow would fail. (#3357)
Browse files Browse the repository at this point in the history
# Description

Bugfix for #3355 

This pull request includes a significant change in the
`update_and_persist_generator_node_runs` method in the
`src/promptflow-core/promptflow/_core/run_tracker.py` file. The change
primarily focuses on adding a condition to check if `api_calls` for a
`node_run_info` exists before proceeding with the update. This change is
important as it takes into account scenarios where `api_calls` for the
node run might not exist, such as in a flow as function/serving. In such
cases, the update is skipped.

Additionally, the method of accessing the `output` from `api_calls` has
been changed from direct indexing to using the `get` method, which is a
safer way to access dictionary values.

*
[`src/promptflow-core/promptflow/_core/run_tracker.py`](diffhunk://#diff-a5027d19a24cb28a68ead16dfe6c54492c78d6e0e7640e80533928808cdb3422R451-R457):
Added a condition to check if `api_calls` exists for `node_run_info`
before updating it. This accounts for scenarios where `api_calls` for
the node run might not exist. Also, changed the way `output` is accessed
from `api_calls` by using the `get` method instead of direct indexing.
# All Promptflow Contribution checklist:
- [ ] **The pull request does not introduce [breaking changes].**
- [ ] **CHANGELOG is updated for new features, bug fixes or other
significant changes.**
- [ ] **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
- [ ] Title of the pull request is clear and informative.
- [ ] 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.

---------

Signed-off-by: Brynn Yin <[email protected]>
Co-authored-by: Heyi <[email protected]>
Co-authored-by: Brynn Yin <[email protected]>
  • Loading branch information
3 people authored May 31, 2024
1 parent 618d86c commit e31d8e0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/promptflow-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

### Bugs fixed
- Fix ChatUI can't work in docker container when running image build with `pf flow build`.
- Fix [#3355](https://github.com/microsoft/promptflow/issues/3355) that IndexError is raised when generator is used in a flow and the flow is called inside another flow.

## v1.11.0 (2024.05.17)

Expand Down
6 changes: 5 additions & 1 deletion src/promptflow-core/promptflow/_core/run_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,13 @@ def update_and_persist_generator_node_runs(self, run_id: str, node_names: List[s
run_info for run_info in self.collect_child_node_runs(run_id) if run_info.node in node_names
)
for node_run_info in selected_node_run_info:
if not node_run_info.api_calls:
# Note that in some scenario (flow as function/serving), we don't have api_calls for the node run,
# we don't need to update it.
continue
# Update the output of the node run with the output in the trace.
# This is because the output in the trace would includes the generated items.
output_in_trace = node_run_info.api_calls[0]["output"]
output_in_trace = node_run_info.api_calls[0].get("output")
node_run_info.output = output_in_trace
# Update the openai metrics for the node run, since we can calculator the
# completion tokens from the generated output.
Expand Down
3 changes: 1 addition & 2 deletions src/promptflow/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

### Bugs fixed
- [promptflow-core] Fix ChatUI can't work in docker container when running image build with `pf flow build`.

## v1.12.0 (Upcoming)
- [promptflow-core] Fix [#3355](https://github.com/microsoft/promptflow/issues/3355) that IndexError is raised when generator is used in a flow and the flow is called inside another flow.

### Improvements
- [promptflow-devkit] Add retry logic when uploading run details to cloud.
Expand Down

0 comments on commit e31d8e0

Please sign in to comment.