Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection override fix #2746

Merged
merged 4 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------
import copy
import tempfile
from functools import lru_cache
from os import PathLike
Expand Down Expand Up @@ -82,7 +83,7 @@ def _resolve_connections(self, flow_context: FlowContext) -> "FlowContextResolve

overwrite_connections(
flow_dag=self.flow_dag,
connections=flow_context.connections,
singankit marked this conversation as resolved.
Show resolved Hide resolved
connections=copy.deepcopy(flow_context.connections),
working_dir=self.working_dir,
)
return self
singankit marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
14 changes: 14 additions & 0 deletions src/promptflow/tests/sdk_cli_test/e2etests/test_flow_as_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,17 @@ def test_flow_with_default_variant(self, azure_open_ai_connection):
)
# function can successfully run with connection override
f(url="https://www.youtube.com/watch?v=o5ZQyXaAv1g")

def test_flow_with_connection_override(self, azure_open_ai_connection):
f = load_flow(f"{FLOWS_DIR}/llm_tool_non_existing_connection")
with pytest.raises(ConnectionNotFoundError):
f(joke="joke")
f.context = FlowContext(
connections={
"joke": {"connection": azure_open_ai_connection},
}
)
# function can successfully run with connection override
f(topic="joke")
# This should work on subsequent call not just first
f(topic="joke")
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from promptflow.core import tool


@tool
def echo(input: str) -> str:
return input
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
inputs:
topic:
type: string
default: hello world
is_chat_input: false
stream:
type: bool
default: false
is_chat_input: false
outputs:
joke:
type: string
reference: ${echo.output}
nodes:
- name: echo
type: python
source:
type: code
path: echo.py
inputs:
input: ${joke.output}
use_variants: false
- name: joke
type: llm
source:
type: code
path: joke.jinja2
inputs:
deployment_name: gpt-35-turbo
temperature: 1
top_p: 1
max_tokens: 256
presence_penalty: 0
frequency_penalty: 0
stream: ${inputs.stream}
topic: ${inputs.topic}
provider: AzureOpenAI
connection: azure_open_ai_missing_connection
api: chat
module: promptflow.tools.aoai
use_variants: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{# Prompt is a jinja2 template that generates prompt for LLM #}

system:

You are a bot can tell good jokes

user:

A joke about {{topic}} please
Loading