Prompty-Ausgabeformat#

Experimentelles Feature

Dies ist ein experimentelles Feature und kann sich jederzeit ändern. Erfahren Sie mehr.

In diesem Dokument erfahren Sie

  • Verstehen Sie, wie Sie das Ausgabeformat von Prompty wie folgt behandeln: text, json_object.

  • Verstehen Sie, wie Sie die Streaming-Ausgabe von Prompty konsumieren

Formatierung der Prompty-Ausgabe#

Textausgabe#

Standardmäßig gibt Prompty die Nachricht aus der ersten Wahl in der Antwort zurück. Nachfolgend finden Sie ein Beispiel für die Formatierung eines Prompty für die Textausgabe

---
name: Text Format Prompt
description: A basic prompt that uses the GPT-3 chat API to answer questions
model:
  api: chat
  configuration:
    type: azure_openai
    connection: open_ai_connection
    azure_deployment: gpt-35-turbo-0125
  parameters:
    max_tokens: 128
    temperature: 0.2
inputs:
  first_name:
    type: string
  last_name:
    type: string
  question:
    type: string
sample:
  first_name: John
  last_name: Doe
  question: what is the meaning of life?
---
system:
You are an AI assistant who helps people find information.
As the assistant, you answer questions briefly, succinctly,
and in a personable manner using markdown and even add some personal flair with appropriate emojis.

# Safety
- You **should always** reference factual statements to search results based on [relevant documents]
- Search results based on [relevant documents] may be incomplete or irrelevant. You do not make assumptions
# Customer
You are helping {{first_name}} {{last_name}} to find answers to their questions.
Use their name to address them in your responses.

user:
{{question}}

Die Ausgabe des Prompty ist ein Zeichenketteninhalt, wie im folgenden Beispiel gezeigt

Ah, the age-old question about the meaning of life! 🌍🤔 The meaning of life is a deeply philosophical and subjective topic. Different people have different perspectives on it. Some believe that the meaning of life is to seek happiness and fulfillment, while others find meaning in personal relationships, accomplishments, or spiritual beliefs. Ultimately, it's up to each individual to explore and discover their own purpose and meaning in life. 🌟

JSON-Objekt-Ausgabe#

Prompty kann den Inhalt der ersten Wahl als Wörterbuchobjekt zurückgeben, wenn die folgenden Bedingungen erfüllt sind

  • Das response_format ist in den Parametern als type: json_object definiert

  • Die Vorlage gibt das JSON-Format für den Rückgabewert an.

Hinweis: Das json_object response_format ist kompatibel mit GPT-4 Turbo und allen GPT-3.5 Turbo-Modellen, die neuer als gpt-3.5-turbo-1106 sind. Weitere Details finden Sie in diesem Dokument.

Hier erfahren Sie, wie Sie einen Prompty für die Ausgabe von JSON-Objekten konfigurieren

---
name: Json Format Prompt
description: A basic prompt that uses the GPT-3 chat API to answer questions
model:
  api: chat
  configuration:
    type: azure_openai
    azure_deployment: gpt-35-turbo-0125
    connection: open_ai_connection
  parameters:
    max_tokens: 128
    temperature: 0.2
    response_format:
      type: json_object
inputs:
  first_name:
    type: string
  last_name:
    type: string
  question:
    type: string
sample:
  first_name: John
  last_name: Doe
  question: what is the meaning of life?
---
system:
You are an AI assistant who helps people find information.
As the assistant, you answer questions briefly, succinctly. Your structured response. Only accepts JSON format, likes below:
{"name": customer_name, "answer": the answer content}

# Customer
You are helping {{first_name}} {{last_name}} to find answers to their questions.
Use their name to address them in your responses.

user:
{{question}}

Die Ausgabe des Prompty ist ein JSON-Objekt, das den Inhalt der ersten Wahl enthält

{
    "name": "John",
    "answer": "The meaning of life is a philosophical question that varies depending on individual beliefs and perspectives."
}

Benutzer können auch die Felder angeben, die zurückgegeben werden sollen, indem sie den Ausgabeabschnitt konfigurieren

