DokumentationKonversation
Entwickeln
Konversation
Anweisungen, eine Frage, eine Antwort. Dann geht der Dialog weiter, und Sie senden den Verlauf in jeder Runde erneut mit.
Auf dieser Seite
Die Nachrichten
Eine Konversation ist eine Liste von Nachrichten, jede mit einer Rolle.
| Rolle | Wer spricht |
|---|---|
system | Ihre Anweisungen: Ton, Sprache, was das Modell tun oder vermeiden soll |
user | Die Person oder Ihre Anwendung |
assistant | Die bisherigen Antworten des Modells |
tool | Das Ergebnis einer Ihrer Funktionen |
Mehrere Runden
Das Modell merkt sich nichts von einem Aufruf zum nächsten. Um einen Dialog fortzusetzen, senden Sie die ganze Konversation mit der neuen Nachricht erneut.
messages = [
{
"role": "system",
"content": "Answer in French, in plain words.",
},
{
"role": "user",
"content": "What must a privacy notice contain?",
},
]
first = client.chat.completions.create(
model="flash", messages=messages
)
# No memory between calls: send the whole conversation again.
messages.append(first.choices[0].message)
messages.append(
{
"role": "user",
"content": "Write one for a bakery with a web shop.",
}
)
second = client.chat.completions.create(
model="flash", messages=messages, temperature=0.4
)
print(second.choices[0].message.content)const messages = [
{
role: "system",
content: "Answer in French, in plain words.",
},
{
role: "user",
content: "What must a privacy notice contain?",
},
]
const first = await client.chat.completions.create({
model: "flash",
messages,
})
// No memory between calls: send the whole conversation again.
messages.push(first.choices[0].message)
messages.push({
role: "user",
content: "Write one for a bakery with a web shop.",
})
const second = await client.chat.completions.create({
model: "flash",
messages,
temperature: 0.4,
})
console.log(second.choices[0].message.content)import type OpenAI from "openai"
const messages: OpenAI.ChatCompletionMessageParam[] = [
{
role: "system",
content: "Answer in French, in plain words.",
},
{
role: "user",
content: "What must a privacy notice contain?",
},
]
const first = await client.chat.completions.create({
model: "flash",
messages,
})
// No memory between calls: send the whole conversation again.
messages.push(first.choices[0].message)
messages.push({
role: "user",
content: "Write one for a bakery with a web shop.",
})
const second = await client.chat.completions.create({
model: "flash",
messages,
temperature: 0.4,
})
console.log(second.choices[0].message.content)Nützliche Parameter
temperatureZahl- Niedriger ergibt einheitlichere Antworten, höher abwechslungsreichere. Ohne Angabe erhält das Modell den Wert, den wir dafür gewählt haben.
max_tokensGanzzahl- Die maximale Länge der Antwort. Liegt sie über der Obergrenze des Modells, wird sie darauf gesenkt.
response_formatObjekt- Fordert eine Antwort in JSON an, damit Ihr Code sie direkt lesen kann.
stopListe- Zeichenfolgen, die die Antwort beenden.
Schlussfolgern
Bei einer schwierigen Frage bitten Sie das Modell, vor der Antwort nachzudenken. Der Aufwand reicht von none bis high. Das Schlussfolgern kommt separat, in reasoning_content.
response = client.chat.completions.create(
model="max",
reasoning_effort="high",
messages=[
{
"role": "user",
"content": "Compare these contracts.",
}
],
)
message = response.choices[0].message
# How the model got there, then the answer.
print(getattr(message, "reasoning_content", None))
print(message.content)const response = await client.chat.completions.create({
model: "max",
reasoning_effort: "high",
messages: [
{ role: "user", content: "Compare these contracts." },
],
})
const message = response.choices[0].message
// How the model got there, then the answer.
console.log(message.reasoning_content)
console.log(message.content)import type { ChatCompletionMessage } from "openai/resources"
// Learnya adds the reasoning next to the answer,
// a field the OpenAI types do not declare.
type LearnyaMessage = ChatCompletionMessage & {
reasoning_content?: string
}
const response = await client.chat.completions.create({
model: "max",
reasoning_effort: "high",
messages: [
{ role: "user", content: "Compare these contracts." },
],
})
const message: LearnyaMessage = response.choices[0].message
// How the model got there, then the answer.
console.log(message.reasoning_content)
console.log(message.content)curl https://api.learnya.ai/v1/chat/completions \
-H "Authorization: Bearer $LEARNYA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "max",
"reasoning_effort": "high",
"messages": [
{"role": "user", "content": "Compare these contracts."}
]
}'