Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[prompty] Refine stream output of prompty (#2862)
# Description - response format: text ``` --- model: api: chat configuration: type: azure_openai parameters: stream: true response_format: type: text inputs: question: type: string --- system: You are an AI assistant who helps people find information. # omit some content user: {{question}} ``` python code: ``` prompty_func = Flow.load(source=f"{PROMPTY_DIR}/prompty.prompty") stream_result = prompty_func(question="what is the result of 1+1?") response_content = [] for item in stream_result: response_content.append(item) ``` Return type is generator[str], like: ['The', ' result', ' of', ' ', '1', '+', '1', ' is', ' ', '2', '.', ' It', "'s", ' a', ' simple', ' addition', '!', ' 😊'] - response format is text with multi choice ``` --- model: api: chat configuration: type: azure_openai parameters: stream: true response_format: type: text n: 2 response: all inputs: question: type: string --- system: You are an AI assistant who helps people find information. # omit some content user: {{question}} ``` python code: ``` prompty_func = Flow.load(source=f"{PROMPTY_DIR}/prompty.prompty") stream_result = prompty_func(question="what is the result of 1+1?") response_content = [] for chunk in stream_result: if len(chunk.choices) > 0 and chunk.choices[0].delta.content: response_content.append(chunk.choices[0].delta.content) ``` Response type is openai.Stream - response format is json_object ``` --- model: api: chat configuration: type: azure_openai parameters: stream: true response_format: type: json_object inputs: question: type: string --- system: You are an AI assistant who helps people find information. Your structured response. Only accepts JSON format, likes below: {"name": customer_name, "answer": the answer content} # omit some content user: {{question}} ``` python code: ``` prompty_func = Flow.load(source=f"{PROMPTY_DIR}/prompty.prompty") result = prompty_func(question="what is the result of 1+1?") ``` Return json dict. like {"name": "John", "answer": 2} - response format is json_object with output ``` --- model: api: chat configuration: type: azure_openai parameters: stream: true response_format: type: json_object inputs: question: type: string outputs: answer: type: string --- system: You are an AI assistant who helps people find information. Your structured response. Only accepts JSON format, likes below: {"name": customer_name, "answer": the answer content} # omit some content user: {{question}} ``` python code: ``` prompty_func = Flow.load(source=f"{PROMPTY_DIR}/prompty.prompty") result = prompty_func(question="what is the result of 1+1?") ``` Return json dict. like {"answer": 2} - response format is json_object and response is all ``` --- model: api: chat configuration: type: azure_openai parameters: stream: true response_format: type: json_object n: 2 response: all inputs: question: type: string --- system: You are an AI assistant who helps people find information. Your structured response. Only accepts JSON format, likes below: {"name": customer_name, "answer": the answer content} # omit some content user: {{question}} ``` python code: ``` prompty_func = Flow.load(source=f"{PROMPTY_DIR}/prompty.prompty") stream_result = prompty_func(question="what is the result of 1+1?") response_content = [] for chunk in stream_result: if len(chunk.choices) > 0 and chunk.choices[0].delta.content: response_content.append(chunk.choices[0].delta.content) ``` Response type is openai.Stream # 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