टेक्स्ट जनरेट करने की सुविधा
Gemini API, टेक्स्ट, इमेज, वीडियो, और ऑडियो इनपुट से टेक्स्ट आउटपुट जनरेट कर सकता है.
यहां एक सामान्य उदाहरण दिया गया है:
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input="How does AI work?"
)
print(interaction.steps[-1].content[0].text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
async function main() {
const interaction = await ai.interactions.create({
model: "gemini-3-flash-preview",
input: "How does AI work?",
});
console.log(interaction.steps.at(-1).content[0].text);
}
await main();
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-flash-preview",
"input": "How does AI work?"
}'
Gemini के साथ मिलकर सोचना
Gemini मॉडल में, "सोचने" की सुविधा डिफ़ॉल्ट रूप से चालू होती है. इससे मॉडल को किसी अनुरोध का जवाब देने से पहले, जानकारी का विश्लेषण करने यानी तर्क करने में मदद मिलती है.
हर मॉडल, अलग-अलग थिंकिंग कॉन्फ़िगरेशन के साथ काम करता है. इससे आपको लागत, लेटेन्सी, और इंटेलिजेंस को कंट्रोल करने में मदद मिलती है. ज़्यादा जानकारी के लिए, सोचने की गाइड देखें.
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input="How does AI work?",
generation_config={
"thinking_level": "low"
}
)
print(interaction.steps[-1].content[0].text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
async function main() {
const interaction = await ai.interactions.create({
model: "gemini-3-flash-preview",
input: "How does AI work?",
generation_config: {
thinking_level: "low",
},
});
console.log(interaction.steps.at(-1).content[0].text);
}
await main();
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-flash-preview",
"input": "How does AI work?",
"generation_config": {
"thinking_level": "low"
}
}'
सिस्टम के निर्देश और अन्य कॉन्फ़िगरेशन
सिस्टम के निर्देशों की मदद से, Gemini के मॉडल के व्यवहार को कंट्रोल किया जा सकता है. मॉडल के व्यवहार को कॉन्फ़िगर करने के लिए, system_instruction पैरामीटर पास करें.
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3-flash-preview",
system_instruction="You are a cat. Your name is Neko.",
input="Hello there"
)
print(interaction.steps[-1].content[0].text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
async function main() {
const interaction = await ai.interactions.create({
model: "gemini-3-flash-preview",
input: "Hello there",
system_instruction: "You are a cat. Your name is Neko.",
});
console.log(interaction.steps.at(-1).content[0].text);
}
await main();
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-flash-preview",
"system_instruction": "You are a cat. Your name is Neko.",
"input": "Hello there"
}'
generation_config पैरामीटर का इस्तेमाल करके, जनरेट करने के डिफ़ॉल्ट पैरामीटर को भी बदला जा सकता है. जैसे, तापमान.
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input="Explain how AI works",
generation_config={
"temperature": 0.1
}
)
print(interaction.steps[-1].content[0].text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
async function main() {
const interaction = await ai.interactions.create({
model: "gemini-3-flash-preview",
input: "Explain how AI works",
generation_config: {
temperature: 0.1,
},
});
console.log(interaction.steps.at(-1).content[0].text);
}
await main();
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-flash-preview",
"input": "Explain how AI works",
"generation_config": {
"temperature": 0.1
}
}'
कॉन्फ़िगर किए जा सकने वाले पैरामीटर और उनके ब्यौरे की पूरी सूची देखने के लिए, Interactions API का रेफ़रंस देखें.
मल्टीमॉडल इनपुट
Gemini API में, टेक्स्ट, इमेज, वीडियो वगैरह को प्रोसेस करने वाले मोडल के इनपुट इस्तेमाल किए जा सकते हैं. इससे टेक्स्ट के साथ-साथ मीडिया फ़ाइलें भी इस्तेमाल की जा सकती हैं. यहां दी गई इमेज में, इमेज उपलब्ध कराने का तरीका दिखाया गया है:
Python
from google import genai
client = genai.Client()
uploaded_file = client.files.upload(file="path/to/organ.jpg")
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input=[
{"type": "text", "text": "Tell me about this instrument"},
{
"type": "image",
"uri": uploaded_file.uri,
"mime_type": uploaded_file.mime_type
}
]
)
print(interaction.steps[-1].content[0].text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
async function main() {
const uploadedFile = await ai.files.upload({
file: "path/to/organ.jpg",
config: { mimeType: "image/jpeg" }
});
const interaction = await ai.interactions.create({
model: "gemini-3-flash-preview",
input: [
{type: "text", text: "Tell me about this instrument"},
{
type: "image",
uri: uploadedFile.uri,
mimeType: uploadedFile.mimeType
}
],
});
console.log(interaction.steps.at(-1).content[0].text);
}
await main();
REST
# First upload the file using the Files API, then use the URI:
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-flash-preview",
"input": [
{"type": "text", "text": "Tell me about this instrument"},
{
"type": "image",
"uri": "YOUR_FILE_URI",
"mime_type": "image/jpeg"
}
]
}'
इमेज उपलब्ध कराने के अन्य तरीकों और इमेज प्रोसेसिंग के ज़्यादा बेहतर तरीके के बारे में जानने के लिए, इमेज समझने से जुड़ी हमारी गाइड देखें. यह एपीआई, दस्तावेज़, वीडियो, और ऑडियो इनपुट को भी समझ सकता है.
जवाब स्ट्रीम करना
डिफ़ॉल्ट रूप से, मॉडल जवाब सिर्फ़ तब देता है, जब जनरेट करने की पूरी प्रोसेस पूरी हो जाती है.
बेहतर इंटरैक्शन के लिए, जवाब के चंक जनरेट होने पर उन्हें हैंडल करने के लिए स्ट्रीमिंग का इस्तेमाल करें.
Python
from google import genai
client = genai.Client()
stream = client.interactions.create(
model="gemini-3-flash-preview",
input="Explain how AI works",
stream=True
)
for event in stream:
if event.event_type == "step.delta":
if event.delta.type == "text":
print(event.delta.text, end="")
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
async function main() {
const stream = await ai.interactions.create({
model: "gemini-3-flash-preview",
input: "Explain how AI works",
stream: true,
});
for await (const event of stream) {
if (event.type === "step.delta") {
if (event.delta.type === "text") {
process.stdout.write(event.delta.text);
}
}
}
}
await main();
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?alt=sse" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
--no-buffer \
-d '{
"model": "gemini-3-flash-preview",
"input": "Explain how AI works",
"stream": true
}'
एक से ज़्यादा बार बातचीत करने की सुविधा
Interactions API, एक से ज़्यादा बार बातचीत करने की सुविधा देता है. इसके लिए, यह previous_interaction_id का इस्तेमाल करके, इंटरैक्शन को एक साथ जोड़ता है. हर बातचीत एक अलग इंटरैक्शन होती है. साथ ही, एपीआई बातचीत के इतिहास को अपने-आप मैनेज करता है.
Python
from google import genai
client = genai.Client()
interaction1 = client.interactions.create(
model="gemini-3-flash-preview",
input="I have 2 dogs in my house.",
)
print(interaction1.steps[-1].content[0].text)
interaction2 = client.interactions.create(
model="gemini-3-flash-preview",
input="How many paws are in my house?",
previous_interaction_id=interaction1.id,
)
print(interaction2.steps[-1].content[0].text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
async function main() {
const interaction1 = await ai.interactions.create({
model: "gemini-3-flash-preview",
input: "I have 2 dogs in my house.",
});
console.log("Response 1:", interaction1.steps.at(-1).content[0].text);
const interaction2 = await ai.interactions.create({
model: "gemini-3-flash-preview",
input: "How many paws are in my house?",
previousInteractionId: interaction1.id,
});
console.log("Response 2:", interaction2.steps.at(-1).content[0].text);
}
await main();
REST
RESPONSE1=$(curl -s -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-flash-preview",
"input": "I have 2 dogs in my house."
}')
INTERACTION_ID=$(echo "$RESPONSE1" | jq -r '.name')
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-flash-preview",
"input": "I have two dogs in my house. How many paws are in my house?",
"previous_interaction_id": "'$INTERACTION_ID'"
}'
स्ट्रीमिंग का इस्तेमाल, एक से ज़्यादा बार की जाने वाली बातचीत के लिए भी किया जा सकता है. इसके लिए, previous_interaction_id को स्ट्रीमिंग के तरीकों के साथ जोड़ें.
Python
from google import genai
client = genai.Client()
interaction1 = client.interactions.create(
model="gemini-3-flash-preview",
input="I have 2 dogs in my house.",
)
print(interaction1.steps[-1].content[0].text)
stream = client.interactions.create(
model="gemini-3-flash-preview",
input="How many paws are in my house?",
previous_interaction_id=interaction1.id,
stream=True
)
for event in stream:
if event.event_type == "step.delta":
if event.delta.type == "text":
print(event.delta.text, end="")
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
async function main() {
const interaction1 = await ai.interactions.create({
model: "gemini-3-flash-preview",
input: "I have 2 dogs in my house.",
});
console.log("Response 1:", interaction1.steps.at(-1).content[0].text);
const stream = await ai.interactions.create({
model: "gemini-3-flash-preview",
input: "How many paws are in my house?",
previousInteractionId: interaction1.id,
stream: true,
});
for await (const event of stream) {
if (event.type === "step.delta") {
if (event.delta.type === "text") {
process.stdout.write(event.delta.text);
}
}
}
}
await main();
REST
RESPONSE1=$(curl -s -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-flash-preview",
"input": "I have 2 dogs in my house."
}')
INTERACTION_ID=$(echo "$RESPONSE1" | jq -r '.name')
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?alt=sse" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
--no-buffer \
-d '{
"model": "gemini-3-flash-preview",
"input": "How many paws are in my house?",
"previous_interaction_id": "'$INTERACTION_ID'",
"stream": true
}'
प्रॉम्प्ट लिखने से जुड़ी सलाह
Gemini का ज़्यादा से ज़्यादा फ़ायदा पाने के लिए, प्रॉम्प्ट इंजीनियरिंग गाइड देखें.
आगे क्या करना है
- Google AI Studio में Gemini को आज़माएं.
- JSON जैसे जवाबों के लिए, स्ट्रक्चर्ड आउटपुट की सुविधा आज़माएं.
- Gemini की इमेज, वीडियो, ऑडियो, और दस्तावेज़ को समझने की क्षमताओं के बारे में जानें.
- मल्टीमॉडल फ़ाइल प्रॉम्प्टिंग की रणनीतियों के बारे में जानें.