DocumentazioneConversazione
Sviluppa
Conversazione
Istruzioni, una domanda, una risposta. Poi il seguito dello scambio, rinviando la cronologia a ogni turno.
In questa pagina
I messaggi
Una conversazione è un elenco di messaggi, ognuno con un ruolo.
| Ruolo | Chi parla |
|---|---|
system | Le tue istruzioni: il tono, la lingua, cosa il modello deve fare o evitare |
user | La persona o la tua applicazione |
assistant | Le risposte precedenti del modello |
tool | Il risultato di una delle tue funzioni |
Più turni
Il modello non conserva nulla da una chiamata all’altra. Per continuare uno scambio, rinvia tutta la conversazione con il nuovo messaggio.
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)I parametri utili
temperaturenumero- Più bassa, risposte più costanti. Più alta, più varie. Senza impostazione, il modello riceve il valore che abbiamo scelto per lui.
max_tokensintero- La lunghezza massima della risposta, riportata al limite del modello se lo supera.
response_formatoggetto- Chiede una risposta in JSON, da leggere direttamente nel tuo codice.
stoplista- Sequenze di caratteri che interrompono la risposta.
Ragionamento
Per una domanda difficile, chiedi al modello di riflettere prima di rispondere. Lo sforzo va da none a high. Il ragionamento arriva a parte, 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."}
]
}'