Gemini po mendon

Modelet e Gemini përdorin një "proces të menduari" që përmirëson ndjeshëm aftësitë e tyre të arsyetimit dhe planifikimit me shumë hapa, duke i bërë ato shumë efektive për detyra komplekse si kodimi, matematika e përparuar dhe analiza e të dhënave.

Kur përdor një model të të menduarit, Gemini arsyeton në mënyrë të brendshme para se të përgjigjet. Interactions API e shfaq këtë arsyetim nëpërmjet hapave thought, hapa të dedikuar që shfaqen në mënyrë kronologjike bashkë me thirrjet e funksioneve, hyrjet e përdoruesit ose rezultatet e modelit në vektorin steps.

Çdo hap i mendimit përmban dy fusha:

Fusha Kërkohet Përshkrimi
signature ✅ Po Një përfaqësim i enkriptuar i gjendjes së arsyetimit të brendshëm të modelit. Gjithmonë i pranishëm, edhe kur modeli kryen arsyetim minimal.
summary ❌ Jo Një grup përmbajtjesh (tekst dhe/ose imazhe) që përmbledhin arsyetimin. Mund të jetë bosh në varësi të konfigurimit të thinking_summaries, nëse modeli ka kryer arsyetim të mjaftueshëm ose llojit të përmbajtjes (për shembull, imazhet e fshehura mund të mos kenë përmbledhje me tekst).

Ndërveprimet me arsyetuesin

Nisja e një ndërveprimi me një model që mendon është e ngjashme me çdo kërkesë tjetër ndërveprimi. Specifiko një nga modelet me mbështetje për arsyetimin në fushën model:

Python

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.8-flash",
    input="Explain the concept of Occam's Razor and provide a simple, everyday example."
)
print(interaction.output_text)

JavaScript

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: "gemini-3.8-flash",
    input: "Explain the concept of Occam's Razor and provide a simple, everyday example."
});
console.log(interaction.output_text);

Java

import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;

Client client = new Client();

CreateModelInteraction params =
    CreateModelInteraction.builder()
        .model(Model.of("gemini-3.8-flash"))
        .input(
            InteractionsInput.of(
                "Explain the concept of Occam's Razor and provide a simple, everyday example."))
        .build();

Interaction interaction =
    client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();

System.out.println(interaction.outputText().orElse(""));

Go

package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model: interactions.Model("gemini-3.8-flash"),
            Input: interactions.NewInteractionsInput("Explain the concept of Occam's Razor and provide a simple, everyday example."),
        }),
    })
    if err != nil {
        log.Fatal(err)
    }

    if res.Interaction.OutputText != nil {
        fmt.Println(*res.Interaction.OutputText)
    }
}

QETËSI

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gemini-3.8-flash",
    "input": "Explain the concept of Occam'\''s Razor and provide a simple example."
  }'

Përmbledhjet e mendimeve

Përmbledhjet e mendimeve ofrojnë statistika për procesin e arsyetimit të brendshëm të modelit. Si parazgjedhje, kthehet vetëm rezultati përfundimtar. Mund të aktivizosh përmbledhjet e mendimeve me thinking_summaries:

Python

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.8-flash",
    input="What is the sum of the first 50 prime numbers?",
    generation_config={
        "thinking_summaries": "auto"
    }
)

for step in interaction.steps:
    if step.type == "thought":
        print("Thought summary:")
        if step.summary:
            for content_block in step.summary:
                if content_block.type == "text":
                    print(content_block.text)
        print()
    elif step.type == "model_output":
        for content_block in step.content:
            if content_block.type == "text":
                print("Answer:")
                print(content_block.text)
                print()

JavaScript

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: "gemini-3.8-flash",
    input: "What is the sum of the first 50 prime numbers?",
    generation_config: {
        thinking_summaries: "auto"
    }
});

for (const step of interaction.steps) {
    if (step.type === "thought") {
        console.log("Thought summary:");
        if (step.summary) {
            for (const contentBlock of step.summary) {
                if (contentBlock.type === "text") console.log(contentBlock.text);
            }
        }
    } else if (step.type === "model_output") {
        for (const contentBlock of step.content) {
            if (contentBlock.type === "text") {
                console.log("Answer:");
                console.log(contentBlock.text);
            }
        }
    }
}

Java

