Gjenerimi i tekstit
API-ja Gemini mund të gjenerojë të dhëna teksti nga teksti, imazhet, videot dhe hyrjet audio.
Ja një shembull bazë:
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();
PUSHTIM
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?"
}'
Të menduarit me Binjakët
Modelet Gemini shpesh e kanë të aktivizuar "të menduarit" si parazgjedhje, gjë që i lejon modelit të arsyetojë përpara se t'i përgjigjet një kërkese.
Çdo model mbështet konfigurime të ndryshme të të menduarit, të cilat ju japin kontroll mbi koston, vonesën dhe inteligjencën. Për më shumë detaje, shihni udhëzuesin e të menduarit .
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();
PUSHTIM
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"
}
}'
Udhëzimet e sistemit dhe konfigurimet e tjera
Ju mund të udhëzoni sjelljen e modeleve Gemini me udhëzime të sistemit. Kaloni një parametër system_instruction për të konfiguruar sjelljen e modelit.
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();
PUSHTIM
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"
}'
Gjithashtu mund të anashkaloni parametrat parazgjedhur të gjenerimit, siç është temperatura, duke përdorur parametrin 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();
PUSHTIM
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
}
}'
Referojuni referencës së Interactions API për një listë të plotë të parametrave të konfigurueshëm dhe përshkrimeve të tyre.
Hyrjet multimodale
API-ja Gemini mbështet hyrjet multimodale, duke ju lejuar të kombinoni tekstin me skedarët mediatikë. Shembulli i mëposhtëm demonstron ofrimin e një imazhi:
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();
PUSHTIM
# 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"
}
]
}'
Për metoda alternative të ofrimit të imazheve dhe përpunim më të avancuar të imazheve, shihni udhëzuesin tonë të të kuptuarit të imazheve . API gjithashtu mbështet hyrjet dhe të kuptuarit e dokumenteve , videove dhe audiove .
Përgjigjet që transmetohen
Si parazgjedhje, modeli kthen një përgjigje vetëm pasi të përfundojë i gjithë procesi i gjenerimit.
Për ndërveprime më fluide, përdorni transmetimin në rrjedhë për të trajtuar pjesët e përgjigjes ndërsa ato gjenerohen.
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();
PUSHTIM
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
}'
Biseda me shumë kthesa
API-ja e Ndërveprimeve mbështet bisedat me shumë kthesa duke i lidhur bashkëveprimet së bashku duke përdorur previous_interaction_id . Çdo kthesë është një bashkëveprim i veçantë dhe API-ja menaxhon automatikisht historikun e bisedave.
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();
PUSHTIM
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'"
}'
Transmetimi mund të përdoret gjithashtu për biseda me shumë kthesa duke kombinuar previous_interaction_id me metodat e transmetimit.
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();
PUSHTIM
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
}'
Këshilla nxitëse
Konsultohuni me udhëzuesin tonë të shpejtë inxhinierik për sugjerime se si të përfitoni sa më shumë nga Gemini.
Çfarë vjen më pas
- Provo Gemini në Google AI Studio .
- Eksperimentoni me rezultate të strukturuara për përgjigje të ngjashme me JSON.
- Eksploroni aftësitë e Gemini për të kuptuar imazhet , videot , audiot dhe dokumentet .
- Mësoni rreth strategjive multimodale të nxitjes së skedarëve .