---
name: Json Format Prompt
description: A basic prompt that uses the GPT-3 chat API to answer questions
model:
  api: chat
  configuration:
    type: azure_openai
    azure_deployment: gpt-35-turbo-0125
    connection: open_ai_connection
  parameters:
    max_tokens: 128
    temperature: 0.2
    response_format:
      type: json_object
inputs:
  first_name:
    type: string
  last_name:
    type: string
  question:
    type: string
outputs:
  answer:
    type: string
sample:
  first_name: John
  last_name: Doe
  question: what is the meaning of life?
---
system:
You are an AI assistant who helps people find information.
As the assistant, you answer questions briefly, succinctly. Your structured response. Only accepts JSON format, likes below:
{"name": customer_name, "answer": the answer content}

# Customer
You are helping {{first_name}} {{last_name}} to find answers to their questions.
Use their name to address them in your responses.

user:
{{question}}

Prompty gibt dann die vom Benutzer angegebenen Ausgaben zurück

{
  "answer": "The meaning of life is a philosophical question that varies depending on individual beliefs and perspectives."
}

Alle Auswahlen#

In bestimmten Szenarien benötigen Benutzer Zugriff auf die ursprüngliche Antwort des Sprachmodells (LLM) für die weitere Verarbeitung. Dies kann durch Setzen von response=all erreicht werden, wodurch die ursprüngliche LLM-Antwort abgerufen werden kann. Ausführliche Informationen finden Sie in der LLM-Antwort.

---
name: All Choices Text Format Prompt
description: A basic prompt that uses the GPT-3 chat API to answer questions
model:
  api: chat
  configuration:
    type: azure_openai
    connection: open_ai_connection
    azure_deployment: gpt-35-turbo-0125
  parameters:
    max_tokens: 128
    temperature: 0.2
    n: 3
  response: all
inputs:
  first_name:
    type: string
  last_name:
    type: string
  question:
    type: string
sample:
  first_name: John
  last_name: Doe
  question: what is the meaning of life?
---
system:
You are an AI assistant who helps people find information.
As the assistant, you answer questions briefly, succinctly,
and in a personable manner using markdown and even add some personal flair with appropriate emojis.

# Safety
- You **should always** reference factual statements to search results based on [relevant documents]
- Search results based on [relevant documents] may be incomplete or irrelevant. You do not make assumptions
# Customer
You are helping {{first_name}} {{last_name}} to find answers to their questions.
Use their name to address them in your responses.

user:
{{question}}

Streaming-Ausgabe#

Für Prompty-Konfigurationen, bei denen das response_format text ist, führt das Setzen von stream=true in den Parametern dazu, dass das Promptflow SDK einen Generator zurückgibt. Jedes Element aus dem Generator stellt den Inhalt eines Chunks dar.

Hier erfahren Sie, wie Sie einen Prompty für die Ausgabe von Streaming-Text konfigurieren

---
name: Stream Mode Text Format Prompt
description: A basic prompt that uses the GPT-3 chat API to answer questions
model:
  api: chat
  configuration:
    type: azure_openai
    connection: open_ai_connection
    azure_deployment: gpt-35-turbo-0125
  parameters:
    max_tokens: 512
    temperature: 0.2
    stream: true
inputs:
  first_name:
    type: string
  last_name:
    type: string
  question:
    type: string
sample:
  first_name: John
  last_name: Doe
  question: What's the steps to get rich?
---
system:
You are an AI assistant who helps people find information.
and in a personable manner using markdown and even add some personal flair with appropriate emojis.

# Safety
- You **should always** reference factual statements to search results based on [relevant documents]
- Search results based on [relevant documents] may be incomplete or irrelevant. You do not make assumptions
# Customer
You are helping user to find answers to their questions.

user:
{{question}}

Um Elemente aus den Generatorergebnissen abzurufen, verwenden Sie den folgenden Python-Code

from promptflow.core import Prompty

# load prompty as a flow
prompty_func = Prompty.load("stream_output.prompty")
# execute the flow as function
question = "What's the steps to get rich?"
result = prompty_func(first_name="John", last_name="Doh", question=question)
# Type of the result is generator
for item in result:
    print(item, end="")