import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.Content;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.GenerationConfig;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.ModelOutputStep;
import com.google.genai.gaos.models.interactions.Step;
import com.google.genai.gaos.models.interactions.TextContent;
import com.google.genai.gaos.models.interactions.ThinkingSummaries;
import com.google.genai.gaos.models.interactions.ThoughtStep;
import com.google.genai.gaos.models.interactions.ThoughtSummaryContent;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.Collections;

Client client = new Client();

CreateModelInteraction params =
    CreateModelInteraction.builder()
        .model(Model.of("gemini-3.8-flash"))
        .input(InteractionsInput.of("What is the sum of the first 50 prime numbers?"))
        .generationConfig(
            GenerationConfig.builder().thinkingSummaries(ThinkingSummaries.AUTO).build())
        .build();

Interaction interaction =
    client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();

for (Step step : interaction.steps().orElse(Collections.emptyList())) {
  if (step instanceof ThoughtStep thoughtStep) {
    System.out.println("Thought summary:");
    for (ThoughtSummaryContent contentBlock : thoughtStep.summary().orElse(Collections.emptyList())) {
      if (contentBlock instanceof TextContent textContent) {
        System.out.println(textContent.text().orElse(""));
      }
    }
    System.out.println();
  } else if (step instanceof ModelOutputStep outputStep) {
    for (Content contentBlock : outputStep.content().orElse(Collections.emptyList())) {
      if (contentBlock instanceof TextContent textContent) {
        System.out.println("Answer:");
        System.out.println(textContent.text().orElse(""));
        System.out.println();
      }
    }
  }
}

Go

package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model: interactions.Model("gemini-3.8-flash"),
            Input: interactions.NewInteractionsInput("Provide a list of 3 famous physicists and their key contributions"),
            GenerationConfig: &interactions.GenerationConfig{
                ThinkingLevel: interactions.ThinkingLevelLow.ToPointer(),
            },
        }),
    })
    if err != nil {
        log.Fatal(err)
    }

    if res.Interaction.OutputText != nil {
        fmt.Println(*res.Interaction.OutputText)
    }
}

REST

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gemini-3.8-flash",
    "input": "What is the sum of the first 50 prime numbers?",
    "generation_config": {
      "thinking_summaries": "auto"
    }
  }'

Një bllok mendimi mund të përmbajë vetëm një nënshkrim pa përmbledhje në këto raste:

  • Kërkesat e thjeshta, ku modeli nuk ka arsyetuar mjaftueshëm për të gjeneruar një përmbledhje
  • thinking_summaries: "none", ku përmbledhjet janë çaktivizuar në mënyrë eksplicite
  • Lloje të caktuara të përmbajtjeve të mendimit, si p.sh. imazhet, mund të mos kenë përmbledhje me tekst

Kodi yt duhet të menaxhojë gjithmonë blloqet e mendimit ku summary është bosh ose mungon.

Transmetimi me arsyetim

Përdor transmetimin për të marrë përmbledhje rritëse të mendimit gjatë gjenerimit. Blloqet e mendimeve ofrohen duke përdorur Server-Sent Events (SSE) me dy lloje të dallueshme delta:

Lloji i ndryshimit rritës Përmban Kur dërgohet
thought_summary Përmbajtja e përmbledhjes me tekst ose imazh Një ose më shumë ndryshime me përmbledhje shtesë
thought_signature Nënshkrimi kriptografik delta e fundit para step.stop

Python

from google import genai

client = genai.Client()

prompt = """
Alice, Bob, and Carol each live in a different house on the same street: red, green, and blue.
Alice does not live in the red house.
Bob does not live in the green house.
Carol does not live in the red or green house.
Which house does each person live in?
"""

thoughts = ""
answer = ""

stream = client.interactions.create(
    model="gemini-3.8-flash",
    input=prompt,
    generation_config={
        "thinking_summaries": "auto"
    },
    stream=True
)

for event in stream:
    if event.event_type == "step.delta":
        if event.delta.type == "thought_summary":
            if not thoughts:
                print("Thinking...")
            summary_text = event.delta.content.text
            print(f"[Thought] {summary_text}", end="")
            thoughts += summary_text
        elif event.delta.type == "text" and event.delta.text:
            if not answer:
                print("\nAnswer:")
            print(event.delta.text, end="")
            answer += event.delta.text

JavaScript

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const prompt = `Alice, Bob, and Carol each live in a different house on the same
street: red, green, and blue. Alice does not live in the red house.
Bob does not live in the green house.
Carol does not live in the red or green house.
Which house does each person live in?`;

