تولید متن

رابط برنامه‌نویسی نرم‌افزار Gemini می‌تواند از ورودی‌های متن، تصویر، ویدئو و صدا، خروجی متن تولید کند.

در اینجا یک مثال اساسی آورده شده است:

پایتون

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.7-flash",
    input="How does AI work?"
)
print(interaction.output_text)

جاوا اسکریپت

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

const ai = new GoogleGenAI({});

async function main() {
  const interaction = await ai.interactions.create({
    model: "gemini-3.7-flash",
    input: "How does AI work?",
  });
  console.log(interaction.output_text);
}

await main();

استراحت

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.7-flash",
    "input": "How does AI work?"
  }'

کیت‌های توسعه نرم‌افزاری GenAI گوگل، ویژگی‌های راحتی را مستقیماً روی شیء Interaction برگردانده شده ارائه می‌دهند تا به پاسخ مدل دسترسی داشته باشید.

رایج‌ترین تابع کمکی interaction.output_text (رشته‌ای) است که آخرین بلوک‌های متنی در پاسخ مدل را برمی‌گرداند. اگر پاسخ به چندین بلوک TextContent متوالی تقسیم شده باشد، به طور خودکار آنها را به هم متصل می‌کند. توجه داشته باشید که .output_text شامل بلوک‌های متنی قبلی که توسط محتوای غیرمتنی (مانند افکار، تصاویر، صدا یا فراخوانی‌های ابزار) از هم جدا شده‌اند، نمی‌شود. برای پاسخ‌های چندوجهی پیچیده یا درهم‌تنیده، باید به جای آن، steps را به صورت دستی تکرار کنید. برای کسب اطلاعات بیشتر در مورد سایر ویژگی‌های راحتی رسانه، به مرور کلی Interactions مراجعه کنید.

تفکر با جوزا

مدل‌های Gemini اغلب به طور پیش‌فرض قابلیت «تفکر» را فعال دارند که به مدل اجازه می‌دهد قبل از پاسخ به یک درخواست، استدلال کند.

هر مدل از پیکربندی‌های تفکر متفاوتی پشتیبانی می‌کند که به شما امکان کنترل هزینه، تأخیر و هوش را می‌دهد. برای جزئیات بیشتر، به راهنمای تفکر مراجعه کنید.

پایتون

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.7-flash",
    input="How does AI work?",
    generation_config={
        "thinking_level": "low"
    }
)
print(interaction.output_text)

جاوا اسکریپت

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

const ai = new GoogleGenAI({});

async function main() {
  const interaction = await ai.interactions.create({
    model: "gemini-3.7-flash",
    input: "How does AI work?",
    generation_config: {
      thinking_level: "low",
    },
  });
  console.log(interaction.output_text);
}

await main();

استراحت

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.7-flash",
    "input": "How does AI work?",
    "generation_config": {
      "thinking_level": "low"
    }
  }'

دستورالعمل‌های سیستم و سایر تنظیمات

شما می‌توانید رفتار مدل‌های Gemini را با دستورالعمل‌های سیستمی هدایت کنید. برای پیکربندی رفتار مدل، یک پارامتر system_instruction به آن ارسال کنید.

پایتون

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.7-flash",
    system_instruction="You are a cat. Your name is Neko.",
    input="Hello there"
)

print(interaction.output_text)

جاوا اسکریپت

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

const ai = new GoogleGenAI({});

async function main() {
  const interaction = await ai.interactions.create({
    model: "gemini-3.7-flash",
    input: "Hello there",
    system_instruction: "You are a cat. Your name is Neko.",
  });
  console.log(interaction.output_text);
}

await main();

استراحت

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.7-flash",
    "system_instruction": "You are a cat. Your name is Neko.",
    "input": "Hello there"
  }'

همچنین می‌توانید پارامترهای پیش‌فرض تولید، مانند دما، را با استفاده از پارامتر generation_config لغو کنید.

پایتون

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.7-flash",
    input="Explain how AI works",
    generation_config={
        "temperature": 1.0
    }
)
print(interaction.output_text)

جاوا اسکریپت

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

const ai = new GoogleGenAI({});

async function main() {
  const interaction = await ai.interactions.create({
    model: "gemini-3.7-flash",
    input: "Explain how AI works",
    generation_config: {
      temperature: 1.0,
    },
  });
  console.log(interaction.output_text);
}

await main();

استراحت

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY"