Skip to content

Commit

Permalink
fix: remove connection reference in python tool
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotzh committed Oct 19, 2023
1 parent 9bfba90 commit ecfa0b8
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This is a dummy pipeline job with anonymous reference of a flow as a component. Flow directory is copied from [sample in promptflow repository](https://github.com/microsoft/promptflow/tree/main/examples/flows/standard/basic).
This is a dummy pipeline job with anonymous reference of a flow as a component. Flow directory is copied from [sample in promptflow repository](https://github.com/microsoft/promptflow/tree/main/examples/flows/standard/basic) and remove connection dependency to avoid using promptflow connection in azure ml example repository.

Prerequirements:
1. `.promptflow/flow.tools.json` in the flow directory is required to use a flow as a component. Usually you can use `pf flow validate` or `pf run validate` to generate it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,5 @@ def my_python_tool(
api_version=os.environ.get("AZURE_OPENAI_API_VERSION", "2023-07-01-preview"),
)

# TODO: remove below type conversion after client can pass json rather than string.
echo = to_bool(echo)

response = openai.Completion.create(
prompt=prompt,
engine=deployment_name,
# empty string suffix should be treated as None.
suffix=suffix if suffix else None,
max_tokens=int(max_tokens),
temperature=float(temperature),
top_p=float(top_p),
n=int(n),
logprobs=int(logprobs) if logprobs else None,
echo=echo,
# fix bug "[] is not valid under any of the given schemas-'stop'"
stop=stop if stop else None,
presence_penalty=float(presence_penalty),
frequency_penalty=float(frequency_penalty),
best_of=int(best_of),
# Logit bias must be a dict if we passed it to openai api.
logit_bias=logit_bias if logit_bias else {},
user=user,
request_timeout=30,
**conn,
)

# get first element because prompt is single.
return response.choices[0].text
# return directly to avoid using promptflow connection in azure ml example repository
return f"fake answer based on {prompt}"
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ jobs:
component: ./basic/flow.dag.yaml
inputs:
data: ${{parent.inputs.flow_input}}
url: "${data.text}"
text: "${data.text}"
outputs:
flow_outputs: ${{parent.outputs.output_data}}
debug_info: ${{parent.outputs.debug_info}}
environment_variables:
# environment variables from connection
AZURE_OPENAI_API_KEY: ${open_ai_connection.api_key}
AZURE_OPENAI_API_BASE: ${open_ai_connection.api_base}
AZURE_OPENAI_API_TYPE: azure

flow_node_from_run:
type: parallel
component: ./run.yaml
component: ./run.yml
inputs:
data: ${{parent.inputs.flow_input}}
url: "${data.text}"
text: "${data.text}"

This file was deleted.

2 changes: 1 addition & 1 deletion sdk/python/jobs/pipelines/1l_flow_in_pipeline/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This is a dummy pipeline job with anonymous reference of a flow as a component. This example has reused the flow in corresponding CLI example, which is copied from [sample in promptflow repository](https://github.com/microsoft/promptflow/tree/main/examples/flows/standard/basic). Please check [this path](../../../../../cli/jobs/pipelines-with-components/pipeline_job_with_flow_as_component/) for dependent resources.
This is a dummy pipeline job with anonymous reference of a flow as a component. This example has reused the flow in corresponding CLI example, which is copied from [sample in promptflow repository](https://github.com/microsoft/promptflow/tree/main/examples/flows/standard/basic) and remove connection dependency to avoid using promptflow connection in azure ml example repository. Please check [this path](../../../../../cli/jobs/pipelines-with-components/pipeline_job_with_flow_as_component/) for dependent resources.

References:
- [microsoft/promptflow: Build high-quality LLM apps](https://github.com/microsoft/promptflow)
Expand Down

0 comments on commit ecfa0b8

Please sign in to comment.