let thoughts = "";
let answer = "";

const stream = await client.interactions.create({
    model: "gemini-3.8-flash",
    input: prompt,
    generation_config: {
        thinking_summaries: "auto"
    },
    stream: true
});

for await (const event of stream) {
    if (event.event_type === "step.delta") {
        if (event.delta.type === "thought_summary") {
            if (!thoughts) console.log("Thinking...");
            const text = event.delta.content?.text || "";
            process.stdout.write(`[Thought] ${text}`);
            thoughts += text;
        } else if (event.delta.type === "text" && event.delta.text) {
            if (!answer) console.log("\nAnswer:");
            process.stdout.write(event.delta.text);
            answer += event.delta.text;
        }
    }
}

Java

import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.Content;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.GenerationConfig;
import com.google.genai.gaos.models.interactions.InteractionSSEEvent;
import com.google.genai.gaos.models.interactions.InteractionSSEStreamEvent;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.StepDelta;
import com.google.genai.gaos.models.interactions.StepDeltaData;
import com.google.genai.gaos.models.interactions.TextContent;
import com.google.genai.gaos.models.interactions.TextDelta;
import com.google.genai.gaos.models.interactions.ThinkingSummaries;
import com.google.genai.gaos.models.interactions.ThoughtSummaryDelta;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import com.google.genai.gaos.models.operations.CreateInteractionResponse;
import com.google.genai.gaos.utils.EventStream;

Client client = new Client();

String prompt =
    "Alice, Bob, and Carol each live in a different house on the same street: red, green, and blue.\n"
        + "Alice does not live in the red house.\n"
        + "Bob does not live in the green house.\n"
        + "Carol does not live in the red or green house.\n"
        + "Which house does each person live in?";

StringBuilder thoughts = new StringBuilder();
StringBuilder answer = new StringBuilder();

CreateModelInteraction params =
    CreateModelInteraction.builder()
        .model(Model.of("gemini-3.8-flash"))
        .input(InteractionsInput.of(prompt))
        .generationConfig(
            GenerationConfig.builder().thinkingSummaries(ThinkingSummaries.AUTO).build())
        .stream(true)
        .build();

CreateInteractionResponse response =
    client.interactions.create(CreateInteractionRequestBody.of(params));

try (EventStream<InteractionSSEStreamEvent> stream = response.events()) {
  for (InteractionSSEStreamEvent streamEvent : stream) {
    InteractionSSEEvent event = streamEvent.data().orElse(null);
    if (event instanceof StepDelta stepDelta) {
      StepDeltaData delta = stepDelta.delta().orElse(null);
      if (delta instanceof ThoughtSummaryDelta thoughtDelta) {
        Content content = thoughtDelta.content().orElse(null);
        if (content instanceof TextContent textContent) {
          if (thoughts.length() == 0) {
            System.out.println("Thinking...");
          }
          String summaryText = textContent.text().orElse("");
          System.out.print("[Thought] " + summaryText);
          thoughts.append(summaryText);
        }
      } else if (delta instanceof TextDelta textDelta) {
        String text = textDelta.text().orElse("");
        if (!text.isEmpty()) {
          if (answer.length() == 0) {
            System.out.println("\nAnswer:");
          }
          System.out.print(text);
          answer.append(text);
        }
      }
    }
  }
}

Go

package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model: interactions.Model("gemini-3.8-flash"),
            Input: interactions.NewInteractionsInput("What is the sum of the first 50 prime numbers?"),
            GenerationConfig: &interactions.GenerationConfig{
                ThinkingLevel:     interactions.ThinkingLevelHigh.ToPointer(),
                ThinkingSummaries: interactions.ThinkingSummariesAuto.ToPointer(),
            },
        }),
    })
    if err != nil {
        log.Fatal(err)
    }

    for _, step := range res.Interaction.Steps {
        if thought := step.ThoughtStep; thought != nil {
            for _, part := range thought.Summary {
                if part.TextContent != nil {
                    fmt.Printf("Thought summary:\n%s\n\n", part.TextContent.Text)
                }
            }
        }
    }

    if res.Interaction.OutputText != nil {
        fmt.Printf("Answer:\n%s\n", *res.Interaction.OutputText)
    }
}

