Skip to content

Commit

Permalink
[PF run] Update cwd when additional includes exist (#709)
Browse files Browse the repository at this point in the history
# Description
When user code uses the files in additional include, pf run will raise
ModuleNotFound error.
Error msg: Failed to load python module from file
'/tmp/tmprzerq2_9/flow/prepare_examples.py', reason: [Errno 2] No such
file or directory: 'fetch_text_content_from_url.py'."

![image](https://github.com/microsoft/promptflow/assets/17938940/ab00d1b8-c406-4b29-b873-e3a515e1f609)


Please add an informative description that covers that changes made by
the pull request and link all relevant issues.

# 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.
  • Loading branch information
lalala123123 authored Oct 12, 2023
1 parent 44bf79b commit db6bd64
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/promptflow/promptflow/_sdk/operations/_flow_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from promptflow._sdk.entities._validation import ValidationResult
from promptflow._sdk.operations._run_submitter import remove_additional_includes, variant_overwrite_context
from promptflow._sdk.operations._test_submitter import TestSubmitter
from promptflow._utils.context_utils import _change_working_dir
from promptflow.exceptions import UserErrorException


Expand Down Expand Up @@ -289,12 +290,14 @@ def _export_flow_connections(
):
from promptflow.contracts.flow import Flow as ExecutableFlow

executable = ExecutableFlow.from_yaml(flow_file=Path(flow_dag_path.name), working_dir=flow_dag_path.parent)
executable = ExecutableFlow.from_yaml(flow_file=Path(flow_dag_path.name),
working_dir=flow_dag_path.parent.absolute())

return self._migrate_connections(
connection_names=executable.get_connection_names(),
output_dir=output_dir,
)
with _change_working_dir(flow_dag_path.parent):
return self._migrate_connections(
connection_names=executable.get_connection_names(),
output_dir=output_dir,
)

def _build_flow(
self,
Expand Down
3 changes: 2 additions & 1 deletion src/promptflow/promptflow/_sdk/operations/_run_submitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ def _run_bulk(self, run: Run, stream=False, **kwargs):

def _submit_bulk_run(self, flow: Flow, run: Run, local_storage: LocalStorageOperations) -> dict:
run_id = run.name
connections = SubmitterHelper.resolve_connections(flow=flow)
with _change_working_dir(flow.code):
connections = SubmitterHelper.resolve_connections(flow=flow)
column_mapping = run.column_mapping
# resolve environment variables
SubmitterHelper.resolve_environment_variables(environment_variables=run.environment_variables)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from pathlib import Path
from promptflow import tool

# read file from additional includes
lines = open(r"fetch_text_content_from_url.py", "r").readlines()


@tool
def prepare_examples():
Expand Down

0 comments on commit db6bd64

Please sign in to comment.