Skip to content

Commit

Permalink
[Chat window] Expose chat window and add enable_internal_features que…
Browse files Browse the repository at this point in the history
…ry in chat url (#2941)

# Description

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
YingChen1996 authored Apr 23, 2024
1 parent 7d50227 commit 8e523e4
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions src/promptflow-devkit/promptflow/_cli/_pf/_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

DEFAULT_CONNECTION = "open_ai_connection"
DEFAULT_DEPLOYMENT = "gpt-35-turbo"
PF_CHAT_UI_ENABLE_STREAMLIT = "pf_chat_ui_enable_streamlit"
logger = get_cli_sdk_logger()


Expand Down Expand Up @@ -479,25 +480,9 @@ def _build_inputs_for_flow_test(args):

def _test_flow_multi_modal(args, pf_client):
"""Test flow with multi modality mode."""
from promptflow._sdk._load_functions import load_flow

if Configuration.get_instance().is_internal_features_enabled():
from promptflow._sdk._tracing import _invoke_pf_svc

# Todo: use base64 encode for now, will consider whether need use encryption or use db to store flow path info
def generate_url(flow_path, port):
encrypted_flow_path = encrypt_flow_path(flow_path)
query_params = urlencode({"flow": encrypted_flow_path})
return urlunparse(("http", f"127.0.0.1:{port}", "/v1.0/ui/chat", "", query_params, ""))
if str(os.getenv(PF_CHAT_UI_ENABLE_STREAMLIT, "false")).lower() == "true":
from promptflow._sdk._load_functions import load_flow

pfs_port = _invoke_pf_svc()
flow_path_dir, flow_path_file = resolve_flow_path(args.flow)
flow_path = str(flow_path_dir / flow_path_file)
chat_page_url = generate_url(flow_path, pfs_port)
print(f"You can begin chat flow on {chat_page_url}")
if not args.skip_open_browser:
webbrowser.open(chat_page_url)
else:
if is_flex_flow(flow_path=args.flow):
error = ValueError("Only support dag yaml in streamlit ui.")
raise UserErrorException(
Expand All @@ -521,6 +506,25 @@ def generate_url(flow_path, port):
main_script_path = os.path.join(temp_dir, "main.py")
logger.info("Start streamlit with main script generated at: %s", main_script_path)
pf_client.flows._chat_with_ui(script=main_script_path, skip_open_browser=args.skip_open_browser)
else:
from promptflow._sdk._tracing import _invoke_pf_svc

# Todo: use base64 encode for now, will consider whether need use encryption or use db to store flow path info
def generate_url(flow_path, port):
encrypted_flow_path = encrypt_flow_path(flow_path)
query_dict = {"flow": encrypted_flow_path}
if Configuration.get_instance().is_internal_features_enabled():
query_dict.update({"enable_internal_features": "true"})
query_params = urlencode(query_dict)
return urlunparse(("http", f"127.0.0.1:{port}", "/v1.0/ui/chat", "", query_params, ""))

pfs_port = _invoke_pf_svc()
flow_path_dir, flow_path_file = resolve_flow_path(args.flow)
flow_path = str(flow_path_dir / flow_path_file)
chat_page_url = generate_url(flow_path, pfs_port)
print(f"You can begin chat flow on {chat_page_url}")
if not args.skip_open_browser:
webbrowser.open(chat_page_url)


def _test_flow_interactive(args, pf_client, inputs, environment_variables):
Expand Down

0 comments on commit 8e523e4

Please sign in to comment.