chore: import upstream snapshot with attribution
tools_continuous_delivery / Private PyPI non-main branch release (push) Has been skipped
tools_continuous_delivery / Private PyPI main branch release (push) Failing after 2m42s
Publish Promptflow Doc / Build (push) Has been cancelled
Publish Promptflow Doc / Deploy (push) Has been cancelled
Flake8 Lint / flake8 (push) Has been cancelled
Spell check CI / Spell_Check (push) Has been cancelled
tools_continuous_delivery / Private PyPI non-main branch release (push) Has been skipped
tools_continuous_delivery / Private PyPI main branch release (push) Failing after 2m42s
Publish Promptflow Doc / Build (push) Has been cancelled
Publish Promptflow Doc / Deploy (push) Has been cancelled
Flake8 Lint / flake8 (push) Has been cancelled
Spell check CI / Spell_Check (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
# Question simulation:
|
||||
|
||||
This question simulation flow is used to generate suggestions for the next question based on the previous chat history. When the chat history seems like should be ended, then the flow output will be [STOP].
|
||||
|
||||
## Flow inputs
|
||||
* __chat_history__: the previous chat_history, the format for it is as follows:
|
||||
[
|
||||
{
|
||||
"inputs": {
|
||||
"question": "Can you introduce something about large language model?"
|
||||
},
|
||||
"outputs": {
|
||||
"answer": "A large language model (LLM) is a type of language model that is distinguished by its ability to perform general-purpose language generation and understanding."
|
||||
}
|
||||
},
|
||||
{
|
||||
"inputs": {
|
||||
"question": "XXXXXX"
|
||||
},
|
||||
"outputs": {
|
||||
"answer": "XXXXXX"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
* __question_count__: an integer is used to determine the number of questions to be generated. These generated question can be displayed in UX, allowing users to select the one that best suits their needs.
|
||||
|
||||
## Flow outputs
|
||||
* If the conversation should go on, the output the suggestions for next question: multiple questions are seperated by '\n', for instance:
|
||||
"question": "question_1\nquestion_2\nquestion_3"
|
||||
* If the conversation should ended, not more question will be generated, the output is a stop signal: [STOP]
|
||||
|
||||
## Tools used in this flow
|
||||
- LLM tool
|
||||
- Python tool
|
||||
- Prompt tool
|
||||
|
||||
|
||||
## 0. Setup connection
|
||||
Prepare your Azure OpenAI resource follow this [instruction](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal) and get your `api_key` if you don't have one.
|
||||
|
||||
```bash
|
||||
# Override keys with --set to avoid yaml file changes
|
||||
pf connection create --file ../../../connections/azure_openai.yml --set api_key=<your_api_key> api_base=<your_api_base>
|
||||
```
|
||||
|
||||
## 1. Test flow/node
|
||||
```bash
|
||||
# test with default input value in flow.dag.yaml
|
||||
pf flow test --flow .
|
||||
```
|
||||
@@ -0,0 +1,56 @@
|
||||
from promptflow.core import tool
|
||||
from typing import Union
|
||||
from promptflow.connections import AzureOpenAIConnection, OpenAIConnection
|
||||
from openai import AzureOpenAI as AzureOpenAIClient
|
||||
from openai import OpenAI as OpenAIClient
|
||||
from promptflow.tools.common import parse_chat
|
||||
|
||||
|
||||
def parse_questions(completion: str) -> list:
|
||||
questions = []
|
||||
|
||||
for item in completion.choices:
|
||||
response = getattr(item.message, "content", "")
|
||||
print(response)
|
||||
questions.append(response)
|
||||
return questions
|
||||
|
||||
|
||||
@tool
|
||||
def call_llm_chat(
|
||||
connection: Union[AzureOpenAIConnection, OpenAIConnection],
|
||||
prompt: str,
|
||||
question_count: int,
|
||||
deployment_name_or_model: str,
|
||||
stop: list = [],
|
||||
) -> str:
|
||||
|
||||
messages = parse_chat(prompt)
|
||||
params = {
|
||||
"model": deployment_name_or_model,
|
||||
"messages": messages,
|
||||
"temperature": 1.0,
|
||||
"top_p": 1.0,
|
||||
"stream": False,
|
||||
"stop": stop if stop else None,
|
||||
"presence_penalty": 0.8,
|
||||
"frequency_penalty": 0.8,
|
||||
"max_tokens": None,
|
||||
"n": question_count
|
||||
}
|
||||
if isinstance(connection, AzureOpenAIConnection):
|
||||
client = AzureOpenAIClient(api_key=connection.api_key,
|
||||
api_version=connection.api_version,
|
||||
azure_endpoint=connection.api_base)
|
||||
elif isinstance(connection, OpenAIConnection):
|
||||
client = OpenAIClient(api_key=connection.api_key,
|
||||
organization=connection.organization,
|
||||
base_url=connection.base_url)
|
||||
else:
|
||||
raise ValueError("Unsupported connection type")
|
||||
|
||||
completion = client.chat.completions.create(**params)
|
||||
print(completion)
|
||||
questions = parse_questions(completion)
|
||||
|
||||
return "\n".join(questions)
|
||||
@@ -0,0 +1,77 @@
|
||||
$schema: https://azuremlschemas.azureedge.net/promptflow/latest/Flow.schema.json
|
||||
inputs:
|
||||
chat_history:
|
||||
type: list
|
||||
default: [{"inputs":{"question":"Can you introduce something about large language model?"},"outputs":{"answer":"A large language model (LLM) is a type of language model that is distinguished by its ability to perform general-purpose language generation and understanding. These models learn statistical relationships from text documents through a self-supervised and semi-supervised training process that is computationally intensive. LLMs are a form of artificial neural networks, and many of the most advanced ones are built using a transformer-based architecture, although there are some recent implementations based on other architectures, such as recurrent neural network variants and Mamba, which is a state space model.\n\nLLMs are capable of text generation, which is a subset of generative AI. They do this by taking an input text and predicting the next token or word in a sequence. Initially, fine-tuning was the primary method for adapting these models to perform specific tasks, but with the advent of larger models like GPT-3, prompt engineering can be used to achieve similar results without fine-tuning.\n\nThese models are believed to acquire knowledge about the syntax, semantics, and \"ontology\" inherent in human language from the corpora they are trained on. However, they also inherit any inaccuracies and biases present in the training data.\n\nNotable examples of LLMs include OpenAI's GPT series (such as GPT-3","context":"Content: A large language model (LLM) is a language model notable for its ability to achieve general-purpose language generation and understanding. LLMs acquire these abilities by learning statistical relationships from text documents during a computationally intensive self-supervised and semi-supervised training process.[1] LLMs are artificial neural networks, the largest and most capable of which are built with a transformer-based architecture. Some recent implementations are based on other architectures, such as recurrent neural network variants and Mamba (a state space model).[2][3][4]. LLMs can be used for text generation, a form of generative AI, by taking an input text and repeatedly predicting the next token or word.[5] Up to 2020, fine tuning was the only way a model could be adapted to be able to accomplish specific tasks. Larger sized models, such as GPT-3, however, can be prompt-engineered to achieve similar results.[6] They are thought to acquire knowledge about syntax, semantics and \"ontology\" inherent in human language corpora, but also inaccuracies and biases present in the corpora.[7]. Some notable LLMs are OpenAI's GPT series of models (e.g., GPT-3.5 and GPT-4, used in ChatGPT and Microsoft Copilot), Google's PaLM and Gemini (the latter of which is currently used in the chatbot of the same name), Meta's LLaMA family of open-source models, and Anthropic's Claude models.. At the 2017 NeurIPS conference, Google researchers introduced the transformer architecture in their landmark paper \"Attention Is All You Need\". This paper's goal was to improve upon 2014 Seq2seq technology, [8] and was based mainly on the attention mechanism developed by Bahdanau et al. in 2014.[9] The following year in 2018, BERT was introduced and quickly became \"ubiquitous\".[10] Though the original transformer has both encoder and decoder blocks, BERT is an encoder-only model.. Although decoder-only GPT-1 was introduced in 2018, it was GPT-2 in 2019 that caught widespread attention because OpenAI at first deemed it too powerful to release publicly, out of fear of malicious use.[11] GPT-3 in 2020 went a step further and as of 2024[update] is available only via API with no offering of downloading the model to execute locally.\nSource: https://en.wikipedia.org/w/index.php?search=Large language model\n\nContent: Gemini may refer to:. Main pageContentsCurrent eventsRandom articleAbout WikipediaContact usDonate. HelpLearn to editCommunity portalRecent changesUpload file. Create account. Log in. Create account Log in. (Top). 1Space. 2Mythology. 3Given name.\nSource: https://en.wikipedia.org/w/index.php?search=Gemini "}}]
|
||||
is_chat_input: false
|
||||
question_count:
|
||||
type: int
|
||||
default: 3
|
||||
is_chat_input: false
|
||||
outputs:
|
||||
question:
|
||||
type: string
|
||||
reference: ${flow_output.output}
|
||||
nodes:
|
||||
- name: verify_if_conversation_stopped
|
||||
type: llm
|
||||
source:
|
||||
type: code
|
||||
path: verify_if_conversation_stopped.jinja2
|
||||
inputs:
|
||||
deployment_name: gpt-4
|
||||
temperature: 0
|
||||
top_p: 1
|
||||
presence_penalty: 0
|
||||
frequency_penalty: 0
|
||||
chat_history: ${inputs.chat_history}
|
||||
provider: AzureOpenAI
|
||||
connection: open_ai_connection
|
||||
api: chat
|
||||
module: promptflow.tools.aoai
|
||||
use_variants: false
|
||||
- name: if_continue
|
||||
type: python
|
||||
source:
|
||||
type: code
|
||||
path: if_continue.py
|
||||
inputs:
|
||||
stop_or_continue: ${verify_if_conversation_stopped.output}
|
||||
use_variants: false
|
||||
- name: human_prompt
|
||||
type: prompt
|
||||
source:
|
||||
type: code
|
||||
path: human_prompt.jinja2
|
||||
inputs:
|
||||
chat_history: ${inputs.chat_history}
|
||||
activate:
|
||||
when: ${if_continue.output}
|
||||
is: true
|
||||
use_variants: false
|
||||
- name: call_llm_chat
|
||||
type: python
|
||||
source:
|
||||
type: code
|
||||
path: call_llm_chat.py
|
||||
inputs:
|
||||
connection: open_ai_connection
|
||||
deployment_name_or_model: gpt-4
|
||||
prompt: ${human_prompt.output}
|
||||
question_count: ${inputs.question_count}
|
||||
stop:
|
||||
- "Human:"
|
||||
- "Bot:"
|
||||
use_variants: false
|
||||
- name: flow_output
|
||||
type: python
|
||||
source:
|
||||
type: code
|
||||
path: flow_output.py
|
||||
inputs:
|
||||
questions: ${call_llm_chat.output}
|
||||
stop_or_continue: ${verify_if_conversation_stopped.output}
|
||||
use_variants: false
|
||||
node_variants: {}
|
||||
environment:
|
||||
python_requirements_txt: requirements.txt
|
||||
@@ -0,0 +1,9 @@
|
||||
from promptflow.core import tool
|
||||
|
||||
|
||||
@tool
|
||||
def flow_output(stop_or_continue: str, questions: str) -> str:
|
||||
if "stop" in stop_or_continue.lower():
|
||||
return "[STOP]"
|
||||
else:
|
||||
return questions
|
||||
@@ -0,0 +1,27 @@
|
||||
# System:
|
||||
You are an assistant playing as a random human engaging in a conversation with a digital companion, Bot. Your task is to follow the instruction below to role-play as a random human in a conversation with Bot, responding to Bot in a manner that a human would say.
|
||||
|
||||
# Example
|
||||
This example illustrates how to generate a conversational response to Bot as a human would:
|
||||
Conversation:
|
||||
Human: Bot, what's your favorite movie?
|
||||
Bot: I don't watch movies, but I can help you find information about any movie you like!
|
||||
Human: Can you tell me about the latest Marvel movie?
|
||||
Bot: The latest Marvel movie is "Spider-Man: No Way Home". It features Peter Parker dealing with the fallout after his identity is revealed. Want to know more about it?
|
||||
Human: Yes, can you suggest where I can watch it?
|
||||
|
||||
# Instruction:
|
||||
1. Your reply to the Bot should mimic how a human would typically engage in conversation, asking questions or making statements that a person would naturally say in response.
|
||||
2. Do not use interjections.
|
||||
3. Provide a straightforward, factual response without expressions of surprise, admiration, or evaluative comments for Bot's response.
|
||||
4. Focus on directly asking a question about Bot's response in the last exchange. The question should be concise, and without punctuation marks in the middle.
|
||||
5. Avoid creating any messages that appear to come from the Bot. Your response should not contain content that could be mistaken as generated by the Bot, maintaining a clear distinction between your input as the Human and the Bot's contributions to the conversation.
|
||||
6. Your reply should not contain "\n", this is a reserved character.
|
||||
|
||||
# Read the following conversation and respond:
|
||||
Conversation:
|
||||
{% for item in chat_history %}
|
||||
Human: {{ item.inputs.question }}
|
||||
Bot: {{ item.outputs.answer }}
|
||||
{% endfor %}
|
||||
Human:
|
||||
@@ -0,0 +1,9 @@
|
||||
from promptflow.core import tool
|
||||
|
||||
|
||||
@tool
|
||||
def if_continue(stop_or_continue: str) -> bool:
|
||||
if "continue" in stop_or_continue.lower():
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
@@ -0,0 +1,32 @@
|
||||
# System:
|
||||
You are an assistant tasked with determining whether a conversation between a human and a bot will continue or not. Your outputs are limited to "[STOP]" or "[CONTINUE]". When you predict that the conversation will go on, you should respond with "[CONTINUE]". If you believe the conversation has come to an end, respond with "[STOP]".
|
||||
|
||||
# Examples:
|
||||
## Example 1:
|
||||
Conversation:
|
||||
Human: Hey Bot, what's your favorite movie?
|
||||
Bot: I don't watch movies, but I can help you find information about any movie you like!
|
||||
Human: Can you tell me about the latest Marvel movie?
|
||||
Bot: The latest Marvel movie is "Spider-Man: No Way Home". It features Peter Parker dealing with the fallout after his identity is revealed. Want to know more about it?
|
||||
output: [CONTINUE]
|
||||
|
||||
## Example 2:
|
||||
Conversation:
|
||||
Human: Hey Bot, do you know any good Italian restaurants nearby?
|
||||
Bot: I can't access current location data, but I can suggest looking up Italian restaurants on a local review site like Yelp or Google Reviews.
|
||||
Human: Thanks for the tip. I'll check it out.
|
||||
Bot: You're welcome! Enjoy your meal. If you need more help, just ask.
|
||||
output: [STOP]
|
||||
|
||||
# Instruction
|
||||
A conversation is considered to have ended if:
|
||||
1. The Bot's final response only contains polite expressions without substantive content for human to inquire about.
|
||||
2. In the last round of the conversation, the Human did not ask the Bot any questions.
|
||||
|
||||
# Read the following conversation and respond:
|
||||
Conversation:
|
||||
{% for item in chat_history %}
|
||||
Human: {{ item.inputs.question }}
|
||||
Bot: {{ item.outputs.answer }}
|
||||
{% endfor %}
|
||||
output:
|
||||
Reference in New Issue
Block a user