QETËSI

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  --no-buffer \
  -d '{
    "model": "gemini-3.8-flash",
    "input": "Alice, Bob, and Carol each live in a different house on the same street: red, green, and blue. Alice does not live in the red house. Bob does not live in the green house. Carol does not live in the red or green house. Which house does each person live in?",
    "generation_config": {
      "thinking_summaries": "auto"
    },
    "stream": true
  }'

Përgjigjja e transmetimit përdor Server-Sent Events (SSE) dhe përbëhet nga hapa dhe ngjarje, për shembull:

event: interaction.created
data: {"interaction":{"id":"v1_xxx","status":"in_progress","object":"interaction","model":"gemini-3.8-flash"},"event_type":"interaction.created"}

event: step.start
data: {"index":0,"step":{"signature":"","summary":[{"text":"**Evaluating the clues**\n\nI'm considering...","type":"text"}],"type":"thought"},"event_type":"step.start"}

event: step.delta
data: {"index":0,"delta":{"signature":"EpoGCpcGAXLI2nx/...","type":"thought_signature"},"event_type":"step.delta"}

event: step.stop
data: {"index":0,"event_type":"step.stop"}

event: step.start
data: {"index":1,"step":{"content":[{"text":"Based on the clues provided, here","type":"text"}],"type":"model_output"},"event_type":"step.start"}

event: step.delta
data: {"index":1,"delta":{"text":" is the answer to your question...","type":"text"},"event_type":"step.delta"}

event: step.stop
data: {"index":1,"event_type":"step.stop"}

event: interaction.completed
data: {"interaction":{"id":"v1_xxx","status":"completed","usage":{"total_tokens":530,"total_input_tokens":62,"total_output_tokens":171,"total_thought_tokens":297}},"event_type":"interaction.completed"}

event: done
data: [DONE]

Kontrollimi i arsyetimit

Modelet e Gemini përfshihen në mendimin dinamik si parazgjedhje, duke rregulluar automatikisht sasinë e përpjekjes për arsyetim bazuar në kompleksitetin e kërkesës. Mund ta kontrollosh këtë sjellje duke përdorur parametrin thinking_level.

Modeli Arsyetimi i parazgjedhur Nivelet e mbështetura
gemini-4-argon Aktivizuar (mesatare) i ulët, mesatar, i lartë
gemini-3.8-flash Aktivizuar (mesatare) i ulët, mesatar, i lartë
gemini-3.6-flash Aktivizuar (mesatare) minimale, e ulët, mesatare, e lartë
gemini-3.5-flash-lite Aktiv (minimal) minimale, e ulët, mesatare, e lartë
gemini-3.1-pro-preview Aktivizuar (i lartë) i ulët, mesatar, i lartë
gemini-3.1-flash-lite-image Aktiv (minimal) minimal, i lartë
gemini-3-flash-preview Aktivizuar (i lartë) minimale, e ulët, mesatare, e lartë
gemini-3-pro-preview Aktivizuar (i lartë) e ulët, e lartë
gemini-2.5-pro Aktiv i ulët, mesatar, i lartë
gemini-2.5-flash Aktiv i ulët, mesatar, i lartë
gemini-2.5-flash-lite Joaktiv i ulët, mesatar, i lartë
gemini-robotics-er-2-preview Aktiv (i lartë) minimale, e ulët, mesatare, e lartë

Python

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.8-flash",
    input="Provide a list of 3 famous physicists and their key contributions",
    generation_config={
        "thinking_level": "low"
    }
)
print(interaction.output_text)

JavaScript

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: "gemini-3.8-flash",
    input: "Provide a list of 3 famous physicists and their key contributions",
    generation_config: {
        thinking_level: "low"
    }
});
console.log(interaction.output_text);

Java

import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.GenerationConfig;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.ThinkingLevel;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;

Client client = new Client();

CreateModelInteraction params =
    CreateModelInteraction.builder()
        .model(Model.of("gemini-3.8-flash"))
        .input(
            InteractionsInput.of(
                "Provide a list of 3 famous physicists and their key contributions"))
        .generationConfig(GenerationConfig.builder().thinkingLevel(ThinkingLevel.LOW).build())
        .build();

Interaction interaction =
    client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();

System.out.println(interaction.outputText().orElse(""));

Go

