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

Update executable template #2567

Merged
merged 75 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
5bef68f
update
Mar 20, 2024
3e029a3
Merge branch 'main' into dev/chenyin/pf_service
Mar 20, 2024
95c9008
flake8
Mar 20, 2024
4cf6853
typo
Mar 21, 2024
9783dfd
show log file
Mar 21, 2024
9e7293c
Merge branch 'main' into dev/chenyin/pf_service
Mar 22, 2024
e02fba9
update msi pf
Mar 22, 2024
00ac975
update linux install
Mar 22, 2024
f0d7280
update linux install
Mar 22, 2024
34fff6c
flake8
Mar 22, 2024
ffec639
update description
Mar 26, 2024
1019ff5
Merge branch 'main' into dev/chenyin/pf_service
Mar 26, 2024
e1a65e2
Merge branch 'main' into dev/chenyin/pf_service
Mar 27, 2024
6e4b201
Merge branch 'main' into dev/chenyin/pf_service
Mar 28, 2024
5a2ee9f
update test
Mar 28, 2024
c8b12f7
update
Mar 28, 2024
c34a1d7
Merge branch 'main' into dev/chenyin/pf_service
Mar 28, 2024
242e58e
Fix
crazygao Mar 28, 2024
b7f860f
Fix
crazygao Mar 28, 2024
b14aeb9
Merge branch 'main' into dev/chenyin/pf_service
Mar 29, 2024
696c1cf
Fix
crazygao Mar 29, 2024
9a448bb
Fix
crazygao Mar 29, 2024
efe4e18
Merge branch 'main' into yigao/fix_upgrade
crazygao Mar 29, 2024
d42afca
Merge branch 'yigao/fix_upgrade' of github.com:microsoft/promptflow i…
crazygao Mar 29, 2024
e013424
remove pfs in toml
Mar 29, 2024
b200128
test ci
Mar 29, 2024
5ab7ab7
add logger to debug
Mar 29, 2024
71d3b10
update pf entry
Mar 29, 2024
0b89e73
revert
Mar 29, 2024
1468ac0
revert
Mar 29, 2024
337c040
Fix
crazygao Mar 29, 2024
70b8c62
Fix
crazygao Mar 29, 2024
ed66543
Merge branch 'main' into dev/chenyin/pf_service
Mar 29, 2024
fc71324
Fix
crazygao Mar 29, 2024
faa0e13
Merge branch 'main' into dev/chenyin/pf_service
Mar 29, 2024
ebbd9af
Merge branch 'main' into yigao/fix_upgrade
crazygao Mar 29, 2024
8fe5461
Fix
crazygao Mar 29, 2024
d2cabaf
Fix
crazygao Mar 29, 2024
74cd93c
Merge branch 'main' into yigao/fix_upgrade
crazygao Mar 29, 2024
7324751
Merge branch 'main' into dev/chenyin/pf_service
Mar 30, 2024
989fcbf
update
Mar 30, 2024
38bc484
Merge branch 'dev/chenyin/pf_service' into dev/chenyin/update_executable
Mar 30, 2024
6a2cbb2
update
Mar 30, 2024
5be1f10
update
Mar 30, 2024
01ceb49
update
Mar 30, 2024
ef1efa7
support start pf
Apr 1, 2024
a3587e3
Fix
crazygao Apr 1, 2024
640ab12
update streamlit entry code
Apr 1, 2024
f69d5d7
[Internal] _skip_tracing_local_setup should also skip trace related s…
riddlexu Mar 29, 2024
d9f8bde
[Internal][Executor] Add try-catch to handle HttpError or UnexpectedE…
PeiwenGaoMS Mar 29, 2024
b683c8e
[devkit][bugfix] Use SQLAlchemy 1.x style ORM (#2560)
zhengfeiwang Mar 31, 2024
7a7bcbe
Update test matrix (#2539)
brynn-code Apr 1, 2024
722b339
Fix
crazygao Apr 1, 2024
e460a3e
Fix
crazygao Apr 1, 2024
e1476b8
Merge branch 'main' into dev/chenyin/update_executable
Apr 1, 2024
2b5c836
Merge branch 'main' into yigao/fix_upgrade
crazygao Apr 1, 2024
aa33be0
Fix
crazygao Apr 1, 2024
29e3781
Fix
crazygao Apr 1, 2024
3b003af
flake8
crazygao Apr 1, 2024
c0788a9
update
Apr 1, 2024
8a33bf3
Merge branch 'yigao/fix_upgrade' into dev/chenyin/update_executable
Apr 1, 2024
7b0ac3a
remove debug
Apr 1, 2024
806f1cd
Merge branch 'main' into dev/chenyin/update_executable
Apr 1, 2024
d94f0cd
remove toml import
Apr 1, 2024
01a86ea
Merge branch 'main' into dev/chenyin/update_executable
Apr 1, 2024
1e54bcf
Merge branch 'main' into dev/chenyin/update_executable
Apr 1, 2024
99affcf
update linux argvs
Apr 1, 2024
498dbe8
onefile mode and add x for pf in linux
Apr 1, 2024
57d9050
update
Apr 1, 2024
ff0cc4e
typo
Apr 2, 2024
258657b
Merge branch 'main' into dev/chenyin/update_executable
Apr 2, 2024
2a8bb85
add promptflow-evals in doc ci
Apr 2, 2024
b51b08a
update
Apr 2, 2024
faf244b
revert
Apr 2, 2024
00fe9f3
Merge branch 'main' into dev/chenyin/update_executable
Apr 2, 2024
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
5 changes: 4 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@
"pywin",
"STARTF",
"mltable",
"setenv"
"setenv",
"cscript",
"nologo",
"wscript"
],
"flagWords": [
"Prompt Flow"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ def is_run_from_built_binary():

Allow customer to use environment variable to control the triggering.
"""
return sys.executable.endswith("pfcli.exe") or os.environ.get(PF_RUN_AS_BUILT_BINARY, "").lower() == "true"
return (not sys.executable.endswith("python.exe") and not sys.executable.endswith("python")) or os.environ.get(
PF_RUN_AS_BUILT_BINARY, ""
).lower() == "true"


def encrypt_flow_path(flow_path):
Expand Down
21 changes: 17 additions & 4 deletions src/promptflow-devkit/promptflow/_sdk/_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import json
import os
import subprocess
import sys
import typing
import urllib.parse

Expand All @@ -14,7 +16,6 @@
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor

from promptflow._cli._pf.entry import entry
from promptflow._constants import (
OTEL_RESOURCE_SERVICE_NAME,
SpanAttributeFieldName,
Expand All @@ -29,7 +30,12 @@
AzureMLWorkspaceTriad,
ContextAttributeKey,
)
from promptflow._sdk._service.utils.utils import get_port_from_config, is_pfs_service_healthy, is_port_in_use
from promptflow._sdk._service.utils.utils import (
get_port_from_config,
is_pfs_service_healthy,
is_port_in_use,
is_run_from_built_binary,
)
from promptflow._sdk._utils import extract_workspace_triad_from_trace_provider
from promptflow._utils.logger_utils import get_cli_sdk_logger
from promptflow.tracing._integrations._openai_injector import inject_openai_api
Expand Down Expand Up @@ -61,7 +67,12 @@ def _inject_attrs_to_op_ctx(attrs: typing.Dict[str, str]) -> None:
def _invoke_pf_svc() -> str:
port = get_port_from_config(create_if_not_exists=True)
port = str(port)
cmd_args = ["service", "start", "--port", port]
if is_run_from_built_binary():
interpreter_path = os.path.abspath(sys.executable)
pf_path = os.path.join(os.path.dirname(interpreter_path), "pf")
cmd_args = [pf_path, "service", "start", "--port", port]
else:
cmd_args = ["pf", "service", "start", "--port", port]
hint_stop_message = (
f"You can stop the Prompt flow Tracing Server with the following command:'\033[1m pf service stop\033[0m'.\n"
f"Alternatively, if no requests are made within {PF_SERVICE_HOUR_TIMEOUT} "
Expand All @@ -75,7 +86,9 @@ def _invoke_pf_svc() -> str:
print(hint_stop_message)
return port
print("Starting Prompt flow Tracing Server...")
entry(cmd_args)
start_pfs = subprocess.Popen(cmd_args, shell=True)
# Wait for service to be started
start_pfs.wait()
logger.debug("Prompt flow service is serving on port %s", port)
print(hint_stop_message)
return port
Expand Down
38 changes: 24 additions & 14 deletions src/promptflow-devkit/promptflow/_sdk/data/executable/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import multiprocessing
import os
import sys

Expand Down Expand Up @@ -25,18 +26,27 @@ def create_connections(directory_path) -> None:


if __name__ == "__main__":

create_connections(os.path.join(os.path.dirname(__file__), "connections"))
if exists():
start()
multiprocessing.freeze_support()
command = sys.argv[1] if len(sys.argv) > 1 else None
print(f"Command: {command}")
print(sys.argv)
if command == "pf":
sys.argv = sys.argv[1:]
from promptflow._cli._pf.entry import main as pf_main

pf_main()
else:
main_script = os.path.join(os.path.dirname(__file__), "main.py")
sys.argv = [
"streamlit",
"run",
main_script,
"--global.developmentMode=false",
"--client.toolbarMode=viewer",
"--browser.gatherUsageStats=false",
]
st_cli.main(prog_name="streamlit")
create_connections(os.path.join(os.path.dirname(__file__), "connections"))
if exists():
start()
else:
main_script = os.path.join(os.path.dirname(__file__), "main.py")
sys.argv = [
"streamlit",
"run",
main_script,
"--global.developmentMode=false",
"--client.toolbarMode=viewer",
"--browser.gatherUsageStats=false",
]
st_cli.main(prog_name="streamlit")
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
# -*- mode: python ; coding: utf-8 -*-
import sys
from PyInstaller.utils.hooks import collect_data_files
from PyInstaller.utils.hooks import copy_metadata
from PyInstaller.utils.hooks import collect_data_files, collect_all, copy_metadata

sys.setrecursionlimit(sys.getrecursionlimit() * 5)

datas = [('connections', 'connections'), ('flow', 'flow'), ('settings.json', '.'), ('main.py', '.'), ('utils.py', '.'), ('logo.png', '.'), ('config.json', '.'), ('{{runtime_interpreter_path}}', './streamlit/runtime')]
datas += collect_data_files('streamlit')
datas += copy_metadata('streamlit')
datas = [('connections', 'connections'), ('flow', 'flow'), ('settings.json', '.'), ('main.py', '.'), ('utils.py', '.'),
('logo.png', '.'), ('config.json', '.'), ('{{runtime_interpreter_path}}', './streamlit/runtime')]


all_packages = {{all_packages}}
meta_packages = ['opentelemetry-api'] + {{meta_packages}}

for package in all_packages:
datas += collect_data_files(package)

for package in meta_packages:
datas += copy_metadata(package)

opentelemetry_datas, opentelemetry_binaries, opentelemetry_hiddenimports = collect_all('opentelemetry')
promptflow_datas, promptflow_binaries, promptflow_hiddenimports = collect_all('promptflow')

datas += opentelemetry_datas
datas += promptflow_datas
datas += collect_data_files('streamlit_quill')
datas += collect_data_files('keyrings.alt', include_py_files=True)
datas += copy_metadata('keyrings.alt')
datas += collect_data_files('streamlit_quill')

hidden_imports = ['win32timezone', 'opentelemetry.context.contextvars_context', 'streamlit.runtime.scriptrunner.magic_funcs'] + {{hidden_imports}}
hidden_imports += opentelemetry_hiddenimports
hidden_imports += promptflow_hiddenimports

binaries = []
binaries += opentelemetry_binaries
binaries += promptflow_binaries

block_cipher = None

a = Analysis(
pfcli_a = Analysis(
['app.py', 'main.py', 'utils.py'],
pathex=[],
binaries=[],
binaries=binaries,
datas=datas,
hiddenimports={{hidden_imports}},
hiddenimports=hidden_imports,
hookspath=[],
hooksconfig={},
runtime_hooks=[],
Expand All @@ -29,26 +51,34 @@ a = Analysis(
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
pfcli_pyz = PYZ(pfcli_a.pure, pfcli_a.zipped_data, cipher=block_cipher)

pfcli_exe = EXE(
pfcli_pyz,
pfcli_a.scripts,
[],
exclude_binaries=True,
name='app',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
contents_directory='.',
)

coll = COLLECT(
YingChen1996 marked this conversation as resolved.
Show resolved Hide resolved
pfcli_exe,
pfcli_a.binaries,
pfcli_a.zipfiles,
pfcli_a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='app',
)
16 changes: 8 additions & 8 deletions src/promptflow-devkit/promptflow/_sdk/data/executable/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ def post_process_dump_result(response, session_state_history, *, generator_recor
# Just use BasicMultimediaProcessor to keep the original logic here.
# TODO: Add support for other multimedia types
multimedia_processor = BasicMultimediaProcessor()
multimedia_response = {
k: multimedia_processor.load_multimedia_data_recursively(v) for k, v in response.output.items()
}
resolved_outputs = {
k: multimedia_processor.convert_multimedia_data_to_base64_dict(v) for k, v in response.output.items()
k: multimedia_processor.convert_multimedia_data_to_base64_dict(v) for k, v in multimedia_response.items()
}
st.session_state.messages.append(("assistant", resolved_outputs))
session_state_history.update({"outputs": response.output})
st.session_state.history.append(session_state_history)
if is_chat_flow:
dump_path = Path(flow_path).parent
response.output = multimedia_processor.persist_multimedia_data(
response.output, base_dir=dump_path, sub_dir=Path(".promptflow/output")
)
dump_flow_result(flow_folder=dump_path, flow_result=response, prefix="chat")
return resolved_outputs

Expand All @@ -71,14 +71,14 @@ def submit(**kwargs) -> None:
session_state_history.update({"inputs": kwargs})
with container:
render_message("user", kwargs)
# Force append chat history to kwargs
if is_chat_flow:
kwargs[chat_history_input_name] = get_chat_history_from_session()

flow = load_flow(flow_path)
with TestSubmitter(flow=flow, flow_context=flow.context).init(stream_output=is_streaming) as submitter:
# can't exit the context manager before the generator is fully consumed
response = submitter.flow_test(inputs=kwargs, allow_generator_output=is_streaming)
response = submitter.flow_test(
inputs={chat_history_input_name: get_chat_history_from_session(), **kwargs},
allow_generator_output=is_streaming,
)

if response.run_info.status.value == "Failed":
raise Exception(response.run_info.error)
Expand Down
15 changes: 15 additions & 0 deletions src/promptflow-devkit/promptflow/_sdk/data/executable/pf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

MAIN_EXE="./app"

# Check if the first argument is 'service'
if [ "$1" == "service" ]; then
# Check if the second argument is 'start'
if [ "$2" == "start" ]; then
nohup "$MAIN_EXE" pf "${@:1}" > output.txt 2>&1 &
else
"$MAIN_EXE" pf "${@:1}"
fi
else
"$MAIN_EXE" pf "${@:1}"
fi
21 changes: 21 additions & 0 deletions src/promptflow-devkit/promptflow/_sdk/data/executable/pf.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@echo off
setlocal


set MAIN_EXE=%~dp0.\app.exe
REM Check if the first argument is 'start'
if "%~1"=="service" (
REM Check if the second argument is 'start'
if "%~2"=="start" (
echo Starting service...
echo %*
cscript //nologo %~dp0.\start_pfs.vbs """%MAIN_EXE%"" pf %*"
REM since we won't wait for vbs to finish, we need to wait for the output file to be flushed to disk
timeout /t 5 >nul
type "%~dp0output.txt"
) else (
"%MAIN_EXE%" pf %*
)
) else (
"%MAIN_EXE%" pf %*
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DIM objshell
YingChen1996 marked this conversation as resolved.
Show resolved Hide resolved
set objshell = wscript.createobject("wscript.shell")
cmd = WScript.Arguments(0)
iReturn = objshell.run(cmd, 0, false)
Loading
Loading