diff --git a/examples/flows/standard/flow-with-additional-includes/README.md b/examples/flows/standard/flow-with-additional-includes/README.md index a447b19f893..f79399f763d 100644 --- a/examples/flows/standard/flow-with-additional-includes/README.md +++ b/examples/flows/standard/flow-with-additional-includes/README.md @@ -39,7 +39,7 @@ additional_includes: ### 2. Test & run the flow with additional includes In this sample, this flow will references some files in the [web-classification](../web-classification/README.md) flow. -You can execute this flow with additional_include locally or submit it to cloud. +You can execute this flow with additional_include locally or submit it to cloud. The snapshot generated by Promptflow contains additional include files/folders. #### Test flow with single line data @@ -60,7 +60,6 @@ pf run create --flow . --data ./data.jsonl --stream # create run using yaml file pf run create --file run.yml --stream ``` -Note: the snapshot folder in run should contain the additional_includes file. #### Submit run to cloud @@ -72,4 +71,4 @@ Note: the snapshot folder in run should contain the additional_includes file. # pfazure run create --file run.yml --stream # serverless compute ``` -Note: the snapshot folder in run should contain the additional_includes file. Click portal_url of the run to view the final snapshot. \ No newline at end of file +Note: Click portal_url of the run to view the final snapshot. \ No newline at end of file diff --git a/examples/flows/standard/intent-copilot/.promptflow/flow.tools.json b/examples/flows/standard/intent-copilot/.promptflow/flow.tools.json index b04cb403c40..45e1b31006c 100644 --- a/examples/flows/standard/intent-copilot/.promptflow/flow.tools.json +++ b/examples/flows/standard/intent-copilot/.promptflow/flow.tools.json @@ -1,7 +1,7 @@ { "package": {}, "code": { - "user_prompt_template": { + "chat_prompt": { "type": "prompt", "inputs": { "customer_info": { @@ -20,17 +20,7 @@ "extract_intent_tool.py": { "type": "python", "inputs": { - "customer_info": { - "type": [ - "string" - ] - }, - "history": { - "type": [ - "list" - ] - }, - "user_prompt_template": { + "chat_prompt": { "type": [ "string" ] diff --git a/examples/flows/standard/intent-copilot/README.md b/examples/flows/standard/intent-copilot/README.md index 9d2448e3bbc..4cee694aa69 100644 --- a/examples/flows/standard/intent-copilot/README.md +++ b/examples/flows/standard/intent-copilot/README.md @@ -18,9 +18,12 @@ cat .env 1. init flow directory - create promptflow folder from existing python file ```bash -pf flow init --flow . --entry intent.py --function extract_intent --prompt-template user_prompt_template=user_intent_zero_shot.jinja2 +pf flow init --flow . --entry intent.py --function extract_intent --prompt-template chat_prompt=user_intent_zero_shot.jinja2 ``` -TODO introduce the generated files +The generated files: +- extract_intent_tool.py: Wrap the func `extract_intent` in the `intent.py` script into a [Python Tool](https://promptflow.azurewebsites.net/tools-reference/python-tool.html). +- flow.dag.yaml: Describes the DAG(Directed Acyclic Graph) of this flow. +- .gitignore: File/folder in the flow to be ignored. 2. create needed custom connection ```bash diff --git a/examples/flows/standard/intent-copilot/extract_intent_tool.py b/examples/flows/standard/intent-copilot/extract_intent_tool.py index 517619c93d4..c698ee978e0 100644 --- a/examples/flows/standard/intent-copilot/extract_intent_tool.py +++ b/examples/flows/standard/intent-copilot/extract_intent_tool.py @@ -7,12 +7,7 @@ @tool -def extract_intent_tool( - customer_info, - history, - user_prompt_template, - connection: CustomConnection -) -> str: +def extract_intent_tool(chat_prompt, connection: CustomConnection) -> str: # set environment variables for key, value in connection.items(): @@ -20,7 +15,5 @@ def extract_intent_tool( # call the entry function return extract_intent( - customer_info=customer_info, - history=history, - user_prompt_template=user_prompt_template, + chat_prompt=chat_prompt, ) diff --git a/examples/flows/standard/intent-copilot/flow.dag.yaml b/examples/flows/standard/intent-copilot/flow.dag.yaml index d0b5b6fcb71..c6e26472d38 100644 --- a/examples/flows/standard/intent-copilot/flow.dag.yaml +++ b/examples/flows/standard/intent-copilot/flow.dag.yaml @@ -1,29 +1,28 @@ -$schema: https://azuremlschemas.azureedge.net/promptflow/latest/Flow.schema.json inputs: + history: + type: string customer_info: type: string - history: - type: list outputs: output: type: string reference: ${extract_intent.output} nodes: -- name: user_prompt_template +- name: chat_prompt type: prompt source: type: code path: user_intent_zero_shot.jinja2 - inputs: {} # Please enter the inputs of this node + inputs: # Please check the generated prompt inputs + history: ${inputs.history} + customer_info: ${inputs.customer_info} - name: extract_intent type: python source: type: code path: extract_intent_tool.py inputs: - customer_info: ${inputs.customer_info} - history: ${inputs.history} - user_prompt_template: ${user_prompt_template.output} + chat_prompt: ${chat_prompt.output} connection: custom_connection environment: python_requirements_txt: requirements.txt diff --git a/examples/flows/standard/intent-copilot/intent.py b/examples/flows/standard/intent-copilot/intent.py index 8fa447b9bb5..c2b246863d4 100644 --- a/examples/flows/standard/intent-copilot/intent.py +++ b/examples/flows/standard/intent-copilot/intent.py @@ -1,11 +1,12 @@ import os import pip -from langchain import LLMChain from langchain.chat_models import AzureChatOpenAI from langchain.prompts.chat import ChatPromptTemplate, HumanMessagePromptTemplate +from langchain.prompts.prompt import PromptTemplate +from langchain.schema import HumanMessage -def extract_intent(customer_info: str, history: list, user_prompt_template: str): +def extract_intent(chat_prompt: str): if "AZURE_OPENAI_API_KEY" not in os.environ: # load environment variables from .env file try: @@ -17,10 +18,6 @@ def extract_intent(customer_info: str, history: list, user_prompt_template: str) load_dotenv() - chat_history_text = "\n".join( - [message["role"] + ": " + message["content"] for message in history] - ) - chat = AzureChatOpenAI( deployment_name=os.environ["CHAT_DEPLOYMENT_NAME"], openai_api_key=os.environ["AZURE_OPENAI_API_KEY"], @@ -29,15 +26,23 @@ def extract_intent(customer_info: str, history: list, user_prompt_template: str) openai_api_version="2023-07-01-preview", temperature=0, ) + reply_message = chat([HumanMessage(content=chat_prompt)]) + return reply_message.content - chat_prompt_template = ChatPromptTemplate.from_messages( - [HumanMessagePromptTemplate.from_template(user_prompt_template)] - ) - chain = LLMChain(llm=chat, prompt=chat_prompt_template) +def generate_prompt(customer_info: str, history: list, user_prompt_template: str): - reply = chain.run(customer_info=customer_info, chat_history=chat_history_text) - return reply + chat_history_text = "\n".join( + [message["role"] + ": " + message["content"] for message in history] + ) + + prompt_template = PromptTemplate.from_template(user_prompt_template) + chat_prompt_template = ChatPromptTemplate.from_messages( + [ + HumanMessagePromptTemplate(prompt=prompt_template) + ] + ) + return chat_prompt_template.format_prompt(customer_info=customer_info, chat_history=chat_history_text).to_string() if __name__ == "__main__": @@ -55,9 +60,8 @@ def extract_intent(customer_info: str, history: list, user_prompt_template: str) # each test for item in data: - reply = extract_intent( - item["customer_info"], item["history"], user_prompt_template - ) + chat_prompt = generate_prompt(item["customer_info"], item["history"], user_prompt_template) + reply = extract_intent(chat_prompt) print("=====================================") # print("Customer info: ", item["customer_info"]) # print("+++++++++++++++++++++++++++++++++++++") diff --git a/examples/flows/standard/intent-copilot/user_intent_zero_shot.jinja2 b/examples/flows/standard/intent-copilot/user_intent_zero_shot.jinja2 index 610e84e578e..0da062bfc03 100644 --- a/examples/flows/standard/intent-copilot/user_intent_zero_shot.jinja2 +++ b/examples/flows/standard/intent-copilot/user_intent_zero_shot.jinja2 @@ -1,12 +1,4 @@ -You are given a list of orders with item_numbers from a customer and a statement from the customer. It is your job to identify - -the intent that the customer has with their statement. Possible intents can be: - -"product return", "product exchange", "general question", "product question", "other". - - - - +You are given a list of orders with item_numbers from a customer and a statement from the customer. It is your job to identify the intent that the customer has with their statement. Possible intents can be: "product return", "product exchange", "general question", "product question", "other". In triple backticks below is the customer information and a list of orders. @@ -16,20 +8,14 @@ In triple backticks below is the customer information and a list of orders. ``` - - - In triple backticks below are the is the chat history with customer statements and replies from the customer service agent: ``` -{{chat_history}} +{{history}} ``` - - - What is the customer's `intent:` here? "product return", "exchange product", "general question", "product question" or "other"? diff --git a/examples/requirements.txt b/examples/requirements.txt index f9059cba2d3..a5867968d79 100644 --- a/examples/requirements.txt +++ b/examples/requirements.txt @@ -1,6 +1,6 @@ # remove when we publish to pypi --extra-index-url https://azuremlsdktestpypi.azureedge.net/promptflow/ -promptflow[azure]==0.0.102528530 +promptflow[azure]==0.0.102612974 promptflow-tools==0.1.0.b4 python-dotenv langchain