package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model: interactions.Model("gemini-3.8-pro"),
            Input: interactions.NewInteractionsInput("What is the sum of the first 50 prime numbers?"),
            GenerationConfig: &interactions.GenerationConfig{
                ThinkingLevel:     interactions.ThinkingLevelHigh.ToPointer(),
                ThinkingSummaries: interactions.ThinkingSummariesAuto.ToPointer(),
            },
            Stream: genai.Ptr(true),
        }),
    })
    if err != nil {
        log.Fatal(err)
    }
    stream := res.InteractionSSEStreamEvent
    defer stream.Close()

    for stream.Next() {
        event := stream.Value()
        if stepDelta := event.GetDataStepDelta(); stepDelta != nil {
            if thoughtDelta := stepDelta.GetDeltaThoughtSummary(); thoughtDelta != nil {
                if textContent := thoughtDelta.GetContentText(); textContent != nil {
                    fmt.Printf("[Thought Summary] %s\n", textContent.Text)
                }
            }
            if textDelta := stepDelta.GetDeltaText(); textDelta != nil {
                fmt.Print(textDelta.GetText())
            }
        }
    }
    if err := stream.Err(); err != nil {
        log.Fatal(err)
    }
}

QETËSI

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gemini-3.8-flash",
    "input": "Provide a list of 3 famous physicists and their key contributions",
    "generation_config": {
      "thinking_level": "low"
    }
  }'

Kufijtë e kodeve dhe max_output_tokens

Parametri i gjenerimit të max_output_tokens cakton numrin maksimal të kodeve që mund të gjenerojë një përgjigje, duke përfshirë kodet e mendimeve.

Kur caktohet, ky parametër vepron si një kufi i fortë i zbatuar nga infrastruktura pa ndryshuar mënyrën se si modeli cakton buxhetin e tij të të menduarit (thinking_level).

Nëse modeli e arrin këtë kufi gjatë arsyetimit, ai ndalon gjenerimin me statusin "incomplete" dhe kthen një rezultat të shkurtuar ose bosh (ndërkohë që faturon përsëri për çdo token arsyetimi të gjeneruar). To reduce cost or latency without truncating responses, lower thinking_level (low or medium) instead of setting a small max_output_tokens.

Për modelet e Gemini 4 (gemini-4-argon), ki parasysh kufijtë e mëposhtëm të kontekstit dhe nxjerrjes:

  • Dritarja kontekstuale e ndarë me 1 milion kode: Kodet e hyrjes, të të menduarit dhe të daljes ndajnë një dritare të vetme kontekstuale me 1 milion kode (1,048,576 kode). Nëse tokenët e hyrjes plus max_output_tokens tejkalojnë 1 048 576 tokenë, API-ja kufizon automatikisht kufirin e daljes në hapësirën e mbetur në dritaren kontekstuale (1,048,576 minus tokenët e hyrjes).
  • Kufiri i parazgjedhur i nxjerrjes sinkrone (64K): Kur background=False (për kërkesat me transmetim dhe pa transmetim), kufiri i parazgjedhur dhe maksimal i max_output_tokens është 65,536 token-ë. Caktimi i max_output_tokens > 65536 me background=False kthen një gabim 400.
  • Dekodimi i gjatë (deri në 1 milion kode): Për të lejuar që Gemini 4 të arsyetojë dhe të gjenerojë përtej 65,536 kodeve (deri në 1,048,576 kode), cakto background=True dhe konfiguro max_output_tokens më të madhe se 65,536. Shiko Dekodimi i gjatë për detaje.

Nënshkrimet e mendimeve

Nënshkrimet e mendimeve janë paraqitje të enkriptuara të arsyetimit të brendshëm të modelit. Ato kërkohen për të ruajtur vazhdimësinë e arsyetimit në ndërveprimet me disa hapa.

Interactions API e bën administrimin e nënshkrimeve të mendimeve shumë më të thjeshtë se generateContent API.

Si parazgjedhje, kur përdor Interactions API në modalitetin me gjendje (duke caktuar store: true dhe duke kaluar previous_interaction_id në radhët vijuese), serveri menaxhon automatikisht gjendjen e bisedës, duke përfshirë të gjitha blloqet e mendimeve dhe nënshkrimet. Në këtë modalitet, nuk është e nevojshme të bësh asgjë në lidhje me nënshkrimet. Ato administrohen tërësisht në anën e serverit.

Modaliteti pa gjendje

Nëse po e menaxhon vetë gjendjen e bisedës (modaliteti pa gjendje) dhe po kalon historikun e plotë të hyrjeve dhe daljeve në çdo kërkesë:

  • DUHET të ridërgosh gjithmonë të gjitha blloqet thought saktësisht siç janë marrë nga modeli.
  • NUK duhet t'i heqësh ose modifikosh blloqet e mendimit nga historiku, pasi ato përmbajnë nënshkrimet e kërkuara që modeli të vazhdojë arsyetimin e tij.
  • Kur ndërron modelet brenda një seance, duhet të ridërgosh përsëri blloqet e mendimit të modelit të mëparshëm. Sistemi fundor menaxhon përputhshmërinë.

Çmimet

Kur arsyetimi është i aktivizuar, çmimi i përgjigjes është shuma e tokenave të nxjerrjes dhe tokenave të arsyetimit. Mund të marrësh numrin total të kodeve të gjeneruara të mendimit nga fusha total_thought_tokens.

Python

print("Thoughts tokens:", interaction.usage.total_thought_tokens)
print("Output tokens:", interaction.usage.total_output_tokens)

JavaScript

console.log(`Thoughts tokens: ${interaction.usage.total_thought_tokens}`);
console.log(`Output tokens: ${interaction.usage.total_output_tokens}`);

Java

import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.Usage;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;

Client client = new Client();

CreateModelInteraction params =
    CreateModelInteraction.builder()
        .model(Model.of("gemini-3.8-flash"))
        .input(InteractionsInput.of("Explain the concept of Occam's Razor."))
        .build();

Interaction interaction =
    client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();

if (interaction.usage().isPresent()) {
  Usage usage = interaction.usage().get();
  System.out.println("Thoughts tokens: " + usage.totalThoughtTokens().orElse(0));
  System.out.println("Output tokens: " + usage.totalOutputTokens().orElse(0));
}

Go

package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    // Turn 1: Execute a reasoning + tool use interaction
    turn1, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model: interactions.Model("gemini-3.8-pro"),
            Input: interactions.NewInteractionsInput("Compare the GDP growth of Japan and Germany in 2025."),
            Tools: []interactions.Tool{
                interactions.NewTool(interactions.GoogleSearch{}),
            },
            GenerationConfig: &interactions.GenerationConfig{
                ThinkingLevel: interactions.ThinkingLevelHigh.ToPointer(),
            },
        }),
    })
    if err != nil {
        log.Fatal(err)
    }

    // Turn 2: Pass PreviousInteractionID so thought signatures are automatically preserved
    turn2, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model:                 interactions.Model("gemini-3.8-pro"),
            PreviousInteractionID: turn1.Interaction.ID,
            Input:                 interactions.NewInteractionsInput("Now summarize that comparison in a 3-row markdown table."),
        }),
    })
    if err != nil {
        log.Fatal(err)
    }

    if turn2.Interaction.OutputText != nil {
        fmt.Println(*turn2.Interaction.OutputText)
    }
}

Modelet e "Arsyetuesit" gjenerojnë mendime të plota për të përmirësuar cilësinë e përgjigjes përfundimtare dhe më pas nxjerrin përmbledhje për të ofruar njohuri për procesin e të menduarit. Çmimi bazohet në tokenët e plotë të mendimit që modeli duhet të gjenerojë, pavarësisht se nga API-ja nxirret vetëm përmbledhja.

Mund të mësosh më shumë rreth tokenëve në udhëzuesin për Numërimin e tokenëve.

Praktikat më të mira

Përdori në mënyrë efikase modelet arsyetuese duke ndjekur këto udhëzime.

  • Rishiko arsyetimin: Analizo përmbledhjet e mendimeve për të kuptuar dështimet dhe për të përmirësuar kërkesat.
  • Kontrollo buxhetin e të menduarit: Kërkoji modelit të mendojë më pak për rezultate të gjata për të kursyer tokenët.
  • Detyrat e thjeshta: Përdor nivel minimal ose të ulët të të menduarit për marrjen ose klasifikimin e fakteve (p.sh. "Ku është themeluar DeepMind?").
  • Detyra të moderuara: Përdor arsyetimin e parazgjedhur për krahasimin e koncepteve ose arsyetimin krijues (p.sh. Krahaso makinat elektrike dhe hibride).
  • Detyra komplekse: Përdor arsyetimin maksimal për kodim të përparuar, matematikë ose planifikim me shumë hapa (p.sh. zgjidh problemet matematikore të AIME).

Çfarë ka më pas