Caching

কনটেক্সট ক্যাশিং আপনাকে প্রাক-কম্পিউটেড ইনপুট টোকেনগুলি সংরক্ষণ এবং পুনঃব্যবহারের অনুমতি দেয় যা আপনি বারবার ব্যবহার করতে চান, উদাহরণস্বরূপ একই মিডিয়া ফাইল সম্পর্কে বিভিন্ন প্রশ্ন জিজ্ঞাসা করার সময়। এটি ব্যবহারের উপর নির্ভর করে খরচ এবং গতি সঞ্চয় করতে পারে। বিস্তারিত ভূমিকার জন্য, প্রসঙ্গ ক্যাশিং গাইড দেখুন।

পদ্ধতি: cachedContents.create

ক্যাশেড কনটেন্ট রিসোর্স তৈরি করে।

শেষবিন্দু

পোস্ট https: / /generativelanguage.googleapis.com /v1beta /cachedContents

শরীরের অনুরোধ

অনুরোধের মূল অংশে CachedContent একটি উদাহরণ রয়েছে।

ক্ষেত্র
contents[] object ( Content )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। বিষয়বস্তু ক্যাশে.

tools[] object ( Tool )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। পরবর্তী প্রতিক্রিয়া তৈরি করতে মডেলটি ব্যবহার করতে পারে Tools একটি তালিকা৷

expiration Union type
এই সম্পদের মেয়াদ কখন শেষ হবে তা নির্দিষ্ট করে। expiration নিম্নলিখিতগুলির মধ্যে একটি হতে পারে:
expireTime string ( Timestamp format)

UTC-এ টাইমস্ট্যাম্প যখন এই সংস্থানটির মেয়াদ শেষ বলে বিবেচিত হয়। ইনপুটে যা পাঠানো হয়েছে তা নির্বিশেষে এটি সর্বদা আউটপুটে সরবরাহ করা হয়।

RFC 3339 ব্যবহার করে, যেখানে উৎপন্ন আউটপুট সর্বদা Z-সাধারণ করা হবে এবং 0, 3, 6 বা 9 ভগ্নাংশ সংখ্যা ব্যবহার করে। "Z" ব্যতীত অন্যান্য অফসেটগুলিও গ্রহণ করা হয়। উদাহরণ: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" বা "2014-10-02T15:01:23+05:30"

ttl string ( Duration format)

শুধুমাত্র ইনপুট। এই সম্পদের জন্য নতুন TTL, শুধুমাত্র ইনপুট।

নয়টি পর্যন্ত ভগ্নাংশের সংখ্যা সহ সেকেন্ডে একটি সময়কাল, ' s ' দিয়ে শেষ হয়৷ উদাহরণ: "3.5s"

displayName string

ঐচ্ছিক। অপরিবর্তনীয়। ক্যাশ করা বিষয়বস্তুর ব্যবহারকারীর তৈরি অর্থপূর্ণ প্রদর্শন নাম। সর্বোচ্চ 128টি ইউনিকোড অক্ষর।

model string

প্রয়োজন। অপরিবর্তনীয়। ক্যাশে কন্টেন্ট ফরম্যাটের জন্য ব্যবহার করা Model নাম: models/{model}

systemInstruction object ( Content )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। বিকাশকারী সেট সিস্টেম নির্দেশ. বর্তমানে শুধুমাত্র টেক্সট.

toolConfig object ( ToolConfig )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। টুল কনফিগারেশন। এই কনফিগারেশনটি সকল টুলের জন্য শেয়ার করা হয়েছে।

উদাহরণ অনুরোধ

from google import genai
from google.genai import types

client = genai.Client()
document = client.files.upload(file=media / "a11.txt")
model_name = "gemini-1.5-flash-001"

cache = client.caches.create(
    model=model_name,
    config=types.CreateCachedContentConfig(
        contents=[document],
        system_instruction="You are an expert analyzing transcripts.",
    ),
)
print(cache)

response = client.models.generate_content(
    model=model_name,
    contents="Please summarize this transcript",
    config=types.GenerateContentConfig(cached_content=cache.name),
)
print(response.text)
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);
const modelName = "gemini-1.5-flash-001";

const contents = [
  createUserContent(createPartFromUri(document.uri, document.mimeType)),
];

const cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: contents,
    systemInstruction: "You are an expert analyzing transcripts.",
  },
});
console.log("Cache created:", cache);

const response = await ai.models.generateContent({
  model: modelName,
  contents: "Please summarize this transcript",
  config: { cachedContent: cache.name },
});
console.log("Response text:", response.text);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"), 
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}
parts := []*genai.Part{
	genai.NewPartFromURI(document.URI, document.MIMEType),
}
contents := []*genai.Content{
	genai.NewContentFromParts(parts, "user"),
}
cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents: contents,
	SystemInstruction: genai.NewContentFromText(
		"You are an expert analyzing transcripts.", "user",
	),
})
if err != nil {
	log.Fatal(err)
}
fmt.Println("Cache created:")
fmt.Println(cache)

// Use the cache for generating content.
response, err := client.Models.GenerateContent(
	ctx,
	modelName,
	genai.Text("Please summarize this transcript"),
	&genai.GenerateContentConfig{
		CachedContent: cache.Name,
	},
)
if err != nil {
	log.Fatal(err)
}
printResponse(response)
wget https://storage.googleapis.com/generativeai-downloads/data/a11.txt
echo '{
  "model": "models/gemini-1.5-flash-001",
  "contents":[
    {
      "parts":[
        {
          "inline_data": {
            "mime_type":"text/plain",
            "data": "'$(base64 $B64FLAGS a11.txt)'"
          }
        }
      ],
    "role": "user"
    }
  ],
  "systemInstruction": {
    "parts": [
      {
        "text": "You are an expert at analyzing transcripts."
      }
    ]
  },
  "ttl": "300s"
}' > request.json

curl -X POST "https://generativelanguage.googleapis.com/v1beta/cachedContents?key=$GEMINI_API_KEY" \
 -H 'Content-Type: application/json' \
 -d @request.json \
 > cache.json

CACHE_NAME=$(cat cache.json | grep '"name":' | cut -d '"' -f 4 | head -n 1)

curl -X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-001:generateContent?key=$GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
      "contents": [
        {
          "parts":[{
            "text": "Please summarize this transcript"
          }],
          "role": "user"
        },
      ],
      "cachedContent": "'$CACHE_NAME'"
    }'
from google import genai
from google.genai import types

client = genai.Client()
document = client.files.upload(file=media / "a11.txt")
model_name = "gemini-1.5-flash-001"

cache = client.caches.create(
    model=model_name,
    config=types.CreateCachedContentConfig(
        contents=[document],
        system_instruction="You are an expert analyzing transcripts.",
    ),
)
cache_name = cache.name  # Save the name for later

# Later retrieve the cache
cache = client.caches.get(name=cache_name)
response = client.models.generate_content(
    model=model_name,
    contents="Find a lighthearted moment from this transcript",
    config=types.GenerateContentConfig(cached_content=cache.name),
)
print(response.text)
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);
const modelName = "gemini-1.5-flash-001";

const contents = [
  createUserContent(createPartFromUri(document.uri, document.mimeType)),
];

const cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: contents,
    systemInstruction: "You are an expert analyzing transcripts.",
  },
});
const cacheName = cache.name; // Save the name for later

// Later retrieve the cache
const retrievedCache = await ai.caches.get({ name: cacheName });
const response = await ai.models.generateContent({
  model: modelName,
  contents: "Find a lighthearted moment from this transcript",
  config: { cachedContent: retrievedCache.name },
});
console.log("Response text:", response.text);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"),
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}
parts := []*genai.Part{
	genai.NewPartFromURI(document.URI, document.MIMEType),
}
contents := []*genai.Content{
	genai.NewContentFromParts(parts, "user"),
}
cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents:          contents,
	SystemInstruction: genai.NewContentFromText(
		"You are an expert analyzing transcripts.", "user",
	),
})
if err != nil {
	log.Fatal(err)
}
cacheName := cache.Name

// Later retrieve the cache.
cache, err = client.Caches.Get(ctx, cacheName, &genai.GetCachedContentConfig{})
if err != nil {
	log.Fatal(err)
}

response, err := client.Models.GenerateContent(
	ctx,
	modelName,
	genai.Text("Find a lighthearted moment from this transcript"),
	&genai.GenerateContentConfig{
		CachedContent: cache.Name,
	},
)
if err != nil {
	log.Fatal(err)
}
fmt.Println("Response from cache (create from name):")
printResponse(response)
from google import genai
from google.genai import types

client = genai.Client()
model_name = "gemini-1.5-flash-001"
system_instruction = "You are an expert analyzing transcripts."

# Create a chat session with the given system instruction.
chat = client.chats.create(
    model=model_name,
    config=types.GenerateContentConfig(system_instruction=system_instruction),
)
document = client.files.upload(file=media / "a11.txt")

response = chat.send_message(
    message=["Hi, could you summarize this transcript?", document]
)
print("\n\nmodel:  ", response.text)
response = chat.send_message(
    message=["Okay, could you tell me more about the trans-lunar injection"]
)
print("\n\nmodel:  ", response.text)

# To cache the conversation so far, pass the chat history as the list of contents.
cache = client.caches.create(
    model=model_name,
    config={
        "contents": chat.get_history(),
        "system_instruction": system_instruction,
    },
)
# Continue the conversation using the cached content.
chat = client.chats.create(
    model=model_name,
    config=types.GenerateContentConfig(cached_content=cache.name),
)
response = chat.send_message(
    message="I didn't understand that last part, could you explain it in simpler language?"
)
print("\n\nmodel:  ", response.text)
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const modelName = "gemini-1.5-flash-001";
const systemInstruction = "You are an expert analyzing transcripts.";

// Create a chat session with the system instruction.
const chat = ai.chats.create({
  model: modelName,
  config: { systemInstruction: systemInstruction },
});
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);

let response = await chat.sendMessage({
  message: createUserContent([
    "Hi, could you summarize this transcript?",
    createPartFromUri(document.uri, document.mimeType),
  ]),
});
console.log("\n\nmodel:", response.text);

response = await chat.sendMessage({
  message: "Okay, could you tell me more about the trans-lunar injection",
});
console.log("\n\nmodel:", response.text);

// To cache the conversation so far, pass the chat history as the list of contents.
const chatHistory = chat.getHistory();
const cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: chatHistory,
    systemInstruction: systemInstruction,
  },
});

// Continue the conversation using the cached content.
const chatWithCache = ai.chats.create({
  model: modelName,
  config: { cachedContent: cache.name },
});
response = await chatWithCache.sendMessage({
  message:
    "I didn't understand that last part, could you explain it in simpler language?",
});
console.log("\n\nmodel:", response.text);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"),
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
systemInstruction := "You are an expert analyzing transcripts."

// Create initial chat with a system instruction.
chat, err := client.Chats.Create(ctx, modelName, &genai.GenerateContentConfig{
	SystemInstruction: genai.NewContentFromText(systemInstruction, "user"),
}, nil)
if err != nil {
	log.Fatal(err)
}

document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}

// Send first message with the transcript.
parts := make([]genai.Part, 2)
parts[0] = genai.Part{Text: "Hi, could you summarize this transcript?"}
parts[1] = genai.Part{
	FileData: &genai.FileData{
		FileURI :      document.URI,
		MIMEType: document.MIMEType,
	},
}

// Send chat message.
resp, err := chat.SendMessage(ctx, parts...)
if err != nil {
	log.Fatal(err)
}
fmt.Println("\n\nmodel: ", resp.Text())

resp, err = chat.SendMessage(
	ctx, 
	genai.Part{
		Text: "Okay, could you tell me more about the trans-lunar injection",
	},
)
if err != nil {
	log.Fatal(err)
}
fmt.Println("\n\nmodel: ", resp.Text())

// To cache the conversation so far, pass the chat history as the list of contents.
cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents:          chat.History(false),
	SystemInstruction: genai.NewContentFromText(systemInstruction, "user"),
})
if err != nil {
	log.Fatal(err)
}

// Continue the conversation using the cached history.
chat, err = client.Chats.Create(ctx, modelName, &genai.GenerateContentConfig{
	CachedContent: cache.Name,
}, nil)
if err != nil {
	log.Fatal(err)
}

resp, err = chat.SendMessage(
	ctx, 
	genai.Part{
		Text: "I didn't understand that last part, could you explain it in simpler language?",
	},
)
if err != nil {
	log.Fatal(err)
}
fmt.Println("\n\nmodel: ", resp.Text())

প্রতিক্রিয়া শরীর

সফল হলে, রেসপন্স বডিতে CachedContent একটি নতুন তৈরি ইনস্ট্যান্স থাকে।

পদ্ধতি: cachedContents.list

ক্যাশেড বিষয়বস্তু তালিকাভুক্ত করে।

শেষবিন্দু

https: / /generativelanguage.googleapis.com /v1beta /cachedContents পান

ক্যোয়ারী প্যারামিটার

pageSize integer

ঐচ্ছিক। ফেরত দেওয়ার জন্য ক্যাশ করা সামগ্রীর সর্বাধিক সংখ্যা৷ পরিষেবাটি এই মানের থেকে কম ফেরত দিতে পারে। অনির্দিষ্ট থাকলে, কিছু ডিফল্ট (সর্বোচ্চ অধীনে) আইটেম সংখ্যা ফেরত দেওয়া হবে। সর্বোচ্চ মান 1000; 1000-এর উপরে মান 1000-এ বাধ্য করা হবে।

pageToken string

ঐচ্ছিক। একটি পৃষ্ঠা টোকেন, একটি পূর্ববর্তী cachedContents.list কল থেকে প্রাপ্ত। পরবর্তী পৃষ্ঠাটি পুনরুদ্ধার করতে এটি প্রদান করুন।

পেজিনেট করার সময়, cachedContents.list এ প্রদত্ত অন্যান্য সমস্ত প্যারামিটার অবশ্যই পেজ টোকেন প্রদানকারী কলের সাথে মিলতে হবে।

শরীরের অনুরোধ

অনুরোধের বডি খালি হতে হবে।

প্রতিক্রিয়া শরীর

ক্যাশেড বিষয়বস্তু তালিকা সহ প্রতিক্রিয়া.

সফল হলে, প্রতিক্রিয়া বডিতে নিম্নলিখিত কাঠামোর সাথে ডেটা থাকে:

ক্ষেত্র
cachedContents[] object ( CachedContent )

ক্যাশ করা বিষয়বস্তুর তালিকা।

nextPageToken string

একটি টোকেন, যা পরবর্তী পৃষ্ঠা পুনরুদ্ধার করতে pageToken হিসাবে পাঠানো যেতে পারে। যদি এই ক্ষেত্রটি বাদ দেওয়া হয়, তাহলে পরবর্তী পৃষ্ঠা থাকবে না।

JSON প্রতিনিধিত্ব
{
  "cachedContents": [
    {
      object (CachedContent)
    }
  ],
  "nextPageToken": string
}

পদ্ধতি: cachedContents.get

ক্যাশেড কনটেন্ট রিসোর্স পড়ে।

শেষবিন্দু

https: / /generativelanguage.googleapis.com /v1beta /{name=cachedContents /*} পান

পাথ প্যারামিটার

name string

প্রয়োজন। বিষয়বস্তু ক্যাশে এন্ট্রি উল্লেখ করে সম্পদ নাম. বিন্যাস: cachedContents/{id} এটি cachedContents/{cachedcontent} ফর্ম নেয়।

শরীরের অনুরোধ

অনুরোধের বডি খালি হতে হবে।

উদাহরণ অনুরোধ

from google import genai

client = genai.Client()
document = client.files.upload(file=media / "a11.txt")
model_name = "gemini-1.5-flash-001"

cache = client.caches.create(
    model=model_name,
    config={
        "contents": [document],
        "system_instruction": "You are an expert analyzing transcripts.",
    },
)
print(client.caches.get(name=cache.name))
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);
const modelName = "gemini-1.5-flash-001";

const contents = [
  createUserContent(createPartFromUri(document.uri, document.mimeType)),
];

const cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: contents,
    systemInstruction: "You are an expert analyzing transcripts.",
  },
});
const retrievedCache = await ai.caches.get({ name: cache.name });
console.log("Retrieved Cache:", retrievedCache);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"),
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}
parts := []*genai.Part{
	genai.NewPartFromURI(document.URI, document.MIMEType),
}
contents := []*genai.Content{
	genai.NewContentFromParts(parts, "user"),
}

cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents:          contents,
	SystemInstruction: genai.NewContentFromText(
		"You are an expert analyzing transcripts.", "user",
	),
})
if err != nil {
	log.Fatal(err)
}

cache, err = client.Caches.Get(ctx, cache.Name, &genai.GetCachedContentConfig{})
if err != nil {
	log.Fatal(err)
}
fmt.Println("Retrieved cache:")
fmt.Println(cache)
curl "https://generativelanguage.googleapis.com/v1beta/$CACHE_NAME?key=$GEMINI_API_KEY"

প্রতিক্রিয়া শরীর

সফল হলে, প্রতিক্রিয়া বডিতে CachedContent একটি উদাহরণ থাকে।

পদ্ধতি: cachedContents.patch

ক্যাশেড কনটেন্ট রিসোর্স আপডেট করে (কেবলমাত্র মেয়াদ শেষ হওয়া আপডেটযোগ্য)।

শেষবিন্দু

প্যাচ https: / /generativelanguage.googleapis.com /v1beta /{cachedContent.name=cachedContents /*}
PATCH https://generativelanguage.googleapis.com/v1beta/{cachedContent.name=cachedContents/*}

পাথ প্যারামিটার

cachedContent.name string

শুধুমাত্র আউটপুট। শনাক্তকারী। সম্পদের নাম ক্যাশে করা বিষয়বস্তু উল্লেখ করে। বিন্যাস: cachedContents/{id} এটি cachedContents/{cachedcontent} ফর্ম নেয়।

ক্যোয়ারী প্যারামিটার

updateMask string ( FieldMask format)

আপডেট করার জন্য ক্ষেত্রগুলির তালিকা৷

এটি ক্ষেত্রগুলির সম্পূর্ণরূপে যোগ্য নামের একটি কমা দ্বারা পৃথক করা তালিকা৷ উদাহরণ: "user.displayName,photo"

শরীরের অনুরোধ

অনুরোধের মূল অংশে CachedContent একটি উদাহরণ রয়েছে।

ক্ষেত্র
expiration Union type
এই সম্পদের মেয়াদ কখন শেষ হবে তা নির্দিষ্ট করে। expiration নিম্নলিখিতগুলির মধ্যে একটি হতে পারে:
expireTime string ( Timestamp format)

UTC-এ টাইমস্ট্যাম্প যখন এই সংস্থানটির মেয়াদ শেষ বলে বিবেচিত হয়। ইনপুটে যা পাঠানো হয়েছে তা নির্বিশেষে এটি সর্বদা আউটপুটে সরবরাহ করা হয়।

RFC 3339 ব্যবহার করে, যেখানে উৎপন্ন আউটপুট সর্বদা Z-সাধারণ করা হবে এবং 0, 3, 6 বা 9 ভগ্নাংশ সংখ্যা ব্যবহার করে। "Z" ব্যতীত অন্যান্য অফসেটগুলিও গ্রহণ করা হয়। উদাহরণ: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" বা "2014-10-02T15:01:23+05:30"

ttl string ( Duration format)

শুধুমাত্র ইনপুট। এই সম্পদের জন্য নতুন TTL, শুধুমাত্র ইনপুট।

নয়টি পর্যন্ত ভগ্নাংশের সংখ্যা সহ সেকেন্ডে একটি সময়কাল, ' s ' দিয়ে শেষ হয়৷ উদাহরণ: "3.5s"

উদাহরণ অনুরোধ

from google import genai
from google.genai import types
import datetime

client = genai.Client()
document = client.files.upload(file=media / "a11.txt")
model_name = "gemini-1.5-flash-001"

cache = client.caches.create(
    model=model_name,
    config={
        "contents": [document],
        "system_instruction": "You are an expert analyzing transcripts.",
    },
)

# Update the cache's time-to-live (ttl)
ttl = f"{int(datetime.timedelta(hours=2).total_seconds())}s"
client.caches.update(
    name=cache.name, config=types.UpdateCachedContentConfig(ttl=ttl)
)
print(f"After update:\n {cache}")

# Alternatively, update the expire_time directly
# Update the expire_time directly in valid RFC 3339 format (UTC with a "Z" suffix)
expire_time = (
    (
        datetime.datetime.now(datetime.timezone.utc)
        + datetime.timedelta(minutes=15)
    )
    .isoformat()
    .replace("+00:00", "Z")
)
client.caches.update(
    name=cache.name,
    config=types.UpdateCachedContentConfig(expire_time=expire_time),
)
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);
const modelName = "gemini-1.5-flash-001";

const contents = [
  createUserContent(createPartFromUri(document.uri, document.mimeType)),
];

let cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: contents,
    systemInstruction: "You are an expert analyzing transcripts.",
  },
});

// Update the cache's time-to-live (ttl)
const ttl = `${2 * 3600}s`; // 2 hours in seconds
cache = await ai.caches.update({
  name: cache.name,
  config: { ttl },
});
console.log("After update (TTL):", cache);

// Alternatively, update the expire_time directly (in RFC 3339 format with a "Z" suffix)
const expireTime = new Date(Date.now() + 15 * 60000)
  .toISOString()
  .replace(/\.\d{3}Z$/, "Z");
cache = await ai.caches.update({
  name: cache.name,
  config: { expireTime: expireTime },
});
console.log("After update (expire_time):", cache);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"),
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}
parts := []*genai.Part{
	genai.NewPartFromURI(document.URI, document.MIMEType),
}
contents := []*genai.Content{
	genai.NewContentFromParts(parts, "user"),
}

cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents:          contents,
	SystemInstruction: genai.NewContentFromText(
		"You are an expert analyzing transcripts.", "user",
	),
})
if err != nil {
	log.Fatal(err)
}

_, err = client.Caches.Delete(ctx, cache.Name, &genai.DeleteCachedContentConfig{})
if err != nil {
	log.Fatal(err)
}
fmt.Println("Cache deleted:", cache.Name)
curl -X PATCH "https://generativelanguage.googleapis.com/v1beta/$CACHE_NAME?key=$GEMINI_API_KEY" \
 -H 'Content-Type: application/json' \
 -d '{"ttl": "600s"}'

প্রতিক্রিয়া শরীর

সফল হলে, প্রতিক্রিয়া বডিতে CachedContent একটি উদাহরণ থাকে।

পদ্ধতি: cachedContents.delete

ক্যাশেড কনটেন্ট রিসোর্স মুছে দেয়।

শেষবিন্দু

https: / /generativelanguage.googleapis.com /v1beta /{name=cachedContents /*} মুছুন

পাথ প্যারামিটার

name string

প্রয়োজন। বিষয়বস্তু ক্যাশে এন্ট্রি ফর্ম্যাট উল্লেখ করে সম্পদ নাম: cachedContents/{id} এটি cachedContents/{cachedcontent} ফর্ম নেয়।

শরীরের অনুরোধ

অনুরোধের বডি খালি হতে হবে।

উদাহরণ অনুরোধ

from google import genai

client = genai.Client()
document = client.files.upload(file=media / "a11.txt")
model_name = "gemini-1.5-flash-001"

cache = client.caches.create(
    model=model_name,
    config={
        "contents": [document],
        "system_instruction": "You are an expert analyzing transcripts.",
    },
)
client.caches.delete(name=cache.name)
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);
const modelName = "gemini-1.5-flash-001";

const contents = [
  createUserContent(createPartFromUri(document.uri, document.mimeType)),
];

const cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: contents,
    systemInstruction: "You are an expert analyzing transcripts.",
  },
});
await ai.caches.delete({ name: cache.name });
console.log("Cache deleted:", cache.name);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"),
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}
parts := []*genai.Part{
	genai.NewPartFromURI(document.URI, document.MIMEType),
}
contents := []*genai.Content{
	genai.NewContentFromParts(parts, "user"),
}

cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents:          contents,
	SystemInstruction: genai.NewContentFromText(
		"You are an expert analyzing transcripts.", "user",
	),
})
if err != nil {
	log.Fatal(err)
}

_, err = client.Caches.Delete(ctx, cache.Name, &genai.DeleteCachedContentConfig{})
if err != nil {
	log.Fatal(err)
}
fmt.Println("Cache deleted:", cache.Name)
curl -X DELETE "https://generativelanguage.googleapis.com/v1beta/$CACHE_NAME?key=$GEMINI_API_KEY"

প্রতিক্রিয়া শরীর

সফল হলে, প্রতিক্রিয়া বডি একটি খালি JSON অবজেক্ট।

REST সম্পদ: ক্যাশেড বিষয়বস্তু

সম্পদ: ক্যাশেড সামগ্রী

বিষয়বস্তু যা প্রি-প্রসেস করা হয়েছে এবং পরবর্তীতে GenerativeService-এর অনুরোধে ব্যবহার করা যেতে পারে।

ক্যাশে করা সামগ্রী শুধুমাত্র সেই মডেলের সাথে ব্যবহার করা যেতে পারে যার জন্য এটি তৈরি করা হয়েছিল৷

ক্ষেত্র
contents[] object ( Content )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। বিষয়বস্তু ক্যাশে.

tools[] object ( Tool )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। পরবর্তী প্রতিক্রিয়া তৈরি করতে মডেলটি ব্যবহার করতে পারে Tools একটি তালিকা৷

createTime string ( Timestamp format)

শুধুমাত্র আউটপুট। ক্যাশে এন্ট্রি তৈরির সময়।

RFC 3339 ব্যবহার করে, যেখানে উৎপন্ন আউটপুট সর্বদা Z-সাধারণ করা হবে এবং 0, 3, 6 বা 9 ভগ্নাংশ সংখ্যা ব্যবহার করে। "Z" ব্যতীত অন্যান্য অফসেটগুলিও গ্রহণ করা হয়। উদাহরণ: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" বা "2014-10-02T15:01:23+05:30"

updateTime string ( Timestamp format)

শুধুমাত্র আউটপুট। যখন ক্যাশে এন্ট্রি শেষবার UTC সময়ে আপডেট করা হয়েছিল।

RFC 3339 ব্যবহার করে, যেখানে উৎপন্ন আউটপুট সর্বদা Z-সাধারণ করা হবে এবং 0, 3, 6 বা 9 ভগ্নাংশ সংখ্যা ব্যবহার করে। "Z" ব্যতীত অন্যান্য অফসেটগুলিও গ্রহণ করা হয়। উদাহরণ: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" বা "2014-10-02T15:01:23+05:30"

usageMetadata object ( UsageMetadata )

শুধুমাত্র আউটপুট। ক্যাশে করা বিষয়বস্তুর ব্যবহারের উপর মেটাডেটা।

expiration Union type
এই সম্পদের মেয়াদ কখন শেষ হবে তা নির্দিষ্ট করে। expiration নিম্নলিখিতগুলির মধ্যে একটি হতে পারে:
expireTime string ( Timestamp format)

UTC-এ টাইমস্ট্যাম্প যখন এই সংস্থানটির মেয়াদ শেষ বলে বিবেচিত হয়। ইনপুটে যা পাঠানো হয়েছে তা নির্বিশেষে এটি সর্বদা আউটপুটে সরবরাহ করা হয়।

RFC 3339 ব্যবহার করে, যেখানে উৎপন্ন আউটপুট সর্বদা Z-সাধারণ করা হবে এবং 0, 3, 6 বা 9 ভগ্নাংশ সংখ্যা ব্যবহার করে। "Z" ব্যতীত অন্যান্য অফসেটগুলিও গ্রহণ করা হয়। উদাহরণ: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" বা "2014-10-02T15:01:23+05:30"

ttl string ( Duration format)

শুধুমাত্র ইনপুট। এই সম্পদের জন্য নতুন TTL, শুধুমাত্র ইনপুট।

নয়টি পর্যন্ত ভগ্নাংশের সংখ্যা সহ সেকেন্ডে একটি সময়কাল, ' s ' দিয়ে শেষ হয়৷ উদাহরণ: "3.5s"

name string

শুধুমাত্র আউটপুট। শনাক্তকারী। সম্পদের নাম ক্যাশে করা বিষয়বস্তু উল্লেখ করে। বিন্যাস: cachedContents/{id}

displayName string

ঐচ্ছিক। অপরিবর্তনীয়। ক্যাশ করা বিষয়বস্তুর ব্যবহারকারীর তৈরি অর্থপূর্ণ প্রদর্শন নাম। সর্বোচ্চ 128টি ইউনিকোড অক্ষর।

model string

প্রয়োজন। অপরিবর্তনীয়। ক্যাশে কন্টেন্ট ফরম্যাটের জন্য ব্যবহার করা Model নাম: models/{model}

systemInstruction object ( Content )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। বিকাশকারী সেট সিস্টেম নির্দেশ. বর্তমানে শুধুমাত্র টেক্সট.

toolConfig object ( ToolConfig )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। টুল কনফিগারেশন। এই কনফিগারেশনটি সকল টুলের জন্য শেয়ার করা হয়েছে।

JSON প্রতিনিধিত্ব
{
  "contents": [
    {
      object (Content)
    }
  ],
  "tools": [
    {
      object (Tool)
    }
  ],
  "createTime": string,
  "updateTime": string,
  "usageMetadata": {
    object (UsageMetadata)
  },

  // expiration
  "expireTime": string,
  "ttl": string
  // Union type
  "name": string,
  "displayName": string,
  "model": string,
  "systemInstruction": {
    object (Content)
  },
  "toolConfig": {
    object (ToolConfig)
  }
}

বিষয়বস্তু

একটি বার্তার বহু-অংশ বিষয়বস্তু ধারণকারী বেস স্ট্রাকচার্ড ডেটাটাইপ।

একটি Content মধ্যে একটি role ক্ষেত্র রয়েছে যা Content প্রযোজককে মনোনীত করে এবং একটি parts ক্ষেত্র যাতে বহু-অংশের ডেটা থাকে যাতে বার্তার বিষয়বস্তু থাকে।

ক্ষেত্র
parts[] object ( Part )

অর্ডার করা Parts যা একটি একক বার্তা গঠন করে। অংশের বিভিন্ন MIME প্রকার থাকতে পারে।

role string

ঐচ্ছিক। বিষয়বস্তুর প্রযোজক। 'ব্যবহারকারী' বা 'মডেল' হতে হবে।

মাল্টি-টার্ন কথোপকথনের জন্য সেট করার জন্য দরকারী, অন্যথায় ফাঁকা বা সেট না করা যেতে পারে।

JSON প্রতিনিধিত্ব
{
  "parts": [
    {
      object (Part)
    }
  ],
  "role": string
}

অংশ

মিডিয়া ধারণকারী একটি ডেটাটাইপ যা একটি বহু-অংশ Content বার্তার অংশ।

একটি Part ডেটা থাকে যার একটি সম্পর্কিত ডেটাটাইপ থাকে। একটি Part শুধুমাত্র Part.data তে গৃহীত প্রকারগুলির একটি ধারণ করতে পারে।

একটি Part অবশ্যই একটি নির্দিষ্ট IANA MIME টাইপ থাকতে হবে যা মিডিয়ার ধরন এবং উপপ্রকার সনাক্ত করে যদি inlineData ক্ষেত্র কাঁচা বাইট দিয়ে পূর্ণ হয়।

ক্ষেত্র
boolean thought

ঐচ্ছিক। অংশটি মডেল থেকে চিন্তা করা হলে নির্দেশ করে।

data Union type
data নিম্নলিখিতগুলির মধ্যে একটি হতে পারে:
text string

ইনলাইন পাঠ্য।

inlineData object ( Blob )

ইনলাইন মিডিয়া বাইট।

functionCall object ( FunctionCall )

একটি ভবিষ্যদ্বাণীকৃত FunctionCall মডেল থেকে ফিরে এসেছে যেটিতে একটি স্ট্রিং রয়েছে যা আর্গুমেন্ট এবং তাদের মান সহ FunctionDeclaration.name প্রতিনিধিত্ব করে।

functionResponse object ( FunctionResponse )

একটি FunctionCall এর ফলাফল আউটপুট যেটিতে FunctionDeclaration.name প্রতিনিধিত্বকারী একটি স্ট্রিং রয়েছে এবং ফাংশন থেকে যেকোনো আউটপুট ধারণকারী একটি কাঠামোগত JSON অবজেক্ট মডেলের প্রসঙ্গ হিসাবে ব্যবহৃত হয়।

fileData object ( FileData )

URI ভিত্তিক ডেটা।

executableCode object ( ExecutableCode )

মডেল দ্বারা উত্পন্ন কোড যা কার্যকর করা হবে।

codeExecutionResult object ( CodeExecutionResult )

ExecutableCode কার্যকর করার ফলাফল।

JSON প্রতিনিধিত্ব
{
  "thought": boolean,

  // data
  "text": string,
  "inlineData": {
    object (Blob)
  },
  "functionCall": {
    object (FunctionCall)
  },
  "functionResponse": {
    object (FunctionResponse)
  },
  "fileData": {
    object (FileData)
  },
  "executableCode": {
    object (ExecutableCode)
  },
  "codeExecutionResult": {
    object (CodeExecutionResult)
  }
  // Union type
}

ব্লব

কাঁচা মিডিয়া বাইট।

টেক্সট কাঁচা বাইট হিসাবে পাঠানো উচিত নয়, 'টেক্সট' ক্ষেত্র ব্যবহার করুন।

ক্ষেত্র
mimeType string

উৎস ডেটার IANA স্ট্যান্ডার্ড MIME প্রকার। উদাহরণ: - image/png - image/jpeg যদি একটি অসমর্থিত MIME প্রকার প্রদান করা হয়, একটি ত্রুটি ফেরত দেওয়া হবে। সমর্থিত প্রকারের সম্পূর্ণ তালিকার জন্য, সমর্থিত ফাইল বিন্যাস দেখুন।

data string ( bytes format)

মিডিয়া ফরম্যাটের জন্য কাঁচা বাইট।

একটি base64-এনকোডেড স্ট্রিং।

JSON প্রতিনিধিত্ব
{
  "mimeType": string,
  "data": string
}

ফাংশনকল

একটি ভবিষ্যদ্বাণীকৃত FunctionCall মডেল থেকে ফিরে এসেছে যেটিতে একটি স্ট্রিং রয়েছে যা আর্গুমেন্ট এবং তাদের মান সহ FunctionDeclaration.name প্রতিনিধিত্ব করে।

ক্ষেত্র
id string

ঐচ্ছিক। ফাংশন কলের অনন্য আইডি। জনবহুল হলে, ক্লায়েন্ট functionCall চালাতে কল করবে এবং ম্যাচিং id সহ প্রতিক্রিয়া ফেরত দেবে।

name string

প্রয়োজন। কল করার ফাংশনের নাম। az, AZ, 0-9 হতে হবে অথবা আন্ডারস্কোর এবং ড্যাশ থাকতে হবে, যার সর্বোচ্চ দৈর্ঘ্য 63।

args object ( Struct format)

ঐচ্ছিক। JSON অবজেক্ট ফরম্যাটে ফাংশন প্যারামিটার এবং মান।

JSON প্রতিনিধিত্ব
{
  "id": string,
  "name": string,
  "args": {
    object
  }
}

ফাংশন রেসপন্স

একটি FunctionCall থেকে ফলাফল আউটপুট যেটিতে FunctionDeclaration.name প্রতিনিধিত্বকারী একটি স্ট্রিং রয়েছে এবং ফাংশন থেকে যেকোনো আউটপুট ধারণকারী একটি কাঠামোগত JSON অবজেক্ট মডেলের প্রসঙ্গ হিসাবে ব্যবহৃত হয়। এটিতে মডেল পূর্বাভাসের উপর ভিত্তি করে তৈরি একটি FunctionCall ফলাফল থাকা উচিত।

ক্ষেত্র
id string

ঐচ্ছিক। এই প্রতিক্রিয়া কল ফাংশন আইডি জন্য. সংশ্লিষ্ট ফাংশন কল id সাথে মেলে ক্লায়েন্ট দ্বারা জনবহুল।

name string

প্রয়োজন। কল করার ফাংশনের নাম। az, AZ, 0-9 হতে হবে অথবা আন্ডারস্কোর এবং ড্যাশ থাকতে হবে, যার সর্বোচ্চ দৈর্ঘ্য 63।

response object ( Struct format)

প্রয়োজন। JSON অবজেক্ট ফরম্যাটে ফাংশন প্রতিক্রিয়া।

JSON প্রতিনিধিত্ব
{
  "id": string,
  "name": string,
  "response": {
    object
  }
}

ফাইল ডেটা

URI ভিত্তিক ডেটা।

ক্ষেত্র
mimeType string

ঐচ্ছিক। উৎস ডেটার IANA স্ট্যান্ডার্ড MIME প্রকার।

fileUri string

প্রয়োজন। ইউআরআই।

JSON প্রতিনিধিত্ব
{
  "mimeType": string,
  "fileUri": string
}

এক্সিকিউটেবল কোড

কোড যে মডেলের দ্বারা উত্পন্ন হয় যা কার্যকর করা হয় এবং ফলাফলটি মডেলে ফিরে আসে।

শুধুমাত্র CodeExecution টুল ব্যবহার করার সময় তৈরি করা হয়, যেখানে কোডটি স্বয়ংক্রিয়ভাবে কার্যকর হবে এবং একটি সংশ্লিষ্ট CodeExecutionResult ও তৈরি হবে।

ক্ষেত্র
language enum ( Language )

প্রয়োজন। code প্রোগ্রামিং ভাষা।

code string

প্রয়োজন। কোডটি কার্যকর করতে হবে।

JSON প্রতিনিধিত্ব
{
  "language": enum (Language),
  "code": string
}

ভাষা

উত্পন্ন কোডের জন্য সমর্থিত প্রোগ্রামিং ভাষা।

Enums
LANGUAGE_UNSPECIFIED অনির্দিষ্ট ভাষা। এই মান ব্যবহার করা উচিত নয়.
PYTHON পাইথন >= 3.10, নম্পি এবং সিম্পি উপলব্ধ।

কোড এক্সিকিউশন ফলাফল

ExecutableCode কার্যকর করার ফলাফল।

শুধুমাত্র CodeExecution ব্যবহার করার সময় উৎপন্ন হয় এবং সর্বদা ExecutableCode ধারণকারী একটি part অনুসরণ করে।

ক্ষেত্র
outcome enum ( Outcome )

প্রয়োজন। কোড নির্বাহের ফলাফল।

output string

ঐচ্ছিক। কোড এক্সিকিউশন সফল হলে stdout ধারণ করে, stderr বা অন্যথায় অন্য বিবরণ।

JSON প্রতিনিধিত্ব
{
  "outcome": enum (Outcome),
  "output": string
}

ফলাফল

কোড সম্পাদনের সম্ভাব্য ফলাফলের গণনা।

Enums
OUTCOME_UNSPECIFIED অনির্দিষ্ট অবস্থা। এই মান ব্যবহার করা উচিত নয়.
OUTCOME_OK কোড এক্সিকিউশন সফলভাবে সম্পন্ন হয়েছে।
OUTCOME_FAILED কোড এক্সিকিউশন শেষ হয়েছে কিন্তু ব্যর্থতার সাথে। stderr কারণ থাকতে হবে।
OUTCOME_DEADLINE_EXCEEDED কোড এক্সিকিউশন খুব বেশি সময় ধরে চলেছিল এবং বাতিল করা হয়েছিল৷ আংশিক আউটপুট উপস্থিত থাকতে পারে বা নাও থাকতে পারে।

টুল

টুলের বিবরণ যা মডেল প্রতিক্রিয়া তৈরি করতে ব্যবহার করতে পারে।

একটি Tool হল কোডের একটি অংশ যা মডেলের জ্ঞান এবং সুযোগের বাইরে একটি ক্রিয়া সম্পাদন করতে বা ক্রিয়াগুলির সেট করার জন্য সিস্টেমটিকে বহিরাগত সিস্টেমের সাথে যোগাযোগ করতে সক্ষম করে।

ক্ষেত্র
functionDeclarations[] object ( FunctionDeclaration )

ঐচ্ছিক। মডেলের কাছে উপলব্ধ FunctionDeclarations একটি তালিকা যা ফাংশন কলিংয়ের জন্য ব্যবহার করা যেতে পারে।

মডেল বা সিস্টেম ফাংশন চালায় না। পরিবর্তে সংজ্ঞায়িত ফাংশন কার্যকর করার জন্য ক্লায়েন্ট পক্ষের আর্গুমেন্ট সহ একটি FunctionCall হিসাবে ফেরত দেওয়া হতে পারে। মডেলটি প্রতিক্রিয়াতে FunctionCall পপুলেট করে এই ফাংশনগুলির একটি উপসেট কল করার সিদ্ধান্ত নিতে পারে। পরবর্তী কথোপকথনের পালাটিতে পরবর্তী মডেল টার্নের জন্য Content.role "ফাংশন" প্রজন্মের প্রসঙ্গ সহ একটি FunctionResponse থাকতে পারে।

googleSearchRetrieval object ( GoogleSearchRetrieval )

ঐচ্ছিক। পুনরুদ্ধার সরঞ্জাম যা Google অনুসন্ধান দ্বারা চালিত হয়।

codeExecution object ( CodeExecution )

ঐচ্ছিক। প্রজন্মের অংশ হিসাবে কোড চালানোর জন্য মডেলকে সক্ষম করে।

JSON প্রতিনিধিত্ব
{
  "functionDeclarations": [
    {
      object (FunctionDeclaration)
    }
  ],
  "googleSearchRetrieval": {
    object (GoogleSearchRetrieval)
  },
  "codeExecution": {
    object (CodeExecution)
  },
  "googleSearch": {
    object (GoogleSearch)
  }
}

ফাংশন ঘোষণা

OpenAPI 3.03 স্পেসিফিকেশন দ্বারা সংজ্ঞায়িত একটি ফাংশন ঘোষণার কাঠামোগত উপস্থাপনা। এই ঘোষণার মধ্যে ফাংশনের নাম এবং পরামিতি অন্তর্ভুক্ত রয়েছে। এই ফাংশন ডিক্লারেশন হল কোডের একটি ব্লকের একটি উপস্থাপনা যা মডেল দ্বারা একটি Tool হিসাবে ব্যবহার করা যেতে পারে এবং ক্লায়েন্ট দ্বারা কার্যকর করা যেতে পারে।

ক্ষেত্র
name string

প্রয়োজন। ফাংশনের নাম। az, AZ, 0-9 হতে হবে অথবা আন্ডারস্কোর এবং ড্যাশ থাকতে হবে, যার সর্বোচ্চ দৈর্ঘ্য 63।

description string

প্রয়োজন। ফাংশন একটি সংক্ষিপ্ত বিবরণ.

parameters object ( Schema )

ঐচ্ছিক। এই ফাংশনের পরামিতি বর্ণনা করে। Open API 3.03 প্যারামিটার অবজেক্ট স্ট্রিং কী প্রতিফলিত করে: প্যারামিটারের নাম। প্যারামিটারের নামগুলি কেস সংবেদনশীল৷ স্কিমা মান: প্যারামিটারের জন্য ব্যবহৃত টাইপ সংজ্ঞায়িত করে।

response object ( Schema )

ঐচ্ছিক। JSON স্কিমা বিন্যাসে এই ফাংশন থেকে আউটপুট বর্ণনা করে। Open API 3.03 রেসপন্স অবজেক্ট প্রতিফলিত করে। স্কিমা ফাংশনের প্রতিক্রিয়া মানের জন্য ব্যবহৃত প্রকারকে সংজ্ঞায়িত করে।

JSON প্রতিনিধিত্ব
{
  "name": string,
  "description": string,
  "parameters": {
    object (Schema)
  },
  "response": {
    object (Schema)
  }
}

স্কিমা

Schema অবজেক্ট ইনপুট এবং আউটপুট ডেটা প্রকারের সংজ্ঞা অনুমোদন করে। এই ধরনের বস্তু হতে পারে, কিন্তু আদিম এবং অ্যারেও হতে পারে। একটি OpenAPI 3.0 স্কিমা অবজেক্টের একটি নির্বাচিত উপসেট প্রতিনিধিত্ব করে।

ক্ষেত্র
type enum ( Type )

প্রয়োজন। ডেটা টাইপ।

format string

ঐচ্ছিক। তথ্য বিন্যাস. এটি শুধুমাত্র আদিম ডেটাটাইপের জন্য ব্যবহৃত হয়। সমর্থিত ফর্ম্যাট: NUMBER প্রকারের জন্য: ফ্লোট, INTEGEER প্রকারের জন্য দ্বিগুণ: int32, STRING প্রকারের জন্য int64: enum, তারিখ-সময়

title string

ঐচ্ছিক। স্কিমার শিরোনাম।

description string

ঐচ্ছিক। পরামিতি একটি সংক্ষিপ্ত বিবরণ. এটি ব্যবহারের উদাহরণ থাকতে পারে। প্যারামিটারের বিবরণ মার্কডাউন হিসাবে ফর্ম্যাট করা যেতে পারে।

nullable boolean

ঐচ্ছিক। মান শূন্য হতে পারে কিনা তা নির্দেশ করে।

enum[] string

ঐচ্ছিক। Enum বিন্যাস সহ Type.STRING এর উপাদানের সম্ভাব্য মান। উদাহরণ স্বরূপ আমরা একটি Enum দিক নির্দেশ করতে পারি: {type:STRING, format:enum, enum:["East", NORTH", "SOUTH", "WEST"]}

maxItems string ( int64 format)

ঐচ্ছিক। Type.ARRAY-এর জন্য উপাদানের সর্বাধিক সংখ্যা।

minItems string ( int64 format)

ঐচ্ছিক। Type.ARRAY-এর জন্য উপাদানের ন্যূনতম সংখ্যা।

properties map (key: string, value: object ( Schema ))

ঐচ্ছিক। প্রকারের বৈশিষ্ট্য।OBJECT।

"key": value জোড়া। উদাহরণ: { "name": "wrench", "mass": "1.3kg", "count": "3" }

required[] string

ঐচ্ছিক। Type.OBJECT এর প্রয়োজনীয় বৈশিষ্ট্য।

minProperties string ( int64 format)

ঐচ্ছিক। Type.OBJECT-এর জন্য বৈশিষ্ট্যের ন্যূনতম সংখ্যা।

maxProperties string ( int64 format)

ঐচ্ছিক। Type.OBJECT-এর জন্য সর্বাধিক সংখ্যা।

minLength string ( int64 format)

ঐচ্ছিক। টাইপ স্ট্রিং এর জন্য স্কিমা ফিল্ড টাইপ.STRING এর ন্যূনতম দৈর্ঘ্য

maxLength string ( int64 format)

ঐচ্ছিক। প্রকারের সর্বোচ্চ দৈর্ঘ্য।STRING

pattern string

ঐচ্ছিক। একটি রেগুলার এক্সপ্রেশনে একটি স্ট্রিংকে সীমাবদ্ধ করতে Type.STRING এর প্যাটার্ন।

example value ( Value format)

ঐচ্ছিক। বস্তুর উদাহরণ। বস্তুটি মূল হলেই কেবল পপুলেট হবে।

anyOf[] object ( Schema )

ঐচ্ছিক। তালিকার যেকোনও (এক বা একাধিক) সাবস্কেমার বিরুদ্ধে মানটি যাচাই করা উচিত।

propertyOrdering[] string

ঐচ্ছিক। সম্পত্তির ক্রম। ওপেন এপিআই স্পেকের একটি আদর্শ ক্ষেত্র নয়। প্রতিক্রিয়ায় বৈশিষ্ট্যের ক্রম নির্ধারণ করতে ব্যবহৃত হয়।

default value ( Value format)

ঐচ্ছিক। ক্ষেত্রের ডিফল্ট মান। JSON স্কিমা অনুসারে, এই ক্ষেত্রটি ডকুমেন্টেশন জেনারেটরের জন্য তৈরি এবং বৈধতাকে প্রভাবিত করে না। এইভাবে এটি এখানে অন্তর্ভুক্ত করা হয়েছে এবং উপেক্ষা করা হয়েছে যাতে বিকাশকারীরা যারা একটি default ক্ষেত্রের সাথে স্কিমা পাঠায় তারা অজানা-ক্ষেত্র ত্রুটি না পায়।

items object ( Schema )

ঐচ্ছিক। Type.ARRAY এর উপাদানগুলির স্কিমা।

minimum number

ঐচ্ছিক। Type.INTEGER এবং Type.NUMBER-এর সর্বনিম্ন মানের টাইপ পূর্ণসংখ্যা এবং NUMBER এর জন্য স্কিমা ক্ষেত্র

maximum number

ঐচ্ছিক। Type.INTEGER এবং Type.NUMBER-এর সর্বোচ্চ মান

JSON প্রতিনিধিত্ব
{
  "type": enum (Type),
  "format": string,
  "title": string,
  "description": string,
  "nullable": boolean,
  "enum": [
    string
  ],
  "maxItems": string,
  "minItems": string,
  "properties": {
    string: {
      object (Schema)
    },
    ...
  },
  "required": [
    string
  ],
  "minProperties": string,
  "maxProperties": string,
  "minLength": string,
  "maxLength": string,
  "pattern": string,
  "example": value,
  "anyOf": [
    {
      object (Schema)
    }
  ],
  "propertyOrdering": [
    string
  ],
  "default": value,
  "items": {
    object (Schema)
  },
  "minimum": number,
  "maximum": number
}

টাইপ

টাইপে https://spec.openapis.org/oas/v3.0.3#data-types দ্বারা সংজ্ঞায়িত OpenAPI ডেটা প্রকারের তালিকা রয়েছে

Enums
TYPE_UNSPECIFIED নির্দিষ্ট করা নেই, ব্যবহার করা উচিত নয়।
STRING স্ট্রিং টাইপ।
NUMBER সংখ্যার ধরন।
INTEGER পূর্ণসংখ্যার ধরন।
BOOLEAN বুলিয়ান টাইপ।
ARRAY অ্যারে টাইপ।
OBJECT বস্তুর ধরন।
NULL নাল টাইপ।

GoogleSearch Retrieval

গ্রাউন্ডিংয়ের জন্য সর্বজনীন ওয়েব ডেটা পুনরুদ্ধার করার টুল, Google দ্বারা চালিত।

ক্ষেত্র
dynamicRetrievalConfig object ( DynamicRetrievalConfig )

প্রদত্ত উত্সের জন্য গতিশীল পুনরুদ্ধার কনফিগারেশন নির্দিষ্ট করে।

JSON প্রতিনিধিত্ব
{
  "dynamicRetrievalConfig": {
    object (DynamicRetrievalConfig)
  }
}

DynamicRetrievalConfig

গতিশীল পুনরুদ্ধার কাস্টমাইজ করার বিকল্পগুলি বর্ণনা করে।

ক্ষেত্র
mode enum ( Mode )

গতিশীল পুনরুদ্ধারের জন্য ভবিষ্যদ্বাণীকারীর মোড ব্যবহার করা হবে।

dynamicThreshold number

গতিশীল পুনরুদ্ধারের জন্য থ্রেশহোল্ড ব্যবহার করা হবে। যদি সেট না করা হয়, একটি সিস্টেম ডিফল্ট মান ব্যবহার করা হয়।

JSON প্রতিনিধিত্ব
{
  "mode": enum (Mode),
  "dynamicThreshold": number
}

মোড

গতিশীল পুনরুদ্ধারের জন্য ভবিষ্যদ্বাণীকারীর মোড ব্যবহার করা হবে।

Enums
MODE_UNSPECIFIED সর্বদা পুনরুদ্ধার ট্রিগার.
MODE_DYNAMIC সিস্টেম যখন সিদ্ধান্ত নেয় তখনই পুনরুদ্ধার চালান এটি প্রয়োজনীয়।

কোড এক্সিকিউশন

এই ধরনের কোন ক্ষেত্র আছে.

টুল যেটি মডেল দ্বারা জেনারেট করা কোড এক্সিকিউট করে এবং স্বয়ংক্রিয়ভাবে মডেলে ফলাফল ফেরত দেয়।

এছাড়াও ExecutableCode এবং CodeExecutionResult দেখুন যা শুধুমাত্র এই টুল ব্যবহার করার সময় তৈরি হয়।

গুগল সার্চ

এই ধরনের কোন ক্ষেত্র আছে.

গুগল সার্চ টুল টাইপ। মডেলে Google অনুসন্ধান সমর্থন করার টুল। গুগল দ্বারা চালিত.

টুল কনফিগারেশন

অনুরোধে Tool ব্যবহার নির্দিষ্ট করার জন্য পরামিতি ধারণকারী টুল কনফিগারেশন।

ক্ষেত্র
functionCallingConfig object ( FunctionCallingConfig )

ঐচ্ছিক। ফাংশন কলিং কনফিগারেশন।

JSON প্রতিনিধিত্ব
{
  "functionCallingConfig": {
    object (FunctionCallingConfig)
  }
}

FunctionCallingConfig

ফাংশন কলিং আচরণ নির্দিষ্ট করার জন্য কনফিগারেশন।

ক্ষেত্র
mode enum ( Mode )

ঐচ্ছিক। যে মোডে ফাংশন কলিং চালানো উচিত তা নির্দিষ্ট করে। অনির্দিষ্ট থাকলে, ডিফল্ট মানটি অটোতে সেট করা হবে।

allowedFunctionNames[] string

ঐচ্ছিক। ফাংশনের নামের একটি সেট যা প্রদান করা হলে, মডেলটি যে ফাংশনগুলিকে কল করবে তা সীমিত করে।

এটি শুধুমাত্র তখনই সেট করা উচিত যখন মোড যেকোনো হয়। ফাংশনের নামগুলি [FunctionDeclaration.name] মেলে। মোড যেকোনও সেট করে, মডেল প্রদত্ত ফাংশন নামের সেট থেকে একটি ফাংশন কলের পূর্বাভাস দেবে।

JSON প্রতিনিধিত্ব
{
  "mode": enum (Mode),
  "allowedFunctionNames": [
    string
  ]
}

মোড

এক্সিকিউশন মোড সংজ্ঞায়িত করে ফাংশন কলিংয়ের জন্য নির্বাহ আচরণ সংজ্ঞায়িত করে।

Enums
MODE_UNSPECIFIED অনির্দিষ্ট ফাংশন কলিং মোড। এই মান ব্যবহার করা উচিত নয়.
AUTO ডিফল্ট মডেল আচরণ, মডেল একটি ফাংশন কল বা একটি প্রাকৃতিক ভাষা প্রতিক্রিয়া ভবিষ্যদ্বাণী করার সিদ্ধান্ত নেয়।
ANY মডেল সবসময় শুধুমাত্র একটি ফাংশন কল ভবিষ্যদ্বাণী করতে সীমাবদ্ধ। যদি "allowedFunctionNames" সেট করা থাকে, তাহলে ভবিষ্যদ্বাণীকৃত ফাংশন কলটি "allowedFunctionNames" এর যেকোনো একটিতে সীমাবদ্ধ থাকবে, অন্যথায় পূর্বাভাসিত ফাংশন কলটি প্রদত্ত "ফাংশন ঘোষণা" এর যেকোনো একটি হবে।
NONE মডেল কোনো ফাংশন কল ভবিষ্যদ্বাণী করবে না. মডেল আচরণ কোন ফাংশন ঘোষণা পাস না যখন একই.
VALIDATED মডেল হয় একটি ফাংশন কল বা একটি প্রাকৃতিক ভাষা প্রতিক্রিয়া ভবিষ্যদ্বাণী করার সিদ্ধান্ত নেয়, তবে সীমাবদ্ধ ডিকোডিং সহ ফাংশন কলগুলিকে যাচাই করবে৷

মেটাডেটা ব্যবহার

ক্যাশে করা বিষয়বস্তুর ব্যবহারের উপর মেটাডেটা।

ক্ষেত্র
totalTokenCount integer

ক্যাশ করা সামগ্রী ব্যবহার করে মোট টোকেনের সংখ্যা৷

JSON প্রতিনিধিত্ব
{
  "totalTokenCount": integer
}
,

কনটেক্সট ক্যাশিং আপনাকে প্রাক-কম্পিউটেড ইনপুট টোকেনগুলি সংরক্ষণ এবং পুনঃব্যবহারের অনুমতি দেয় যা আপনি বারবার ব্যবহার করতে চান, উদাহরণস্বরূপ একই মিডিয়া ফাইল সম্পর্কে বিভিন্ন প্রশ্ন জিজ্ঞাসা করার সময়। এটি ব্যবহারের উপর নির্ভর করে খরচ এবং গতি সঞ্চয় করতে পারে। বিস্তারিত ভূমিকার জন্য, প্রসঙ্গ ক্যাশিং গাইড দেখুন।

পদ্ধতি: cachedContents.create

ক্যাশেড কনটেন্ট রিসোর্স তৈরি করে।

শেষবিন্দু

পোস্ট https: / /generativelanguage.googleapis.com /v1beta /cachedContents

শরীরের অনুরোধ

অনুরোধের মূল অংশে CachedContent একটি উদাহরণ রয়েছে।

ক্ষেত্র
contents[] object ( Content )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। বিষয়বস্তু ক্যাশে.

tools[] object ( Tool )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। পরবর্তী প্রতিক্রিয়া তৈরি করতে মডেলটি ব্যবহার করতে পারে Tools একটি তালিকা৷

expiration Union type
এই সম্পদের মেয়াদ কখন শেষ হবে তা নির্দিষ্ট করে। expiration নিম্নলিখিতগুলির মধ্যে একটি হতে পারে:
expireTime string ( Timestamp format)

UTC-এ টাইমস্ট্যাম্প যখন এই সংস্থানটির মেয়াদ শেষ বলে বিবেচিত হয়। ইনপুটে যা পাঠানো হয়েছে তা নির্বিশেষে এটি সর্বদা আউটপুটে সরবরাহ করা হয়।

RFC 3339 ব্যবহার করে, যেখানে উৎপন্ন আউটপুট সর্বদা Z-সাধারণ করা হবে এবং 0, 3, 6 বা 9 ভগ্নাংশ সংখ্যা ব্যবহার করে। "Z" ব্যতীত অন্যান্য অফসেটগুলিও গ্রহণ করা হয়। উদাহরণ: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" বা "2014-10-02T15:01:23+05:30"

ttl string ( Duration format)

শুধুমাত্র ইনপুট। এই সম্পদের জন্য নতুন TTL, শুধুমাত্র ইনপুট।

নয়টি পর্যন্ত ভগ্নাংশের সংখ্যা সহ সেকেন্ডে একটি সময়কাল, ' s ' দিয়ে শেষ হয়৷ উদাহরণ: "3.5s"

displayName string

ঐচ্ছিক। অপরিবর্তনীয়। ক্যাশ করা বিষয়বস্তুর ব্যবহারকারীর তৈরি অর্থপূর্ণ প্রদর্শন নাম। সর্বোচ্চ 128টি ইউনিকোড অক্ষর।

model string

প্রয়োজন। অপরিবর্তনীয়। ক্যাশে কন্টেন্ট ফরম্যাটের জন্য ব্যবহার করা Model নাম: models/{model}

systemInstruction object ( Content )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। বিকাশকারী সেট সিস্টেম নির্দেশ. বর্তমানে শুধুমাত্র টেক্সট.

toolConfig object ( ToolConfig )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। টুল কনফিগারেশন। এই কনফিগারেশনটি সকল টুলের জন্য শেয়ার করা হয়েছে।

উদাহরণ অনুরোধ

from google import genai
from google.genai import types

client = genai.Client()
document = client.files.upload(file=media / "a11.txt")
model_name = "gemini-1.5-flash-001"

cache = client.caches.create(
    model=model_name,
    config=types.CreateCachedContentConfig(
        contents=[document],
        system_instruction="You are an expert analyzing transcripts.",
    ),
)
print(cache)

response = client.models.generate_content(
    model=model_name,
    contents="Please summarize this transcript",
    config=types.GenerateContentConfig(cached_content=cache.name),
)
print(response.text)
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);
const modelName = "gemini-1.5-flash-001";

const contents = [
  createUserContent(createPartFromUri(document.uri, document.mimeType)),
];

const cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: contents,
    systemInstruction: "You are an expert analyzing transcripts.",
  },
});
console.log("Cache created:", cache);

const response = await ai.models.generateContent({
  model: modelName,
  contents: "Please summarize this transcript",
  config: { cachedContent: cache.name },
});
console.log("Response text:", response.text);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"), 
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}
parts := []*genai.Part{
	genai.NewPartFromURI(document.URI, document.MIMEType),
}
contents := []*genai.Content{
	genai.NewContentFromParts(parts, "user"),
}
cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents: contents,
	SystemInstruction: genai.NewContentFromText(
		"You are an expert analyzing transcripts.", "user",
	),
})
if err != nil {
	log.Fatal(err)
}
fmt.Println("Cache created:")
fmt.Println(cache)

// Use the cache for generating content.
response, err := client.Models.GenerateContent(
	ctx,
	modelName,
	genai.Text("Please summarize this transcript"),
	&genai.GenerateContentConfig{
		CachedContent: cache.Name,
	},
)
if err != nil {
	log.Fatal(err)
}
printResponse(response)
wget https://storage.googleapis.com/generativeai-downloads/data/a11.txt
echo '{
  "model": "models/gemini-1.5-flash-001",
  "contents":[
    {
      "parts":[
        {
          "inline_data": {
            "mime_type":"text/plain",
            "data": "'$(base64 $B64FLAGS a11.txt)'"
          }
        }
      ],
    "role": "user"
    }
  ],
  "systemInstruction": {
    "parts": [
      {
        "text": "You are an expert at analyzing transcripts."
      }
    ]
  },
  "ttl": "300s"
}' > request.json

curl -X POST "https://generativelanguage.googleapis.com/v1beta/cachedContents?key=$GEMINI_API_KEY" \
 -H 'Content-Type: application/json' \
 -d @request.json \
 > cache.json

CACHE_NAME=$(cat cache.json | grep '"name":' | cut -d '"' -f 4 | head -n 1)

curl -X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-001:generateContent?key=$GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
      "contents": [
        {
          "parts":[{
            "text": "Please summarize this transcript"
          }],
          "role": "user"
        },
      ],
      "cachedContent": "'$CACHE_NAME'"
    }'
from google import genai
from google.genai import types

client = genai.Client()
document = client.files.upload(file=media / "a11.txt")
model_name = "gemini-1.5-flash-001"

cache = client.caches.create(
    model=model_name,
    config=types.CreateCachedContentConfig(
        contents=[document],
        system_instruction="You are an expert analyzing transcripts.",
    ),
)
cache_name = cache.name  # Save the name for later

# Later retrieve the cache
cache = client.caches.get(name=cache_name)
response = client.models.generate_content(
    model=model_name,
    contents="Find a lighthearted moment from this transcript",
    config=types.GenerateContentConfig(cached_content=cache.name),
)
print(response.text)
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);
const modelName = "gemini-1.5-flash-001";

const contents = [
  createUserContent(createPartFromUri(document.uri, document.mimeType)),
];

const cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: contents,
    systemInstruction: "You are an expert analyzing transcripts.",
  },
});
const cacheName = cache.name; // Save the name for later

// Later retrieve the cache
const retrievedCache = await ai.caches.get({ name: cacheName });
const response = await ai.models.generateContent({
  model: modelName,
  contents: "Find a lighthearted moment from this transcript",
  config: { cachedContent: retrievedCache.name },
});
console.log("Response text:", response.text);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"),
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}
parts := []*genai.Part{
	genai.NewPartFromURI(document.URI, document.MIMEType),
}
contents := []*genai.Content{
	genai.NewContentFromParts(parts, "user"),
}
cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents:          contents,
	SystemInstruction: genai.NewContentFromText(
		"You are an expert analyzing transcripts.", "user",
	),
})
if err != nil {
	log.Fatal(err)
}
cacheName := cache.Name

// Later retrieve the cache.
cache, err = client.Caches.Get(ctx, cacheName, &genai.GetCachedContentConfig{})
if err != nil {
	log.Fatal(err)
}

response, err := client.Models.GenerateContent(
	ctx,
	modelName,
	genai.Text("Find a lighthearted moment from this transcript"),
	&genai.GenerateContentConfig{
		CachedContent: cache.Name,
	},
)
if err != nil {
	log.Fatal(err)
}
fmt.Println("Response from cache (create from name):")
printResponse(response)
from google import genai
from google.genai import types

client = genai.Client()
model_name = "gemini-1.5-flash-001"
system_instruction = "You are an expert analyzing transcripts."

# Create a chat session with the given system instruction.
chat = client.chats.create(
    model=model_name,
    config=types.GenerateContentConfig(system_instruction=system_instruction),
)
document = client.files.upload(file=media / "a11.txt")

response = chat.send_message(
    message=["Hi, could you summarize this transcript?", document]
)
print("\n\nmodel:  ", response.text)
response = chat.send_message(
    message=["Okay, could you tell me more about the trans-lunar injection"]
)
print("\n\nmodel:  ", response.text)

# To cache the conversation so far, pass the chat history as the list of contents.
cache = client.caches.create(
    model=model_name,
    config={
        "contents": chat.get_history(),
        "system_instruction": system_instruction,
    },
)
# Continue the conversation using the cached content.
chat = client.chats.create(
    model=model_name,
    config=types.GenerateContentConfig(cached_content=cache.name),
)
response = chat.send_message(
    message="I didn't understand that last part, could you explain it in simpler language?"
)
print("\n\nmodel:  ", response.text)
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const modelName = "gemini-1.5-flash-001";
const systemInstruction = "You are an expert analyzing transcripts.";

// Create a chat session with the system instruction.
const chat = ai.chats.create({
  model: modelName,
  config: { systemInstruction: systemInstruction },
});
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);

let response = await chat.sendMessage({
  message: createUserContent([
    "Hi, could you summarize this transcript?",
    createPartFromUri(document.uri, document.mimeType),
  ]),
});
console.log("\n\nmodel:", response.text);

response = await chat.sendMessage({
  message: "Okay, could you tell me more about the trans-lunar injection",
});
console.log("\n\nmodel:", response.text);

// To cache the conversation so far, pass the chat history as the list of contents.
const chatHistory = chat.getHistory();
const cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: chatHistory,
    systemInstruction: systemInstruction,
  },
});

// Continue the conversation using the cached content.
const chatWithCache = ai.chats.create({
  model: modelName,
  config: { cachedContent: cache.name },
});
response = await chatWithCache.sendMessage({
  message:
    "I didn't understand that last part, could you explain it in simpler language?",
});
console.log("\n\nmodel:", response.text);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"),
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
systemInstruction := "You are an expert analyzing transcripts."

// Create initial chat with a system instruction.
chat, err := client.Chats.Create(ctx, modelName, &genai.GenerateContentConfig{
	SystemInstruction: genai.NewContentFromText(systemInstruction, "user"),
}, nil)
if err != nil {
	log.Fatal(err)
}

document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}

// Send first message with the transcript.
parts := make([]genai.Part, 2)
parts[0] = genai.Part{Text: "Hi, could you summarize this transcript?"}
parts[1] = genai.Part{
	FileData: &genai.FileData{
		FileURI :      document.URI,
		MIMEType: document.MIMEType,
	},
}

// Send chat message.
resp, err := chat.SendMessage(ctx, parts...)
if err != nil {
	log.Fatal(err)
}
fmt.Println("\n\nmodel: ", resp.Text())

resp, err = chat.SendMessage(
	ctx, 
	genai.Part{
		Text: "Okay, could you tell me more about the trans-lunar injection",
	},
)
if err != nil {
	log.Fatal(err)
}
fmt.Println("\n\nmodel: ", resp.Text())

// To cache the conversation so far, pass the chat history as the list of contents.
cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents:          chat.History(false),
	SystemInstruction: genai.NewContentFromText(systemInstruction, "user"),
})
if err != nil {
	log.Fatal(err)
}

// Continue the conversation using the cached history.
chat, err = client.Chats.Create(ctx, modelName, &genai.GenerateContentConfig{
	CachedContent: cache.Name,
}, nil)
if err != nil {
	log.Fatal(err)
}

resp, err = chat.SendMessage(
	ctx, 
	genai.Part{
		Text: "I didn't understand that last part, could you explain it in simpler language?",
	},
)
if err != nil {
	log.Fatal(err)
}
fmt.Println("\n\nmodel: ", resp.Text())

প্রতিক্রিয়া শরীর

সফল হলে, রেসপন্স বডিতে CachedContent একটি নতুন তৈরি ইনস্ট্যান্স থাকে।

পদ্ধতি: cachedContents.list

ক্যাশেড বিষয়বস্তু তালিকাভুক্ত করে।

শেষবিন্দু

https: / /generativelanguage.googleapis.com /v1beta /cachedContents পান

ক্যোয়ারী প্যারামিটার

pageSize integer

ঐচ্ছিক। ফেরত দেওয়ার জন্য ক্যাশ করা সামগ্রীর সর্বাধিক সংখ্যা৷ পরিষেবাটি এই মানের থেকে কম ফেরত দিতে পারে। অনির্দিষ্ট থাকলে, কিছু ডিফল্ট (সর্বোচ্চ অধীনে) আইটেম সংখ্যা ফেরত দেওয়া হবে। সর্বোচ্চ মান 1000; 1000-এর উপরে মান 1000-এ বাধ্য করা হবে।

pageToken string

ঐচ্ছিক। একটি পৃষ্ঠা টোকেন, একটি পূর্ববর্তী cachedContents.list কল থেকে প্রাপ্ত। পরবর্তী পৃষ্ঠাটি পুনরুদ্ধার করতে এটি প্রদান করুন।

পেজিনেট করার সময়, cachedContents.list এ প্রদত্ত অন্যান্য সমস্ত প্যারামিটার অবশ্যই পেজ টোকেন প্রদানকারী কলের সাথে মিলতে হবে।

শরীরের অনুরোধ

অনুরোধের বডি খালি হতে হবে।

প্রতিক্রিয়া শরীর

ক্যাশেড বিষয়বস্তু তালিকা সহ প্রতিক্রিয়া.

সফল হলে, প্রতিক্রিয়া বডিতে নিম্নলিখিত কাঠামোর সাথে ডেটা থাকে:

ক্ষেত্র
cachedContents[] object ( CachedContent )

ক্যাশ করা বিষয়বস্তুর তালিকা।

nextPageToken string

একটি টোকেন, যা পরবর্তী পৃষ্ঠা পুনরুদ্ধার করতে pageToken হিসাবে পাঠানো যেতে পারে। যদি এই ক্ষেত্রটি বাদ দেওয়া হয়, তাহলে পরবর্তী পৃষ্ঠা থাকবে না।

JSON প্রতিনিধিত্ব
{
  "cachedContents": [
    {
      object (CachedContent)
    }
  ],
  "nextPageToken": string
}

পদ্ধতি: cachedContents.get

ক্যাশেড কনটেন্ট রিসোর্স পড়ে।

শেষবিন্দু

https: / /generativelanguage.googleapis.com /v1beta /{name=cachedContents /*} পান

পাথ প্যারামিটার

name string

প্রয়োজন। বিষয়বস্তু ক্যাশে এন্ট্রি উল্লেখ করে সম্পদ নাম. বিন্যাস: cachedContents/{id} এটি cachedContents/{cachedcontent} ফর্ম নেয়।

শরীরের অনুরোধ

অনুরোধের বডি খালি হতে হবে।

উদাহরণ অনুরোধ

from google import genai

client = genai.Client()
document = client.files.upload(file=media / "a11.txt")
model_name = "gemini-1.5-flash-001"

cache = client.caches.create(
    model=model_name,
    config={
        "contents": [document],
        "system_instruction": "You are an expert analyzing transcripts.",
    },
)
print(client.caches.get(name=cache.name))
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);
const modelName = "gemini-1.5-flash-001";

const contents = [
  createUserContent(createPartFromUri(document.uri, document.mimeType)),
];

const cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: contents,
    systemInstruction: "You are an expert analyzing transcripts.",
  },
});
const retrievedCache = await ai.caches.get({ name: cache.name });
console.log("Retrieved Cache:", retrievedCache);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"),
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}
parts := []*genai.Part{
	genai.NewPartFromURI(document.URI, document.MIMEType),
}
contents := []*genai.Content{
	genai.NewContentFromParts(parts, "user"),
}

cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents:          contents,
	SystemInstruction: genai.NewContentFromText(
		"You are an expert analyzing transcripts.", "user",
	),
})
if err != nil {
	log.Fatal(err)
}

cache, err = client.Caches.Get(ctx, cache.Name, &genai.GetCachedContentConfig{})
if err != nil {
	log.Fatal(err)
}
fmt.Println("Retrieved cache:")
fmt.Println(cache)
curl "https://generativelanguage.googleapis.com/v1beta/$CACHE_NAME?key=$GEMINI_API_KEY"

প্রতিক্রিয়া শরীর

সফল হলে, প্রতিক্রিয়া বডিতে CachedContent একটি উদাহরণ থাকে।

পদ্ধতি: cachedContents.patch

ক্যাশেড কনটেন্ট রিসোর্স আপডেট করে (কেবলমাত্র মেয়াদ শেষ হওয়া আপডেটযোগ্য)।

শেষবিন্দু

প্যাচ https: / /generativelanguage.googleapis.com /v1beta /{cachedContent.name=cachedContents /*}
PATCH https://generativelanguage.googleapis.com/v1beta/{cachedContent.name=cachedContents/*}

পাথ প্যারামিটার

cachedContent.name string

শুধুমাত্র আউটপুট। শনাক্তকারী। সম্পদের নাম ক্যাশে করা বিষয়বস্তু উল্লেখ করে। বিন্যাস: cachedContents/{id} এটি cachedContents/{cachedcontent} ফর্ম নেয়।

ক্যোয়ারী প্যারামিটার

updateMask string ( FieldMask format)

আপডেট করার জন্য ক্ষেত্রগুলির তালিকা৷

এটি ক্ষেত্রগুলির সম্পূর্ণরূপে যোগ্য নামের একটি কমা দ্বারা পৃথক করা তালিকা৷ উদাহরণ: "user.displayName,photo"

শরীরের অনুরোধ

অনুরোধের মূল অংশে CachedContent একটি উদাহরণ রয়েছে।

ক্ষেত্র
expiration Union type
এই সম্পদের মেয়াদ কখন শেষ হবে তা নির্দিষ্ট করে। expiration নিম্নলিখিতগুলির মধ্যে একটি হতে পারে:
expireTime string ( Timestamp format)

UTC-এ টাইমস্ট্যাম্প যখন এই সংস্থানটির মেয়াদ শেষ বলে বিবেচিত হয়। ইনপুটে যা পাঠানো হয়েছে তা নির্বিশেষে এটি সর্বদা আউটপুটে সরবরাহ করা হয়।

RFC 3339 ব্যবহার করে, যেখানে উৎপন্ন আউটপুট সর্বদা Z-সাধারণ করা হবে এবং 0, 3, 6 বা 9 ভগ্নাংশ সংখ্যা ব্যবহার করে। "Z" ব্যতীত অন্যান্য অফসেটগুলিও গ্রহণ করা হয়। উদাহরণ: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" বা "2014-10-02T15:01:23+05:30"

ttl string ( Duration format)

শুধুমাত্র ইনপুট। এই সম্পদের জন্য নতুন TTL, শুধুমাত্র ইনপুট।

নয়টি পর্যন্ত ভগ্নাংশের সংখ্যা সহ সেকেন্ডে একটি সময়কাল, ' s ' দিয়ে শেষ হয়৷ উদাহরণ: "3.5s"

উদাহরণ অনুরোধ

from google import genai
from google.genai import types
import datetime

client = genai.Client()
document = client.files.upload(file=media / "a11.txt")
model_name = "gemini-1.5-flash-001"

cache = client.caches.create(
    model=model_name,
    config={
        "contents": [document],
        "system_instruction": "You are an expert analyzing transcripts.",
    },
)

# Update the cache's time-to-live (ttl)
ttl = f"{int(datetime.timedelta(hours=2).total_seconds())}s"
client.caches.update(
    name=cache.name, config=types.UpdateCachedContentConfig(ttl=ttl)
)
print(f"After update:\n {cache}")

# Alternatively, update the expire_time directly
# Update the expire_time directly in valid RFC 3339 format (UTC with a "Z" suffix)
expire_time = (
    (
        datetime.datetime.now(datetime.timezone.utc)
        + datetime.timedelta(minutes=15)
    )
    .isoformat()
    .replace("+00:00", "Z")
)
client.caches.update(
    name=cache.name,
    config=types.UpdateCachedContentConfig(expire_time=expire_time),
)
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);
const modelName = "gemini-1.5-flash-001";

const contents = [
  createUserContent(createPartFromUri(document.uri, document.mimeType)),
];

let cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: contents,
    systemInstruction: "You are an expert analyzing transcripts.",
  },
});

// Update the cache's time-to-live (ttl)
const ttl = `${2 * 3600}s`; // 2 hours in seconds
cache = await ai.caches.update({
  name: cache.name,
  config: { ttl },
});
console.log("After update (TTL):", cache);

// Alternatively, update the expire_time directly (in RFC 3339 format with a "Z" suffix)
const expireTime = new Date(Date.now() + 15 * 60000)
  .toISOString()
  .replace(/\.\d{3}Z$/, "Z");
cache = await ai.caches.update({
  name: cache.name,
  config: { expireTime: expireTime },
});
console.log("After update (expire_time):", cache);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"),
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}
parts := []*genai.Part{
	genai.NewPartFromURI(document.URI, document.MIMEType),
}
contents := []*genai.Content{
	genai.NewContentFromParts(parts, "user"),
}

cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents:          contents,
	SystemInstruction: genai.NewContentFromText(
		"You are an expert analyzing transcripts.", "user",
	),
})
if err != nil {
	log.Fatal(err)
}

_, err = client.Caches.Delete(ctx, cache.Name, &genai.DeleteCachedContentConfig{})
if err != nil {
	log.Fatal(err)
}
fmt.Println("Cache deleted:", cache.Name)
curl -X PATCH "https://generativelanguage.googleapis.com/v1beta/$CACHE_NAME?key=$GEMINI_API_KEY" \
 -H 'Content-Type: application/json' \
 -d '{"ttl": "600s"}'

প্রতিক্রিয়া শরীর

সফল হলে, প্রতিক্রিয়া বডিতে CachedContent একটি উদাহরণ থাকে।

পদ্ধতি: cachedContents.delete

ক্যাশেড কনটেন্ট রিসোর্স মুছে দেয়।

শেষবিন্দু

https: / /generativelanguage.googleapis.com /v1beta /{name=cachedContents /*} মুছুন

পাথ প্যারামিটার

name string

প্রয়োজন। বিষয়বস্তু ক্যাশে এন্ট্রি ফর্ম্যাট উল্লেখ করে সম্পদ নাম: cachedContents/{id} এটি cachedContents/{cachedcontent} ফর্ম নেয়।

শরীরের অনুরোধ

অনুরোধের বডি খালি হতে হবে।

উদাহরণ অনুরোধ

from google import genai

client = genai.Client()
document = client.files.upload(file=media / "a11.txt")
model_name = "gemini-1.5-flash-001"

cache = client.caches.create(
    model=model_name,
    config={
        "contents": [document],
        "system_instruction": "You are an expert analyzing transcripts.",
    },
)
client.caches.delete(name=cache.name)
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);
const modelName = "gemini-1.5-flash-001";

const contents = [
  createUserContent(createPartFromUri(document.uri, document.mimeType)),
];

const cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: contents,
    systemInstruction: "You are an expert analyzing transcripts.",
  },
});
await ai.caches.delete({ name: cache.name });
console.log("Cache deleted:", cache.name);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"),
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}
parts := []*genai.Part{
	genai.NewPartFromURI(document.URI, document.MIMEType),
}
contents := []*genai.Content{
	genai.NewContentFromParts(parts, "user"),
}

cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents:          contents,
	SystemInstruction: genai.NewContentFromText(
		"You are an expert analyzing transcripts.", "user",
	),
})
if err != nil {
	log.Fatal(err)
}

_, err = client.Caches.Delete(ctx, cache.Name, &genai.DeleteCachedContentConfig{})
if err != nil {
	log.Fatal(err)
}
fmt.Println("Cache deleted:", cache.Name)
curl -X DELETE "https://generativelanguage.googleapis.com/v1beta/$CACHE_NAME?key=$GEMINI_API_KEY"

প্রতিক্রিয়া শরীর

সফল হলে, প্রতিক্রিয়া বডি একটি খালি JSON অবজেক্ট।

REST সম্পদ: ক্যাশেড বিষয়বস্তু

সম্পদ: ক্যাশেড সামগ্রী

বিষয়বস্তু যা প্রি-প্রসেস করা হয়েছে এবং পরবর্তীতে GenerativeService-এর অনুরোধে ব্যবহার করা যেতে পারে।

ক্যাশে করা সামগ্রী শুধুমাত্র সেই মডেলের সাথে ব্যবহার করা যেতে পারে যার জন্য এটি তৈরি করা হয়েছিল৷

ক্ষেত্র
contents[] object ( Content )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। বিষয়বস্তু ক্যাশে.

tools[] object ( Tool )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। পরবর্তী প্রতিক্রিয়া তৈরি করতে মডেলটি ব্যবহার করতে পারে Tools একটি তালিকা৷

createTime string ( Timestamp format)

শুধুমাত্র আউটপুট। ক্যাশে এন্ট্রি তৈরির সময়।

RFC 3339 ব্যবহার করে, যেখানে উৎপন্ন আউটপুট সর্বদা Z-সাধারণ করা হবে এবং 0, 3, 6 বা 9 ভগ্নাংশ সংখ্যা ব্যবহার করে। "Z" ব্যতীত অন্যান্য অফসেটগুলিও গ্রহণ করা হয়। উদাহরণ: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" বা "2014-10-02T15:01:23+05:30"

updateTime string ( Timestamp format)

শুধুমাত্র আউটপুট। যখন ক্যাশে এন্ট্রি শেষবার UTC সময়ে আপডেট করা হয়েছিল।

RFC 3339 ব্যবহার করে, যেখানে উৎপন্ন আউটপুট সর্বদা Z-সাধারণ করা হবে এবং 0, 3, 6 বা 9 ভগ্নাংশ সংখ্যা ব্যবহার করে। "Z" ব্যতীত অন্যান্য অফসেটগুলিও গ্রহণ করা হয়। উদাহরণ: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" বা "2014-10-02T15:01:23+05:30"

usageMetadata object ( UsageMetadata )

শুধুমাত্র আউটপুট। ক্যাশে করা বিষয়বস্তুর ব্যবহারের উপর মেটাডেটা।

expiration Union type
এই সম্পদের মেয়াদ কখন শেষ হবে তা নির্দিষ্ট করে। expiration নিম্নলিখিতগুলির মধ্যে একটি হতে পারে:
expireTime string ( Timestamp format)

UTC-এ টাইমস্ট্যাম্প যখন এই সংস্থানটির মেয়াদ শেষ বলে বিবেচিত হয়। ইনপুটে যা পাঠানো হয়েছে তা নির্বিশেষে এটি সর্বদা আউটপুটে সরবরাহ করা হয়।

RFC 3339 ব্যবহার করে, যেখানে উৎপন্ন আউটপুট সর্বদা Z-সাধারণ করা হবে এবং 0, 3, 6 বা 9 ভগ্নাংশ সংখ্যা ব্যবহার করে। "Z" ব্যতীত অন্যান্য অফসেটগুলিও গ্রহণ করা হয়। উদাহরণ: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" বা "2014-10-02T15:01:23+05:30"

ttl string ( Duration format)

শুধুমাত্র ইনপুট। এই সম্পদের জন্য নতুন TTL, শুধুমাত্র ইনপুট।

নয়টি পর্যন্ত ভগ্নাংশের সংখ্যা সহ সেকেন্ডে একটি সময়কাল, ' s ' দিয়ে শেষ হয়৷ উদাহরণ: "3.5s"

name string

শুধুমাত্র আউটপুট। শনাক্তকারী। সম্পদের নাম ক্যাশে করা বিষয়বস্তু উল্লেখ করে। বিন্যাস: cachedContents/{id}

displayName string

ঐচ্ছিক। অপরিবর্তনীয়। ক্যাশ করা বিষয়বস্তুর ব্যবহারকারীর তৈরি অর্থপূর্ণ প্রদর্শন নাম। সর্বোচ্চ 128টি ইউনিকোড অক্ষর।

model string

প্রয়োজন। অপরিবর্তনীয়। ক্যাশে কন্টেন্ট ফরম্যাটের জন্য ব্যবহার করা Model নাম: models/{model}

systemInstruction object ( Content )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। বিকাশকারী সেট সিস্টেম নির্দেশ. বর্তমানে শুধুমাত্র টেক্সট.

toolConfig object ( ToolConfig )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। টুল কনফিগারেশন। এই কনফিগারেশনটি সকল টুলের জন্য শেয়ার করা হয়েছে।

JSON প্রতিনিধিত্ব
{
  "contents": [
    {
      object (Content)
    }
  ],
  "tools": [
    {
      object (Tool)
    }
  ],
  "createTime": string,
  "updateTime": string,
  "usageMetadata": {
    object (UsageMetadata)
  },

  // expiration
  "expireTime": string,
  "ttl": string
  // Union type
  "name": string,
  "displayName": string,
  "model": string,
  "systemInstruction": {
    object (Content)
  },
  "toolConfig": {
    object (ToolConfig)
  }
}

বিষয়বস্তু

একটি বার্তার বহু-অংশ বিষয়বস্তু ধারণকারী বেস স্ট্রাকচার্ড ডেটাটাইপ।

একটি Content মধ্যে একটি role ক্ষেত্র রয়েছে যা Content প্রযোজককে মনোনীত করে এবং একটি parts ক্ষেত্র যাতে বহু-অংশের ডেটা থাকে যাতে বার্তার বিষয়বস্তু থাকে।

ক্ষেত্র
parts[] object ( Part )

অর্ডার করা Parts যা একটি একক বার্তা গঠন করে। অংশের বিভিন্ন MIME প্রকার থাকতে পারে।

role string

ঐচ্ছিক। বিষয়বস্তুর প্রযোজক। 'ব্যবহারকারী' বা 'মডেল' হতে হবে।

মাল্টি-টার্ন কথোপকথনের জন্য সেট করার জন্য দরকারী, অন্যথায় ফাঁকা বা সেট না করা যেতে পারে।

JSON প্রতিনিধিত্ব
{
  "parts": [
    {
      object (Part)
    }
  ],
  "role": string
}

অংশ

মিডিয়া ধারণকারী একটি ডেটাটাইপ যা একটি বহু-অংশ Content বার্তার অংশ।

একটি Part ডেটা থাকে যার একটি সম্পর্কিত ডেটাটাইপ থাকে। একটি Part শুধুমাত্র Part.data তে গৃহীত প্রকারগুলির একটি ধারণ করতে পারে।

একটি Part অবশ্যই একটি নির্দিষ্ট IANA MIME টাইপ থাকতে হবে যা মিডিয়ার ধরন এবং উপপ্রকার সনাক্ত করে যদি inlineData ক্ষেত্র কাঁচা বাইট দিয়ে পূর্ণ হয়।

ক্ষেত্র
boolean thought

ঐচ্ছিক। অংশটি মডেল থেকে চিন্তা করা হলে নির্দেশ করে।

data Union type
data নিম্নলিখিতগুলির মধ্যে একটি হতে পারে:
text string

ইনলাইন পাঠ্য।

inlineData object ( Blob )

ইনলাইন মিডিয়া বাইট।

functionCall object ( FunctionCall )

একটি ভবিষ্যদ্বাণীকৃত FunctionCall মডেল থেকে ফিরে এসেছে যেটিতে একটি স্ট্রিং রয়েছে যা আর্গুমেন্ট এবং তাদের মান সহ FunctionDeclaration.name প্রতিনিধিত্ব করে।

functionResponse object ( FunctionResponse )

একটি FunctionCall এর ফলাফল আউটপুট যেটিতে FunctionDeclaration.name প্রতিনিধিত্বকারী একটি স্ট্রিং রয়েছে এবং ফাংশন থেকে যেকোনো আউটপুট ধারণকারী একটি কাঠামোগত JSON অবজেক্ট মডেলের প্রসঙ্গ হিসাবে ব্যবহৃত হয়।

fileData object ( FileData )

URI ভিত্তিক ডেটা।

executableCode object ( ExecutableCode )

মডেল দ্বারা উত্পন্ন কোড যা কার্যকর করা হবে।

codeExecutionResult object ( CodeExecutionResult )

ExecutableCode কার্যকর করার ফলাফল।

JSON প্রতিনিধিত্ব
{
  "thought": boolean,

  // data
  "text": string,
  "inlineData": {
    object (Blob)
  },
  "functionCall": {
    object (FunctionCall)
  },
  "functionResponse": {
    object (FunctionResponse)
  },
  "fileData": {
    object (FileData)
  },
  "executableCode": {
    object (ExecutableCode)
  },
  "codeExecutionResult": {
    object (CodeExecutionResult)
  }
  // Union type
}

ব্লব

কাঁচা মিডিয়া বাইট।

টেক্সট কাঁচা বাইট হিসাবে পাঠানো উচিত নয়, 'টেক্সট' ক্ষেত্র ব্যবহার করুন।

ক্ষেত্র
mimeType string

উৎস ডেটার IANA স্ট্যান্ডার্ড MIME প্রকার। উদাহরণ: - image/png - image/jpeg যদি একটি অসমর্থিত MIME প্রকার প্রদান করা হয়, একটি ত্রুটি ফেরত দেওয়া হবে। সমর্থিত প্রকারের একটি সম্পূর্ণ তালিকার জন্য, সমর্থিত ফাইল বিন্যাস দেখুন।

data string ( bytes format)

মিডিয়া ফরম্যাটের জন্য কাঁচা বাইট।

একটি base64-এনকোডেড স্ট্রিং।

JSON প্রতিনিধিত্ব
{
  "mimeType": string,
  "data": string
}

ফাংশনকল

একটি ভবিষ্যদ্বাণীকৃত FunctionCall মডেল থেকে ফিরে এসেছে যেটিতে একটি স্ট্রিং রয়েছে যা আর্গুমেন্ট এবং তাদের মান সহ FunctionDeclaration.name প্রতিনিধিত্ব করে।

ক্ষেত্র
id string

ঐচ্ছিক। ফাংশন কলের অনন্য আইডি। জনবহুল হলে, ক্লায়েন্ট functionCall চালাতে কল করবে এবং ম্যাচিং id সহ প্রতিক্রিয়া ফেরত দেবে।

name string

প্রয়োজন। কল করার ফাংশনের নাম। az, AZ, 0-9 হতে হবে অথবা আন্ডারস্কোর এবং ড্যাশ থাকতে হবে, যার সর্বোচ্চ দৈর্ঘ্য 63।

args object ( Struct format)

ঐচ্ছিক। JSON অবজেক্ট ফরম্যাটে ফাংশন প্যারামিটার এবং মান।

JSON প্রতিনিধিত্ব
{
  "id": string,
  "name": string,
  "args": {
    object
  }
}

ফাংশন রেসপন্স

একটি FunctionCall থেকে ফলাফল আউটপুট যেটিতে FunctionDeclaration.name প্রতিনিধিত্বকারী একটি স্ট্রিং রয়েছে এবং ফাংশন থেকে যেকোনো আউটপুট ধারণকারী একটি কাঠামোগত JSON অবজেক্ট মডেলের প্রসঙ্গ হিসাবে ব্যবহৃত হয়। এটিতে মডেল পূর্বাভাসের উপর ভিত্তি করে তৈরি একটি FunctionCall ফলাফল থাকা উচিত।

ক্ষেত্র
id string

ঐচ্ছিক। এই প্রতিক্রিয়া কল ফাংশন আইডি জন্য. সংশ্লিষ্ট ফাংশন কল id সাথে মেলে ক্লায়েন্ট দ্বারা জনবহুল।

name string

প্রয়োজন। কল করার ফাংশনের নাম। az, AZ, 0-9 হতে হবে অথবা আন্ডারস্কোর এবং ড্যাশ থাকতে হবে, যার সর্বোচ্চ দৈর্ঘ্য 63।

response object ( Struct format)

প্রয়োজন। JSON অবজেক্ট ফরম্যাটে ফাংশন প্রতিক্রিয়া।

JSON প্রতিনিধিত্ব
{
  "id": string,
  "name": string,
  "response": {
    object
  }
}

ফাইল ডেটা

URI ভিত্তিক ডেটা।

ক্ষেত্র
mimeType string

ঐচ্ছিক। উৎস ডেটার IANA স্ট্যান্ডার্ড MIME প্রকার।

fileUri string

প্রয়োজন। ইউআরআই।

JSON প্রতিনিধিত্ব
{
  "mimeType": string,
  "fileUri": string
}

এক্সিকিউটেবল কোড

কোড যে মডেলের দ্বারা উত্পন্ন হয় যা কার্যকর করা হয় এবং ফলাফলটি মডেলে ফিরে আসে।

শুধুমাত্র CodeExecution টুল ব্যবহার করার সময় তৈরি করা হয়, যেখানে কোডটি স্বয়ংক্রিয়ভাবে কার্যকর হবে এবং একটি সংশ্লিষ্ট CodeExecutionResult ও তৈরি হবে।

ক্ষেত্র
language enum ( Language )

প্রয়োজন। code প্রোগ্রামিং ভাষা।

code string

প্রয়োজন। কোডটি কার্যকর করতে হবে।

JSON প্রতিনিধিত্ব
{
  "language": enum (Language),
  "code": string
}

ভাষা

উত্পন্ন কোডের জন্য সমর্থিত প্রোগ্রামিং ভাষা।

Enums
LANGUAGE_UNSPECIFIED অনির্দিষ্ট ভাষা। এই মান ব্যবহার করা উচিত নয়.
PYTHON পাইথন >= 3.10, নম্পি এবং সিম্পি উপলব্ধ।

কোড এক্সিকিউশন ফলাফল

ExecutableCode কার্যকর করার ফলাফল।

শুধুমাত্র CodeExecution ব্যবহার করার সময় উৎপন্ন হয় এবং সর্বদা ExecutableCode ধারণকারী একটি part অনুসরণ করে।

ক্ষেত্র
outcome enum ( Outcome )

প্রয়োজন। কোড নির্বাহের ফলাফল।

output string

ঐচ্ছিক। কোড এক্সিকিউশন সফল হলে stdout ধারণ করে, stderr বা অন্যথায় অন্য বিবরণ।

JSON প্রতিনিধিত্ব
{
  "outcome": enum (Outcome),
  "output": string
}

ফলাফল

কোড সম্পাদনের সম্ভাব্য ফলাফলের গণনা।

Enums
OUTCOME_UNSPECIFIED অনির্দিষ্ট অবস্থা। এই মান ব্যবহার করা উচিত নয়.
OUTCOME_OK কোড এক্সিকিউশন সফলভাবে সম্পন্ন হয়েছে।
OUTCOME_FAILED কোড এক্সিকিউশন শেষ হয়েছে কিন্তু ব্যর্থতার সাথে। stderr কারণ থাকতে হবে।
OUTCOME_DEADLINE_EXCEEDED কোড এক্সিকিউশন খুব বেশি সময় ধরে চলেছিল এবং বাতিল করা হয়েছিল৷ আংশিক আউটপুট উপস্থিত থাকতে পারে বা নাও থাকতে পারে।

টুল

টুলের বিবরণ যা মডেল প্রতিক্রিয়া তৈরি করতে ব্যবহার করতে পারে।

একটি Tool হল কোডের একটি অংশ যা মডেলের জ্ঞান এবং সুযোগের বাইরে একটি ক্রিয়া সম্পাদন করতে বা ক্রিয়াগুলির সেট করার জন্য সিস্টেমটিকে বহিরাগত সিস্টেমের সাথে যোগাযোগ করতে সক্ষম করে।

ক্ষেত্র
functionDeclarations[] object ( FunctionDeclaration )

ঐচ্ছিক। মডেলের কাছে উপলব্ধ FunctionDeclarations একটি তালিকা যা ফাংশন কলিংয়ের জন্য ব্যবহার করা যেতে পারে।

মডেল বা সিস্টেম ফাংশন চালায় না। পরিবর্তে সংজ্ঞায়িত ফাংশন কার্যকর করার জন্য ক্লায়েন্ট পক্ষের আর্গুমেন্ট সহ একটি FunctionCall হিসাবে ফেরত দেওয়া হতে পারে। মডেলটি প্রতিক্রিয়াতে FunctionCall পপুলেট করে এই ফাংশনগুলির একটি উপসেট কল করার সিদ্ধান্ত নিতে পারে। পরবর্তী কথোপকথনের পালাটিতে পরবর্তী মডেল টার্নের জন্য Content.role "ফাংশন" প্রজন্মের প্রসঙ্গ সহ একটি FunctionResponse থাকতে পারে।

googleSearchRetrieval object ( GoogleSearchRetrieval )

ঐচ্ছিক। পুনরুদ্ধার সরঞ্জাম যা Google অনুসন্ধান দ্বারা চালিত হয়।

codeExecution object ( CodeExecution )

ঐচ্ছিক। প্রজন্মের অংশ হিসাবে কোড চালানোর জন্য মডেলকে সক্ষম করে।

JSON প্রতিনিধিত্ব
{
  "functionDeclarations": [
    {
      object (FunctionDeclaration)
    }
  ],
  "googleSearchRetrieval": {
    object (GoogleSearchRetrieval)
  },
  "codeExecution": {
    object (CodeExecution)
  },
  "googleSearch": {
    object (GoogleSearch)
  }
}

ফাংশন ঘোষণা

ওপেনএপিআই 3.03 স্পেসিফিকেশন দ্বারা সংজ্ঞায়িত হিসাবে একটি ফাংশন ঘোষণার কাঠামোগত উপস্থাপনা। এই ঘোষণায় অন্তর্ভুক্ত হ'ল ফাংশন নাম এবং পরামিতি। এই ফাংশনডেক্লারেশন হ'ল কোডের একটি ব্লকের প্রতিনিধিত্ব যা মডেল দ্বারা Tool হিসাবে ব্যবহার করা যেতে পারে এবং ক্লায়েন্ট দ্বারা সম্পাদিত হতে পারে।

ক্ষেত্র
name string

প্রয়োজন। ফাংশনের নাম। অবশ্যই এজেড, এজেড, 0-9 হতে হবে বা সর্বাধিক দৈর্ঘ্য 63 সহ আন্ডারস্কোর এবং ড্যাশ থাকতে পারে।

description string

প্রয়োজন। ফাংশন একটি সংক্ষিপ্ত বিবরণ।

parameters object ( Schema )

ঐচ্ছিক। এই ফাংশনের পরামিতিগুলি বর্ণনা করে। ওপেন এপিআই 3.03 প্যারামিটার অবজেক্ট স্ট্রিং কী প্রতিফলিত করে: প্যারামিটারের নাম। প্যারামিটারের নামগুলি কেস সংবেদনশীল৷ স্কিমা মান: স্কিমা প্যারামিটারের জন্য ব্যবহৃত প্রকারটি সংজ্ঞায়িত করে।

response object ( Schema )

ঐচ্ছিক। জেএসএন স্কিমা ফর্ম্যাটে এই ফাংশন থেকে আউটপুট বর্ণনা করে। ওপেন এপিআই 3.03 প্রতিক্রিয়া অবজেক্টটি প্রতিফলিত করে। স্কিমা ফাংশনের প্রতিক্রিয়া মানের জন্য ব্যবহৃত প্রকারটি সংজ্ঞায়িত করে।

JSON প্রতিনিধিত্ব
{
  "name": string,
  "description": string,
  "parameters": {
    object (Schema)
  },
  "response": {
    object (Schema)
  }
}

স্কিমা

Schema অবজেক্টটি ইনপুট এবং আউটপুট ডেটা প্রকারের সংজ্ঞা দেয়। এই ধরনের বস্তু হতে পারে, কিন্তু আদিম এবং অ্যারেও হতে পারে। একটি ওপেনাপি 3.0 স্কিমা অবজেক্টের একটি নির্বাচিত সাবসেট উপস্থাপন করে।

ক্ষেত্র
type enum ( Type )

প্রয়োজন। ডেটা টাইপ।

format string

ঐচ্ছিক। ডেটা ফর্ম্যাট। এটি কেবল আদিম ডেটাটাইপগুলির জন্য ব্যবহৃত হয়। সমর্থিত ফর্ম্যাটগুলি: সংখ্যার প্রকারের জন্য: ভাসমান, পূর্ণসংখ্যার জন্য ডাবল: আইএনটি 32, স্ট্রিং প্রকারের জন্য INT64: এনাম, তারিখ-সময়

title string

ঐচ্ছিক। স্কিমার শিরোনাম।

description string

ঐচ্ছিক। পরামিতি একটি সংক্ষিপ্ত বিবরণ. এটি ব্যবহারের উদাহরণ থাকতে পারে। প্যারামিটারের বিবরণ মার্কডাউন হিসাবে ফর্ম্যাট করা যেতে পারে।

nullable boolean

ঐচ্ছিক। মানটি বাতিল হতে পারে কিনা তা নির্দেশ করে।

enum[] string

ঐচ্ছিক। এনাম ফর্ম্যাট সহ প্রকারের উপাদানগুলির সম্ভাব্য মানগুলি। উদাহরণস্বরূপ আমরা একটি এনাম দিকনির্দেশ হিসাবে সংজ্ঞায়িত করতে পারি: {প্রকার: স্ট্রিং, ফর্ম্যাট: এনাম, এনাম: ["পূর্ব", উত্তর "," দক্ষিণ "," পশ্চিম "]}

maxItems string ( int64 format)

ঐচ্ছিক। টাইপ.আরাইয়ের জন্য উপাদানগুলির সর্বাধিক সংখ্যা।

minItems string ( int64 format)

ঐচ্ছিক। টাইপ.আরাইয়ের জন্য উপাদানগুলির সর্বনিম্ন সংখ্যা।

properties map (key: string, value: object ( Schema ))

ঐচ্ছিক। টাইপ.অবজেক্টের বৈশিষ্ট্য।

"key": value জোড়। উদাহরণ: { "name": "wrench", "mass": "1.3kg", "count": "3" }

required[] string

ঐচ্ছিক। টাইপ.অবজেক্টের প্রয়োজনীয় বৈশিষ্ট্য।

minProperties string ( int64 format)

ঐচ্ছিক। টাইপ.অবজেক্টের জন্য সম্পত্তিগুলির সর্বনিম্ন সংখ্যা।

maxProperties string ( int64 format)

ঐচ্ছিক। টাইপ.অবজেক্টের জন্য বৈশিষ্ট্যগুলির সর্বাধিক সংখ্যা।

minLength string ( int64 format)

ঐচ্ছিক। টাইপ স্ট্রিং এর জন্য স্কিমা ক্ষেত্রগুলি টাইপের ন্যূনতম দৈর্ঘ্য.স্ট্রিং

maxLength string ( int64 format)

ঐচ্ছিক। টাইপ.স্ট্রিংয়ের সর্বাধিক দৈর্ঘ্য

pattern string

ঐচ্ছিক। একটি স্ট্রিংকে নিয়মিত প্রকাশের মধ্যে সীমাবদ্ধ করতে টাইপের প্যাটার্ন।

example value ( Value format)

ঐচ্ছিক। বস্তুর উদাহরণ। কেবল তখনই পপুলেট হবে যখন বস্তুটি মূল হয়।

anyOf[] object ( Schema )

ঐচ্ছিক। তালিকার সাবমেমার যে কোনও (এক বা একাধিক) এর বিরুদ্ধে মানটি বৈধ করা উচিত।

propertyOrdering[] string

ঐচ্ছিক। সম্পত্তি অর্ডার। ওপেন এপিআই স্পেসে কোনও স্ট্যান্ডার্ড ক্ষেত্র নয়। প্রতিক্রিয়াতে বৈশিষ্ট্যগুলির ক্রম নির্ধারণ করতে ব্যবহৃত হয়।

default value ( Value format)

ঐচ্ছিক। ক্ষেত্রের ডিফল্ট মান। জেএসএন স্কিমা অনুযায়ী, এই ক্ষেত্রটি ডকুমেন্টেশন জেনারেটরগুলির জন্য তৈরি এবং বৈধতা প্রভাবিত করে না। সুতরাং এটি এখানে অন্তর্ভুক্ত রয়েছে এবং উপেক্ষা করা হয়েছে যাতে বিকাশকারীরা যারা default ক্ষেত্রের সাথে স্কিমা প্রেরণ করেন তারা অজানা-ক্ষেত্রের ত্রুটিগুলি পান না।

items object ( Schema )

ঐচ্ছিক। টাইপ.আরাইয়ের উপাদানগুলির স্কিমা।

minimum number

ঐচ্ছিক। টাইপ পূর্ণসংখ্যার জন্য স্কিমা ক্ষেত্রগুলি এবং প্রকারের ন্যূনতম মান এবং প্রকারের ন্যূনতম মান।

maximum number

ঐচ্ছিক। প্রকারের সর্বাধিক মান।

JSON প্রতিনিধিত্ব
{
  "type": enum (Type),
  "format": string,
  "title": string,
  "description": string,
  "nullable": boolean,
  "enum": [
    string
  ],
  "maxItems": string,
  "minItems": string,
  "properties": {
    string: {
      object (Schema)
    },
    ...
  },
  "required": [
    string
  ],
  "minProperties": string,
  "maxProperties": string,
  "minLength": string,
  "maxLength": string,
  "pattern": string,
  "example": value,
  "anyOf": [
    {
      object (Schema)
    }
  ],
  "propertyOrdering": [
    string
  ],
  "default": value,
  "items": {
    object (Schema)
  },
  "minimum": number,
  "maximum": number
}

টাইপ

টাইপটিতে https://spec.openapis.org/oas/v3.0.3#data- টাইপস দ্বারা সংজ্ঞায়িত ওপেনাপি ডেটা প্রকারের তালিকা রয়েছে

Enums
TYPE_UNSPECIFIED নির্দিষ্ট করা হয়নি, ব্যবহার করা উচিত নয়।
STRING স্ট্রিং টাইপ।
NUMBER সংখ্যা প্রকার।
INTEGER পূর্ণসংখ্যার ধরণ।
BOOLEAN বুলিয়ান প্রকার।
ARRAY অ্যারে টাইপ।
OBJECT বস্তুর ধরন।
NULL নাল টাইপ।

GoogleSearch Retrieval

গুগল দ্বারা চালিত গ্রাউন্ডিংয়ের জন্য পাবলিক ওয়েব ডেটা পুনরুদ্ধার করার সরঞ্জাম।

ক্ষেত্র
dynamicRetrievalConfig object ( DynamicRetrievalConfig )

প্রদত্ত উত্সটির জন্য গতিশীল পুনরুদ্ধার কনফিগারেশন নির্দিষ্ট করে।

JSON প্রতিনিধিত্ব
{
  "dynamicRetrievalConfig": {
    object (DynamicRetrievalConfig)
  }
}

DynamicRetrievalConfig

গতিশীল পুনরুদ্ধার কাস্টমাইজ করার বিকল্পগুলি বর্ণনা করে।

ক্ষেত্র
mode enum ( Mode )

গতিশীল পুনরুদ্ধারে ব্যবহার করার জন্য ভবিষ্যদ্বাণীকারীর মোড।

dynamicThreshold number

গতিশীল পুনরুদ্ধারে ব্যবহৃত প্রান্তিকতা। যদি সেট না করা হয় তবে একটি সিস্টেম ডিফল্ট মান ব্যবহৃত হয়।

JSON প্রতিনিধিত্ব
{
  "mode": enum (Mode),
  "dynamicThreshold": number
}

মোড

গতিশীল পুনরুদ্ধারে ব্যবহার করার জন্য ভবিষ্যদ্বাণীকারীর মোড।

Enums
MODE_UNSPECIFIED সর্বদা পুনরুদ্ধার ট্রিগার।
MODE_DYNAMIC সিস্টেমটি যখন সিদ্ধান্ত নেয় তখনই পুনরুদ্ধার চালান।

কোডেক্সিকিউশন

এই ধরণের কোনও ক্ষেত্র নেই।

সরঞ্জাম যা মডেল দ্বারা উত্পাদিত কোড কার্যকর করে এবং স্বয়ংক্রিয়ভাবে ফলাফলটি মডেলটিতে ফিরিয়ে দেয়।

ExecutableCode এবং CodeExecutionResult দেখুন যা কেবল এই সরঞ্জামটি ব্যবহার করার সময় উত্পন্ন হয়।

গুগল সার্চ

এই ধরণের কোনও ক্ষেত্র নেই।

গুগলস অনুসন্ধান সরঞ্জাম প্রকার। মডেলটিতে গুগল অনুসন্ধান সমর্থন করার সরঞ্জাম। গুগল দ্বারা চালিত.

টুল কনফিগারেশন

অনুরোধে Tool ব্যবহার নির্দিষ্ট করার জন্য প্যারামিটারযুক্ত সরঞ্জাম কনফিগারেশন।

ক্ষেত্র
functionCallingConfig object ( FunctionCallingConfig )

ঐচ্ছিক। ফাংশন কলিং কনফিগারেশন।

JSON প্রতিনিধিত্ব
{
  "functionCallingConfig": {
    object (FunctionCallingConfig)
  }
}

FunctionCallingConfig

ফাংশন কলিং আচরণ নির্দিষ্ট করার জন্য কনফিগারেশন।

ক্ষেত্র
mode enum ( Mode )

ঐচ্ছিক। ফাংশন কলিং কার্যকর করা উচিত এমন মোডটি নির্দিষ্ট করে। যদি অনির্ধারিত হয় তবে ডিফল্ট মানটি অটোতে সেট করা হবে।

allowedFunctionNames[] string

ঐচ্ছিক। ফাংশন নামগুলির একটি সেট যা সরবরাহ করা হলে মডেলটি কল করবে এমন ফাংশনগুলিকে সীমাবদ্ধ করে।

এটি কেবল তখনই সেট করা উচিত যখন মোডটি থাকে। ফাংশনের নামগুলি মেলে [ফাংশনডেক্লারেশন.নাম]। মোড যে কোনওটিতে সেট করে, মডেল প্রদত্ত ফাংশন নামগুলির সেট থেকে একটি ফাংশন কলের পূর্বাভাস দেবে।

JSON প্রতিনিধিত্ব
{
  "mode": enum (Mode),
  "allowedFunctionNames": [
    string
  ]
}

মোড

এক্সিকিউশন মোডটি সংজ্ঞায়িত করে ফাংশন কলিংয়ের জন্য এক্সিকিউশন আচরণকে সংজ্ঞায়িত করে।

Enums
MODE_UNSPECIFIED অনির্ধারিত ফাংশন কলিং মোড। এই মানটি ব্যবহার করা উচিত নয়।
AUTO ডিফল্ট মডেল আচরণ, মডেল কোনও ফাংশন কল বা প্রাকৃতিক ভাষার প্রতিক্রিয়া পূর্বাভাস দেওয়ার সিদ্ধান্ত নেয়।
ANY মডেল সর্বদা কেবল একটি ফাংশন কল পূর্বাভাস দিতে বাধ্য। যদি "অনুমোদিত ফাংশননামস" সেট করা থাকে তবে পূর্বাভাসিত ফাংশন কলটি "অনুমোদিত ফাংশন নামগুলি" এর মধ্যে সীমাবদ্ধ থাকবে, অন্যথায় পূর্বাভাসিত ফাংশন কলটি সরবরাহিত "ফাংশনডিক্লারেশনস" এর কোনও একটি হবে।
NONE মডেল কোনও ফাংশন কল পূর্বাভাস দেবে না। কোনও ফাংশন ঘোষণা পাস না করার সময় মডেল আচরণটি একই।
VALIDATED মডেল কোনও ফাংশন কল বা প্রাকৃতিক ভাষার প্রতিক্রিয়ার পূর্বাভাস দেওয়ার সিদ্ধান্ত নিয়েছে, তবে সীমাবদ্ধ ডিকোডিংয়ের সাথে ফাংশন কলগুলি বৈধ করবে।

মেটাডেটা ব্যবহার

ক্যাশেড সামগ্রী ব্যবহারের উপর মেটাডেটা।

ক্ষেত্র
totalTokenCount integer

ক্যাশেড সামগ্রী যে মোট টোকেন গ্রহণ করে।

JSON প্রতিনিধিত্ব
{
  "totalTokenCount": integer
}
,

প্রসঙ্গে ক্যাচিং আপনাকে বারবার ব্যবহার করতে চান এমন প্রাকপম্পিউটেড ইনপুট টোকেনগুলি সংরক্ষণ এবং পুনরায় ব্যবহার করতে দেয়, উদাহরণস্বরূপ একই মিডিয়া ফাইল সম্পর্কে বিভিন্ন প্রশ্ন জিজ্ঞাসা করার সময়। এটি ব্যবহারের উপর নির্ভর করে ব্যয় এবং গতি সাশ্রয় হতে পারে। বিশদ পরিচিতির জন্য, প্রসঙ্গে ক্যাচিং গাইড দেখুন।

পদ্ধতি: ক্যাশেডকন্টেন্টস.ক্রিয়েট

ক্যাশেড কনটেন্ট রিসোর্স তৈরি করে।

শেষবিন্দু

পোস্ট https: / /generativelanguage.googleapis.com /v1beta /cachedContents

শরীরের অনুরোধ

অনুরোধ বডিটিতে CachedContent একটি উদাহরণ রয়েছে।

ক্ষেত্র
contents[] object ( Content )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। ক্যাশে সামগ্রী।

tools[] object ( Tool )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। মডেলটি পরবর্তী প্রতিক্রিয়া উত্পন্ন করতে Tools ব্যবহার করতে পারে এমন একটি তালিকা

expiration Union type
এই সংস্থানটি কখন শেষ হবে তা নির্দিষ্ট করে। expiration নিম্নলিখিতগুলির মধ্যে একটি হতে পারে:
expireTime string ( Timestamp format)

ইউটিসিতে টাইমস্ট্যাম্প যখন এই সংস্থানটি মেয়াদোত্তীর্ণ হিসাবে বিবেচিত হয়। ইনপুটটিতে যা প্রেরণ করা হয়েছিল তা নির্বিশেষে এটি সর্বদা আউটপুটে সরবরাহ করা হয়।

আরএফসি 3339 ব্যবহার করে, যেখানে উত্পন্ন আউটপুট সর্বদা জেড-সাধারণীকরণ করা হবে এবং 0, 3, 6 বা 9 ভগ্নাংশের সংখ্যা ব্যবহার করে। "জেড" ব্যতীত অন্যান্য অফসেটগুলিও গৃহীত হয়। উদাহরণ: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" বা "2014-10-02T15:01:23+05:30"

ttl string ( Duration format)

শুধুমাত্র ইনপুট। এই সংস্থানটির জন্য নতুন টিটিএল, কেবল ইনপুট।

' s ' দিয়ে শেষ হওয়া নয়টি ভগ্নাংশের সংখ্যা সহ সেকেন্ডে একটি সময়কাল। উদাহরণ: "3.5s"

displayName string

ঐচ্ছিক। অপরিবর্তনীয়। ক্যাশেড সামগ্রীর ব্যবহারকারী-উত্পাদিত অর্থপূর্ণ ডিসপ্লে নাম। সর্বাধিক 128 ইউনিকোড অক্ষর।

model string

প্রয়োজন। অপরিবর্তনীয়। ক্যাশেড সামগ্রী ফর্ম্যাটের জন্য Model নাম: models/{model}

systemInstruction object ( Content )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। বিকাশকারী সেট সিস্টেম নির্দেশ। বর্তমানে কেবল পাঠ্য।

toolConfig object ( ToolConfig )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। সরঞ্জাম কনফিগারেশন। এই কনফিগারেশনটি সমস্ত সরঞ্জামের জন্য ভাগ করা হয়েছে।

উদাহরণ অনুরোধ

from google import genai
from google.genai import types

client = genai.Client()
document = client.files.upload(file=media / "a11.txt")
model_name = "gemini-1.5-flash-001"

cache = client.caches.create(
    model=model_name,
    config=types.CreateCachedContentConfig(
        contents=[document],
        system_instruction="You are an expert analyzing transcripts.",
    ),
)
print(cache)

response = client.models.generate_content(
    model=model_name,
    contents="Please summarize this transcript",
    config=types.GenerateContentConfig(cached_content=cache.name),
)
print(response.text)
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);
const modelName = "gemini-1.5-flash-001";

const contents = [
  createUserContent(createPartFromUri(document.uri, document.mimeType)),
];

const cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: contents,
    systemInstruction: "You are an expert analyzing transcripts.",
  },
});
console.log("Cache created:", cache);

const response = await ai.models.generateContent({
  model: modelName,
  contents: "Please summarize this transcript",
  config: { cachedContent: cache.name },
});
console.log("Response text:", response.text);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"), 
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}
parts := []*genai.Part{
	genai.NewPartFromURI(document.URI, document.MIMEType),
}
contents := []*genai.Content{
	genai.NewContentFromParts(parts, "user"),
}
cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents: contents,
	SystemInstruction: genai.NewContentFromText(
		"You are an expert analyzing transcripts.", "user",
	),
})
if err != nil {
	log.Fatal(err)
}
fmt.Println("Cache created:")
fmt.Println(cache)

// Use the cache for generating content.
response, err := client.Models.GenerateContent(
	ctx,
	modelName,
	genai.Text("Please summarize this transcript"),
	&genai.GenerateContentConfig{
		CachedContent: cache.Name,
	},
)
if err != nil {
	log.Fatal(err)
}
printResponse(response)
wget https://storage.googleapis.com/generativeai-downloads/data/a11.txt
echo '{
  "model": "models/gemini-1.5-flash-001",
  "contents":[
    {
      "parts":[
        {
          "inline_data": {
            "mime_type":"text/plain",
            "data": "'$(base64 $B64FLAGS a11.txt)'"
          }
        }
      ],
    "role": "user"
    }
  ],
  "systemInstruction": {
    "parts": [
      {
        "text": "You are an expert at analyzing transcripts."
      }
    ]
  },
  "ttl": "300s"
}' > request.json

curl -X POST "https://generativelanguage.googleapis.com/v1beta/cachedContents?key=$GEMINI_API_KEY" \
 -H 'Content-Type: application/json' \
 -d @request.json \
 > cache.json

CACHE_NAME=$(cat cache.json | grep '"name":' | cut -d '"' -f 4 | head -n 1)

curl -X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-001:generateContent?key=$GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
      "contents": [
        {
          "parts":[{
            "text": "Please summarize this transcript"
          }],
          "role": "user"
        },
      ],
      "cachedContent": "'$CACHE_NAME'"
    }'
from google import genai
from google.genai import types

client = genai.Client()
document = client.files.upload(file=media / "a11.txt")
model_name = "gemini-1.5-flash-001"

cache = client.caches.create(
    model=model_name,
    config=types.CreateCachedContentConfig(
        contents=[document],
        system_instruction="You are an expert analyzing transcripts.",
    ),
)
cache_name = cache.name  # Save the name for later

# Later retrieve the cache
cache = client.caches.get(name=cache_name)
response = client.models.generate_content(
    model=model_name,
    contents="Find a lighthearted moment from this transcript",
    config=types.GenerateContentConfig(cached_content=cache.name),
)
print(response.text)
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);
const modelName = "gemini-1.5-flash-001";

const contents = [
  createUserContent(createPartFromUri(document.uri, document.mimeType)),
];

const cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: contents,
    systemInstruction: "You are an expert analyzing transcripts.",
  },
});
const cacheName = cache.name; // Save the name for later

// Later retrieve the cache
const retrievedCache = await ai.caches.get({ name: cacheName });
const response = await ai.models.generateContent({
  model: modelName,
  contents: "Find a lighthearted moment from this transcript",
  config: { cachedContent: retrievedCache.name },
});
console.log("Response text:", response.text);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"),
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}
parts := []*genai.Part{
	genai.NewPartFromURI(document.URI, document.MIMEType),
}
contents := []*genai.Content{
	genai.NewContentFromParts(parts, "user"),
}
cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents:          contents,
	SystemInstruction: genai.NewContentFromText(
		"You are an expert analyzing transcripts.", "user",
	),
})
if err != nil {
	log.Fatal(err)
}
cacheName := cache.Name

// Later retrieve the cache.
cache, err = client.Caches.Get(ctx, cacheName, &genai.GetCachedContentConfig{})
if err != nil {
	log.Fatal(err)
}

response, err := client.Models.GenerateContent(
	ctx,
	modelName,
	genai.Text("Find a lighthearted moment from this transcript"),
	&genai.GenerateContentConfig{
		CachedContent: cache.Name,
	},
)
if err != nil {
	log.Fatal(err)
}
fmt.Println("Response from cache (create from name):")
printResponse(response)
from google import genai
from google.genai import types

client = genai.Client()
model_name = "gemini-1.5-flash-001"
system_instruction = "You are an expert analyzing transcripts."

# Create a chat session with the given system instruction.
chat = client.chats.create(
    model=model_name,
    config=types.GenerateContentConfig(system_instruction=system_instruction),
)
document = client.files.upload(file=media / "a11.txt")

response = chat.send_message(
    message=["Hi, could you summarize this transcript?", document]
)
print("\n\nmodel:  ", response.text)
response = chat.send_message(
    message=["Okay, could you tell me more about the trans-lunar injection"]
)
print("\n\nmodel:  ", response.text)

# To cache the conversation so far, pass the chat history as the list of contents.
cache = client.caches.create(
    model=model_name,
    config={
        "contents": chat.get_history(),
        "system_instruction": system_instruction,
    },
)
# Continue the conversation using the cached content.
chat = client.chats.create(
    model=model_name,
    config=types.GenerateContentConfig(cached_content=cache.name),
)
response = chat.send_message(
    message="I didn't understand that last part, could you explain it in simpler language?"
)
print("\n\nmodel:  ", response.text)
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const modelName = "gemini-1.5-flash-001";
const systemInstruction = "You are an expert analyzing transcripts.";

// Create a chat session with the system instruction.
const chat = ai.chats.create({
  model: modelName,
  config: { systemInstruction: systemInstruction },
});
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);

let response = await chat.sendMessage({
  message: createUserContent([
    "Hi, could you summarize this transcript?",
    createPartFromUri(document.uri, document.mimeType),
  ]),
});
console.log("\n\nmodel:", response.text);

response = await chat.sendMessage({
  message: "Okay, could you tell me more about the trans-lunar injection",
});
console.log("\n\nmodel:", response.text);

// To cache the conversation so far, pass the chat history as the list of contents.
const chatHistory = chat.getHistory();
const cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: chatHistory,
    systemInstruction: systemInstruction,
  },
});

// Continue the conversation using the cached content.
const chatWithCache = ai.chats.create({
  model: modelName,
  config: { cachedContent: cache.name },
});
response = await chatWithCache.sendMessage({
  message:
    "I didn't understand that last part, could you explain it in simpler language?",
});
console.log("\n\nmodel:", response.text);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"),
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
systemInstruction := "You are an expert analyzing transcripts."

// Create initial chat with a system instruction.
chat, err := client.Chats.Create(ctx, modelName, &genai.GenerateContentConfig{
	SystemInstruction: genai.NewContentFromText(systemInstruction, "user"),
}, nil)
if err != nil {
	log.Fatal(err)
}

document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}

// Send first message with the transcript.
parts := make([]genai.Part, 2)
parts[0] = genai.Part{Text: "Hi, could you summarize this transcript?"}
parts[1] = genai.Part{
	FileData: &genai.FileData{
		FileURI :      document.URI,
		MIMEType: document.MIMEType,
	},
}

// Send chat message.
resp, err := chat.SendMessage(ctx, parts...)
if err != nil {
	log.Fatal(err)
}
fmt.Println("\n\nmodel: ", resp.Text())

resp, err = chat.SendMessage(
	ctx, 
	genai.Part{
		Text: "Okay, could you tell me more about the trans-lunar injection",
	},
)
if err != nil {
	log.Fatal(err)
}
fmt.Println("\n\nmodel: ", resp.Text())

// To cache the conversation so far, pass the chat history as the list of contents.
cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents:          chat.History(false),
	SystemInstruction: genai.NewContentFromText(systemInstruction, "user"),
})
if err != nil {
	log.Fatal(err)
}

// Continue the conversation using the cached history.
chat, err = client.Chats.Create(ctx, modelName, &genai.GenerateContentConfig{
	CachedContent: cache.Name,
}, nil)
if err != nil {
	log.Fatal(err)
}

resp, err = chat.SendMessage(
	ctx, 
	genai.Part{
		Text: "I didn't understand that last part, could you explain it in simpler language?",
	},
)
if err != nil {
	log.Fatal(err)
}
fmt.Println("\n\nmodel: ", resp.Text())

প্রতিক্রিয়া শরীর

যদি সফল হয় তবে প্রতিক্রিয়া বডিটিতে CachedContent একটি নতুন তৈরি উদাহরণ রয়েছে।

পদ্ধতি: ক্যাশেড কনটেন্টস.লিস্ট

ক্যাশেড কনটেন্টগুলি তালিকা করে।

শেষবিন্দু

https: / /generativelanguage.googleapis.com /v1beta /cachedContents পান

ক্যোয়ারী প্যারামিটার

pageSize integer

ঐচ্ছিক। প্রত্যাবর্তনের জন্য সর্বাধিক সংখ্যক ক্যাশেড সামগ্রী। পরিষেবাটি এই মানের চেয়ে কম ফিরে আসতে পারে। যদি অনির্ধারিত হয় তবে কিছু ডিফল্ট (সর্বাধিক নিচে) আইটেমের সংখ্যা ফিরে আসবে। সর্বাধিক মান 1000; 1000 এর উপরে মানগুলি 1000 এ জোর করা হবে।

pageToken string

ঐচ্ছিক। একটি পৃষ্ঠা টোকেন, পূর্ববর্তী cachedContents.list কল থেকে প্রাপ্ত। পরবর্তী পৃষ্ঠাটি পুনরুদ্ধার করতে এটি সরবরাহ করুন।

প্যাগিনেট করার সময়, cachedContents.list সরবরাহ করা অন্যান্য সমস্ত পরামিতি.লিস্ট অবশ্যই কলটির সাথে মেলে যা পৃষ্ঠাটি টোকেন সরবরাহ করে।

শরীরের অনুরোধ

অনুরোধের বডি খালি হতে হবে।

প্রতিক্রিয়া শরীর

ক্যাশেড কনটেন্টেন্টস তালিকার সাথে প্রতিক্রিয়া।

যদি সফল হয় তবে প্রতিক্রিয়া বডিটিতে নিম্নলিখিত কাঠামোর সাথে ডেটা রয়েছে:

ক্ষেত্র
cachedContents[] object ( CachedContent )

ক্যাশেড সামগ্রীগুলির তালিকা।

nextPageToken string

একটি টোকেন, যা পরবর্তী পৃষ্ঠাটি পুনরুদ্ধার করতে pageToken হিসাবে প্রেরণ করা যেতে পারে। যদি এই ক্ষেত্রটি বাদ দেওয়া হয় তবে পরবর্তী কোনও পৃষ্ঠা নেই।

JSON প্রতিনিধিত্ব
{
  "cachedContents": [
    {
      object (CachedContent)
    }
  ],
  "nextPageToken": string
}

পদ্ধতি: ক্যাশেড কনটেন্টস.জেট

ক্যাশেড কনটেন্ট রিসোর্স পড়ে।

শেষবিন্দু

https: / /generativelanguage.googleapis.com /v1beta /{name=cachedContents /*} পান

পাথ প্যারামিটার

name string

প্রয়োজন। সামগ্রীর ক্যাশে প্রবেশের উল্লেখ করে রিসোর্সের নাম। ফর্ম্যাট: cachedContents/{id} এটি ফর্ম cachedContents/{cachedcontent} নেয়}

শরীরের অনুরোধ

অনুরোধের বডি খালি হতে হবে।

উদাহরণ অনুরোধ

from google import genai

client = genai.Client()
document = client.files.upload(file=media / "a11.txt")
model_name = "gemini-1.5-flash-001"

cache = client.caches.create(
    model=model_name,
    config={
        "contents": [document],
        "system_instruction": "You are an expert analyzing transcripts.",
    },
)
print(client.caches.get(name=cache.name))
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);
const modelName = "gemini-1.5-flash-001";

const contents = [
  createUserContent(createPartFromUri(document.uri, document.mimeType)),
];

const cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: contents,
    systemInstruction: "You are an expert analyzing transcripts.",
  },
});
const retrievedCache = await ai.caches.get({ name: cache.name });
console.log("Retrieved Cache:", retrievedCache);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"),
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}
parts := []*genai.Part{
	genai.NewPartFromURI(document.URI, document.MIMEType),
}
contents := []*genai.Content{
	genai.NewContentFromParts(parts, "user"),
}

cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents:          contents,
	SystemInstruction: genai.NewContentFromText(
		"You are an expert analyzing transcripts.", "user",
	),
})
if err != nil {
	log.Fatal(err)
}

cache, err = client.Caches.Get(ctx, cache.Name, &genai.GetCachedContentConfig{})
if err != nil {
	log.Fatal(err)
}
fmt.Println("Retrieved cache:")
fmt.Println(cache)
curl "https://generativelanguage.googleapis.com/v1beta/$CACHE_NAME?key=$GEMINI_API_KEY"

প্রতিক্রিয়া শরীর

যদি সফল হয় তবে প্রতিক্রিয়া বডিটিতে CachedContent একটি উদাহরণ রয়েছে।

পদ্ধতি: ক্যাশেড কনটেন্টস.প্যাচ

আপডেটগুলি ক্যাশেড কনটেন্ট রিসোর্স (কেবলমাত্র মেয়াদ শেষ হওয়া আপডেটযোগ্য)।

শেষবিন্দু

প্যাচ https: / /generativelanguage.googleapis.com /v1beta /{cachedContent.name=cachedContents /*}
PATCH https://generativelanguage.googleapis.com/v1beta/{cachedContent.name=cachedContents/*}

পাথ প্যারামিটার

cachedContent.name string

শুধুমাত্র আউটপুট। সনাক্তকারী ক্যাশেড সামগ্রী উল্লেখ করে রিসোর্সের নাম। ফর্ম্যাট: cachedContents/{id} এটি ফর্ম cachedContents/{cachedcontent} নেয়}

ক্যোয়ারী প্যারামিটার

updateMask string ( FieldMask format)

আপডেট করার জন্য ক্ষেত্রগুলির তালিকা।

এটি ক্ষেত্রগুলির সম্পূর্ণরূপে যোগ্য নামগুলির একটি কমা-বিচ্ছিন্ন তালিকা। উদাহরণ: "user.displayName,photo"

শরীরের অনুরোধ

অনুরোধ বডিটিতে CachedContent একটি উদাহরণ রয়েছে।

ক্ষেত্র
expiration Union type
এই সংস্থানটি কখন শেষ হবে তা নির্দিষ্ট করে। expiration নিম্নলিখিতগুলির মধ্যে একটি হতে পারে:
expireTime string ( Timestamp format)

ইউটিসিতে টাইমস্ট্যাম্প যখন এই সংস্থানটি মেয়াদোত্তীর্ণ হিসাবে বিবেচিত হয়। ইনপুটটিতে যা প্রেরণ করা হয়েছিল তা নির্বিশেষে এটি সর্বদা আউটপুটে সরবরাহ করা হয়।

আরএফসি 3339 ব্যবহার করে, যেখানে উত্পন্ন আউটপুট সর্বদা জেড-সাধারণীকরণ করা হবে এবং 0, 3, 6 বা 9 ভগ্নাংশের সংখ্যা ব্যবহার করে। "জেড" ব্যতীত অন্যান্য অফসেটগুলিও গৃহীত হয়। উদাহরণ: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" বা "2014-10-02T15:01:23+05:30"

ttl string ( Duration format)

শুধুমাত্র ইনপুট। এই সংস্থানটির জন্য নতুন টিটিএল, কেবল ইনপুট।

' s ' দিয়ে শেষ হওয়া নয়টি ভগ্নাংশের সংখ্যা সহ সেকেন্ডে একটি সময়কাল। উদাহরণ: "3.5s"

উদাহরণ অনুরোধ

from google import genai
from google.genai import types
import datetime

client = genai.Client()
document = client.files.upload(file=media / "a11.txt")
model_name = "gemini-1.5-flash-001"

cache = client.caches.create(
    model=model_name,
    config={
        "contents": [document],
        "system_instruction": "You are an expert analyzing transcripts.",
    },
)

# Update the cache's time-to-live (ttl)
ttl = f"{int(datetime.timedelta(hours=2).total_seconds())}s"
client.caches.update(
    name=cache.name, config=types.UpdateCachedContentConfig(ttl=ttl)
)
print(f"After update:\n {cache}")

# Alternatively, update the expire_time directly
# Update the expire_time directly in valid RFC 3339 format (UTC with a "Z" suffix)
expire_time = (
    (
        datetime.datetime.now(datetime.timezone.utc)
        + datetime.timedelta(minutes=15)
    )
    .isoformat()
    .replace("+00:00", "Z")
)
client.caches.update(
    name=cache.name,
    config=types.UpdateCachedContentConfig(expire_time=expire_time),
)
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);
const modelName = "gemini-1.5-flash-001";

const contents = [
  createUserContent(createPartFromUri(document.uri, document.mimeType)),
];

let cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: contents,
    systemInstruction: "You are an expert analyzing transcripts.",
  },
});

// Update the cache's time-to-live (ttl)
const ttl = `${2 * 3600}s`; // 2 hours in seconds
cache = await ai.caches.update({
  name: cache.name,
  config: { ttl },
});
console.log("After update (TTL):", cache);

// Alternatively, update the expire_time directly (in RFC 3339 format with a "Z" suffix)
const expireTime = new Date(Date.now() + 15 * 60000)
  .toISOString()
  .replace(/\.\d{3}Z$/, "Z");
cache = await ai.caches.update({
  name: cache.name,
  config: { expireTime: expireTime },
});
console.log("After update (expire_time):", cache);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"),
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}
parts := []*genai.Part{
	genai.NewPartFromURI(document.URI, document.MIMEType),
}
contents := []*genai.Content{
	genai.NewContentFromParts(parts, "user"),
}

cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents:          contents,
	SystemInstruction: genai.NewContentFromText(
		"You are an expert analyzing transcripts.", "user",
	),
})
if err != nil {
	log.Fatal(err)
}

_, err = client.Caches.Delete(ctx, cache.Name, &genai.DeleteCachedContentConfig{})
if err != nil {
	log.Fatal(err)
}
fmt.Println("Cache deleted:", cache.Name)
curl -X PATCH "https://generativelanguage.googleapis.com/v1beta/$CACHE_NAME?key=$GEMINI_API_KEY" \
 -H 'Content-Type: application/json' \
 -d '{"ttl": "600s"}'

প্রতিক্রিয়া শরীর

যদি সফল হয় তবে প্রতিক্রিয়া বডিটিতে CachedContent একটি উদাহরণ রয়েছে।

পদ্ধতি: ক্যাশেডকন্টেন্টস.ডিলিট

ক্যাশেড কনটেন্ট রিসোর্স মুছে ফেলেছে।

শেষবিন্দু

https: / /generativelanguage.googleapis.com /v1beta /{name=cachedContents /*} মুছুন

পাথ প্যারামিটার

name string

প্রয়োজন। সামগ্রীর ক্যাশে প্রবেশের ফর্ম্যাটটি উল্লেখ করে রিসোর্স নাম: cachedContents/{id} এটি ফর্ম cachedContents/{cachedcontent} নেয়}

শরীরের অনুরোধ

অনুরোধের বডি খালি হতে হবে।

উদাহরণ অনুরোধ

from google import genai

client = genai.Client()
document = client.files.upload(file=media / "a11.txt")
model_name = "gemini-1.5-flash-001"

cache = client.caches.create(
    model=model_name,
    config={
        "contents": [document],
        "system_instruction": "You are an expert analyzing transcripts.",
    },
)
client.caches.delete(name=cache.name)
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);
const modelName = "gemini-1.5-flash-001";

const contents = [
  createUserContent(createPartFromUri(document.uri, document.mimeType)),
];

const cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: contents,
    systemInstruction: "You are an expert analyzing transcripts.",
  },
});
await ai.caches.delete({ name: cache.name });
console.log("Cache deleted:", cache.name);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"),
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}
parts := []*genai.Part{
	genai.NewPartFromURI(document.URI, document.MIMEType),
}
contents := []*genai.Content{
	genai.NewContentFromParts(parts, "user"),
}

cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents:          contents,
	SystemInstruction: genai.NewContentFromText(
		"You are an expert analyzing transcripts.", "user",
	),
})
if err != nil {
	log.Fatal(err)
}

_, err = client.Caches.Delete(ctx, cache.Name, &genai.DeleteCachedContentConfig{})
if err != nil {
	log.Fatal(err)
}
fmt.Println("Cache deleted:", cache.Name)
curl -X DELETE "https://generativelanguage.googleapis.com/v1beta/$CACHE_NAME?key=$GEMINI_API_KEY"

প্রতিক্রিয়া শরীর

যদি সফল হয় তবে প্রতিক্রিয়া বডিটি একটি খালি JSON অবজেক্ট।

বিশ্রাম সংস্থান: ক্যাশেড কনটেন্টস

সংস্থান: ক্যাশেড কনটেন্ট

যে বিষয়বস্তু প্রাক -প্রসেস করা হয়েছে এবং পরবর্তীকালে জেনারেটর সার্ভিসে অনুরোধে ব্যবহার করা যেতে পারে।

ক্যাশেড সামগ্রী কেবল এটির জন্য তৈরি করা মডেল দিয়ে ব্যবহার করা যেতে পারে।

ক্ষেত্র
contents[] object ( Content )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। ক্যাশে সামগ্রী।

tools[] object ( Tool )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। মডেলটি পরবর্তী প্রতিক্রিয়া উত্পন্ন করতে Tools ব্যবহার করতে পারে এমন একটি তালিকা

createTime string ( Timestamp format)

শুধুমাত্র আউটপুট। ক্যাশে প্রবেশের তৈরির সময়।

আরএফসি 3339 ব্যবহার করে, যেখানে উত্পন্ন আউটপুট সর্বদা জেড-সাধারণীকরণ করা হবে এবং 0, 3, 6 বা 9 ভগ্নাংশের সংখ্যা ব্যবহার করে। "জেড" ব্যতীত অন্যান্য অফসেটগুলিও গৃহীত হয়। উদাহরণ: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" বা "2014-10-02T15:01:23+05:30"

updateTime string ( Timestamp format)

শুধুমাত্র আউটপুট। যখন ক্যাশে এন্ট্রিটি সর্বশেষ ইউটিসি সময়ে আপডেট হয়েছিল।

আরএফসি 3339 ব্যবহার করে, যেখানে উত্পন্ন আউটপুট সর্বদা জেড-সাধারণীকরণ করা হবে এবং 0, 3, 6 বা 9 ভগ্নাংশের সংখ্যা ব্যবহার করে। "জেড" ব্যতীত অন্যান্য অফসেটগুলিও গৃহীত হয়। উদাহরণ: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" বা "2014-10-02T15:01:23+05:30"

usageMetadata object ( UsageMetadata )

শুধুমাত্র আউটপুট। ক্যাশেড সামগ্রী ব্যবহারের উপর মেটাডেটা।

expiration Union type
এই সংস্থানটি কখন শেষ হবে তা নির্দিষ্ট করে। expiration নিম্নলিখিতগুলির মধ্যে একটি হতে পারে:
expireTime string ( Timestamp format)

ইউটিসিতে টাইমস্ট্যাম্প যখন এই সংস্থানটি মেয়াদোত্তীর্ণ হিসাবে বিবেচিত হয়। ইনপুটটিতে যা প্রেরণ করা হয়েছিল তা নির্বিশেষে এটি সর্বদা আউটপুটে সরবরাহ করা হয়।

আরএফসি 3339 ব্যবহার করে, যেখানে উত্পন্ন আউটপুট সর্বদা জেড-সাধারণীকরণ করা হবে এবং 0, 3, 6 বা 9 ভগ্নাংশের সংখ্যা ব্যবহার করে। "জেড" ব্যতীত অন্যান্য অফসেটগুলিও গৃহীত হয়। উদাহরণ: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" বা "2014-10-02T15:01:23+05:30"

ttl string ( Duration format)

শুধুমাত্র ইনপুট। এই সংস্থানটির জন্য নতুন টিটিএল, কেবল ইনপুট।

' s ' দিয়ে শেষ হওয়া নয়টি ভগ্নাংশের সংখ্যা সহ সেকেন্ডে একটি সময়কাল। উদাহরণ: "3.5s"

name string

শুধুমাত্র আউটপুট। সনাক্তকারী ক্যাশেড সামগ্রী উল্লেখ করে রিসোর্সের নাম। ফর্ম্যাট: cachedContents/{id}

displayName string

ঐচ্ছিক। অপরিবর্তনীয়। ক্যাশেড সামগ্রীর ব্যবহারকারী-উত্পাদিত অর্থপূর্ণ প্রদর্শন নাম। সর্বাধিক 128 ইউনিকোড অক্ষর।

model string

প্রয়োজন। অপরিবর্তনীয়। ক্যাশেড সামগ্রী ফর্ম্যাটের জন্য Model নাম: models/{model}

systemInstruction object ( Content )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। বিকাশকারী সেট সিস্টেম নির্দেশ। বর্তমানে কেবল পাঠ্য।

toolConfig object ( ToolConfig )

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। সরঞ্জাম কনফিগারেশন। এই কনফিগারেশনটি সমস্ত সরঞ্জামের জন্য ভাগ করা হয়েছে।

JSON প্রতিনিধিত্ব
{
  "contents": [
    {
      object (Content)
    }
  ],
  "tools": [
    {
      object (Tool)
    }
  ],
  "createTime": string,
  "updateTime": string,
  "usageMetadata": {
    object (UsageMetadata)
  },

  // expiration
  "expireTime": string,
  "ttl": string
  // Union type
  "name": string,
  "displayName": string,
  "model": string,
  "systemInstruction": {
    object (Content)
  },
  "toolConfig": {
    object (ToolConfig)
  }
}

বিষয়বস্তু

একটি বার্তার মাল্টি-পার্ট সামগ্রীযুক্ত বেস স্ট্রাকচার্ড ডেটাটাইপ।

একটি Content Content প্রযোজককে মনোনীত করে এমন একটি role ক্ষেত্র এবং বার্তার টার্নের সামগ্রী রয়েছে এমন মাল্টি-পার্ট ডেটাযুক্ত একটি parts ক্ষেত্র অন্তর্ভুক্ত রয়েছে।

ক্ষেত্র
parts[] object ( Part )

অর্ডার করা Parts যা একটি একক বার্তা গঠন করে। অংশগুলি বিভিন্ন মাইম প্রকার থাকতে পারে।

role string

ঐচ্ছিক। বিষয়বস্তু প্রযোজক। হয় 'ব্যবহারকারী' বা 'মডেল' হতে হবে।

মাল্টি-টার্ন কথোপকথনের জন্য সেট করতে দরকারী, অন্যথায় ফাঁকা বা আনসেট ছেড়ে দেওয়া যেতে পারে।

JSON প্রতিনিধিত্ব
{
  "parts": [
    {
      object (Part)
    }
  ],
  "role": string
}

অংশ

মিডিয়াযুক্ত একটি ডেটাটাইপ যা মাল্টি-পার্ট Content বার্তার অংশ।

একটি Part ডেটা থাকে যার সাথে সম্পর্কিত ডেটাটাইপ রয়েছে। একটি Part কেবল Part.data স্বীকৃত প্রকারগুলির মধ্যে একটি থাকতে পারে।

inlineData ক্ষেত্রটি কাঁচা বাইটে ভরাট থাকলে একটি Part অবশ্যই মিডিয়ার ধরণ এবং সাব টাইপ সনাক্তকারী একটি স্থির আইনা মাইম টাইপ থাকতে হবে।

ক্ষেত্র
thought boolean

ঐচ্ছিক। অংশটি মডেল থেকে চিন্তা করা হয় কিনা তা নির্দেশ করে।

data Union type
data নিম্নলিখিতগুলির মধ্যে একটি হতে পারে:
text string

ইনলাইন পাঠ্য।

inlineData object ( Blob )

ইনলাইন মিডিয়া বাইটস।

functionCall object ( FunctionCall )

একটি পূর্বাভাসযুক্ত FunctionCall মডেল থেকে ফিরে এসেছিল যাতে FunctionDeclaration.name উপস্থাপন করে এমন একটি স্ট্রিং থাকে nome আর্গুমেন্ট এবং তাদের মানগুলির সাথে নাম।

functionResponse object ( FunctionResponse )

FunctionCall ফলাফল আউটপুট যা FunctionDeclaration.name এবং ফাংশন থেকে কোনও আউটপুটযুক্ত একটি কাঠামোগত জেএসএন অবজেক্টকে উপস্থাপন করে এমন একটি স্ট্রিং রয়েছে যা মডেলটির প্রসঙ্গ হিসাবে ব্যবহৃত হয়।

fileData object ( FileData )

ইউআরআই ভিত্তিক ডেটা।

executableCode object ( ExecutableCode )

মডেল দ্বারা উত্পাদিত কোড যা কার্যকর করা বোঝানো হয়।

codeExecutionResult object ( CodeExecutionResult )

ExecutableCode কার্যকর করার ফলাফল।

JSON প্রতিনিধিত্ব
{
  "thought": boolean,

  // data
  "text": string,
  "inlineData": {
    object (Blob)
  },
  "functionCall": {
    object (FunctionCall)
  },
  "functionResponse": {
    object (FunctionResponse)
  },
  "fileData": {
    object (FileData)
  },
  "executableCode": {
    object (ExecutableCode)
  },
  "codeExecutionResult": {
    object (CodeExecutionResult)
  }
  // Union type
}

ব্লব

কাঁচা মিডিয়া বাইটস।

পাঠ্য কাঁচা বাইট হিসাবে প্রেরণ করা উচিত নয়, 'পাঠ্য' ক্ষেত্রটি ব্যবহার করুন।

ক্ষেত্র
mimeType string

উত্স ডেটা আইএএনএ স্ট্যান্ডার্ড মাইম প্রকার। উদাহরণ: - চিত্র/পিএনজি - চিত্র/জেপিইজি যদি কোনও অসমর্থিত মাইম টাইপ সরবরাহ করা হয় তবে একটি ত্রুটি ফিরে আসবে। সমর্থিত ধরণের সম্পূর্ণ তালিকার জন্য, সমর্থিত ফাইল ফর্ম্যাটগুলি দেখুন।

data string ( bytes format)

মিডিয়া ফর্ম্যাটগুলির জন্য কাঁচা বাইট।

একটি বেস 64-এনকোডড স্ট্রিং।

JSON প্রতিনিধিত্ব
{
  "mimeType": string,
  "data": string
}

ফাংশনকল

একটি পূর্বাভাসযুক্ত FunctionCall মডেল থেকে ফিরে এসেছিল যাতে FunctionDeclaration.name উপস্থাপন করে এমন একটি স্ট্রিং থাকে nome আর্গুমেন্ট এবং তাদের মানগুলির সাথে নাম।

ক্ষেত্র
id string

ঐচ্ছিক। ফাংশন কল এর অনন্য আইডি। যদি পপুলেটেড হয় তবে ক্লায়েন্টটি functionCall কার্যকর করতে এবং ম্যাচিং id দিয়ে প্রতিক্রিয়াটি ফিরিয়ে দিতে।

name string

প্রয়োজন। কল করার জন্য ফাংশনের নাম। অবশ্যই এজেড, এজেড, 0-9 হতে হবে বা সর্বাধিক দৈর্ঘ্য 63 সহ আন্ডারস্কোর এবং ড্যাশ থাকতে পারে।

args object ( Struct format)

ঐচ্ছিক। JSON অবজেক্ট ফর্ম্যাটে ফাংশন পরামিতি এবং মান।

JSON প্রতিনিধিত্ব
{
  "id": string,
  "name": string,
  "args": {
    object
  }
}

ফাংশন রেসপন্স

FunctionCall থেকে ফলাফল আউটপুটটিতে FunctionDeclaration.name এবং ফাংশন থেকে কোনও আউটপুটযুক্ত কাঠামোগত জেএসএন অবজেক্টের প্রতিনিধিত্ব করে এমন একটি স্ট্রিং রয়েছে যা মডেলটির প্রসঙ্গ হিসাবে ব্যবহৃত হয়। এটিতে মডেল পূর্বাভাসের ভিত্তিতে তৈরি FunctionCall ফলাফল থাকা উচিত।

ক্ষেত্র
id string

ঐচ্ছিক। ফাংশনটির আইডি কল এই প্রতিক্রিয়াটির জন্য। সংশ্লিষ্ট ফাংশন কল id সাথে মেলে ক্লায়েন্ট দ্বারা জনবহুল।

name string

প্রয়োজন। কল করার জন্য ফাংশনের নাম। অবশ্যই এজেড, এজেড, 0-9 হতে হবে বা সর্বাধিক দৈর্ঘ্য 63 সহ আন্ডারস্কোর এবং ড্যাশ থাকতে পারে।

response object ( Struct format)

প্রয়োজন। JSON অবজেক্ট ফর্ম্যাটে ফাংশন প্রতিক্রিয়া।

JSON প্রতিনিধিত্ব
{
  "id": string,
  "name": string,
  "response": {
    object
  }
}

ফাইলডেটা

ইউআরআই ভিত্তিক ডেটা।

ক্ষেত্র
mimeType string

ঐচ্ছিক। উত্স ডেটা আইএএনএ স্ট্যান্ডার্ড মাইম প্রকার।

fileUri string

প্রয়োজন। ইউআরআই।

JSON প্রতিনিধিত্ব
{
  "mimeType": string,
  "fileUri": string
}

এক্সিকিউটেবল কোড

মডেল দ্বারা উত্পাদিত কোড যা কার্যকর করা বোঝানো হয় এবং ফলাফলটি মডেলটিতে ফিরে আসে।

CodeExecution সরঞ্জামটি ব্যবহার করার সময় কেবল উত্পন্ন হয়, যেখানে কোডটি স্বয়ংক্রিয়ভাবে কার্যকর করা হবে এবং সংশ্লিষ্ট CodeExecutionResult উত্পন্ন হবে।

ক্ষেত্র
language enum ( Language )

প্রয়োজন। code প্রোগ্রামিং ভাষা।

code string

প্রয়োজন। কোড কার্যকর করা হবে।

JSON প্রতিনিধিত্ব
{
  "language": enum (Language),
  "code": string
}

ভাষা

উত্পন্ন কোডের জন্য সমর্থিত প্রোগ্রামিং ভাষা।

Enums
LANGUAGE_UNSPECIFIED অনির্ধারিত ভাষা। এই মানটি ব্যবহার করা উচিত নয়।
PYTHON পাইথন> = 3.10, নুমপি এবং সিম্পি উপলব্ধ।

কোড এক্সিকিউশন ফলাফল

ExecutableCode কার্যকর করার ফলাফল।

CodeExecution ব্যবহার করার সময় কেবল উত্পাদিত হয় এবং সর্বদা ExecutableCode একটি part অনুসরণ করে।

ক্ষেত্র
outcome enum ( Outcome )

প্রয়োজন। কোড এক্সিকিউশনের ফলাফল।

output string

ঐচ্ছিক। কোড এক্সিকিউশন সফল, স্টেরার বা অন্য বিবরণ অন্যথায় যখন স্টাডআউট থাকে।

JSON প্রতিনিধিত্ব
{
  "outcome": enum (Outcome),
  "output": string
}

ফলাফল

কোড এক্সিকিউশনের সম্ভাব্য ফলাফলগুলির গণনা।

Enums
OUTCOME_UNSPECIFIED অনির্ধারিত অবস্থা। এই মানটি ব্যবহার করা উচিত নয়।
OUTCOME_OK কোড এক্সিকিউশন সফলভাবে সম্পন্ন হয়েছে।
OUTCOME_FAILED কোড এক্সিকিউশন শেষ হয়েছে তবে ব্যর্থতার সাথে। stderr কারণ থাকা উচিত।
OUTCOME_DEADLINE_EXCEEDED কোড এক্সিকিউশন খুব দীর্ঘ সময় ধরে চলেছিল, এবং বাতিল করা হয়েছিল। আংশিক আউটপুট উপস্থিত থাকতে পারে বা নাও থাকতে পারে।

টুল

সরঞ্জামের বিবরণ যা মডেলটি প্রতিক্রিয়া তৈরি করতে ব্যবহার করতে পারে।

একটি Tool হ'ল কোডের একটি অংশ যা সিস্টেমকে জ্ঞান এবং মডেলের সুযোগের বাইরে কোনও ক্রিয়া বা ক্রিয়া সেট করতে বাহ্যিক সিস্টেমগুলির সাথে ইন্টারঅ্যাক্ট করতে সক্ষম করে।

ক্ষেত্র
functionDeclarations[] object ( FunctionDeclaration )

ঐচ্ছিক। ফাংশন কলিংয়ের জন্য ব্যবহার করা যেতে পারে এমন মডেলটির জন্য উপলব্ধ FunctionDeclarations একটি তালিকা।

মডেল বা সিস্টেম ফাংশনটি কার্যকর করে না। পরিবর্তে সংজ্ঞায়িত ফাংশনটি কার্যকর করার জন্য ক্লায়েন্টের পক্ষে যুক্তি সহ একটি FunctionCall হিসাবে ফিরে আসতে পারে। মডেলটি প্রতিক্রিয়াতে FunctionCall পপুলেট করে এই ফাংশনগুলির একটি সাবসেট কল করার সিদ্ধান্ত নিতে পারে। পরবর্তী কথোপকথনের টার্নটিতে Content.role সাথে একটি FunctionResponse থাকতে পারে ole পরবর্তী মডেল টার্নের জন্য "ফাংশন" প্রজন্মের প্রসঙ্গ।

googleSearchRetrieval object ( GoogleSearchRetrieval )

ঐচ্ছিক। পুনরুদ্ধার সরঞ্জাম যা গুগল অনুসন্ধান দ্বারা চালিত।

codeExecution object ( CodeExecution )

ঐচ্ছিক। প্রজন্মের অংশ হিসাবে কোড কার্যকর করতে মডেলটিকে সক্ষম করে।

JSON প্রতিনিধিত্ব
{
  "functionDeclarations": [
    {
      object (FunctionDeclaration)
    }
  ],
  "googleSearchRetrieval": {
    object (GoogleSearchRetrieval)
  },
  "codeExecution": {
    object (CodeExecution)
  },
  "googleSearch": {
    object (GoogleSearch)
  }
}

ফাংশন ঘোষণা

ওপেনএপিআই 3.03 স্পেসিফিকেশন দ্বারা সংজ্ঞায়িত হিসাবে একটি ফাংশন ঘোষণার কাঠামোগত উপস্থাপনা। এই ঘোষণায় অন্তর্ভুক্ত হ'ল ফাংশন নাম এবং পরামিতি। এই ফাংশনডেক্লারেশন হ'ল কোডের একটি ব্লকের প্রতিনিধিত্ব যা মডেল দ্বারা Tool হিসাবে ব্যবহার করা যেতে পারে এবং ক্লায়েন্ট দ্বারা সম্পাদিত হতে পারে।

ক্ষেত্র
name string

প্রয়োজন। ফাংশনের নাম। অবশ্যই এজেড, এজেড, 0-9 হতে হবে বা সর্বাধিক দৈর্ঘ্য 63 সহ আন্ডারস্কোর এবং ড্যাশ থাকতে পারে।

description string

প্রয়োজন। ফাংশন একটি সংক্ষিপ্ত বিবরণ।

parameters object ( Schema )

ঐচ্ছিক। এই ফাংশনের পরামিতিগুলি বর্ণনা করে। ওপেন এপিআই 3.03 প্যারামিটার অবজেক্ট স্ট্রিং কী প্রতিফলিত করে: প্যারামিটারের নাম। প্যারামিটারের নামগুলি কেস সংবেদনশীল৷ স্কিমা মান: স্কিমা প্যারামিটারের জন্য ব্যবহৃত প্রকারটি সংজ্ঞায়িত করে।

response object ( Schema )

ঐচ্ছিক। জেএসএন স্কিমা ফর্ম্যাটে এই ফাংশন থেকে আউটপুট বর্ণনা করে। ওপেন এপিআই 3.03 প্রতিক্রিয়া অবজেক্টটি প্রতিফলিত করে। স্কিমা ফাংশনের প্রতিক্রিয়া মানের জন্য ব্যবহৃত প্রকারটি সংজ্ঞায়িত করে।

JSON প্রতিনিধিত্ব
{
  "name": string,
  "description": string,
  "parameters": {
    object (Schema)
  },
  "response": {
    object (Schema)
  }
}

স্কিমা

Schema অবজেক্টটি ইনপুট এবং আউটপুট ডেটা প্রকারের সংজ্ঞা দেয়। এই ধরনের বস্তু হতে পারে, কিন্তু আদিম এবং অ্যারেও হতে পারে। একটি ওপেনাপি 3.0 স্কিমা অবজেক্টের একটি নির্বাচিত সাবসেট উপস্থাপন করে।

ক্ষেত্র
type enum ( Type )

প্রয়োজন। ডেটা টাইপ।

format string

ঐচ্ছিক। ডেটা ফর্ম্যাট। এটি কেবল আদিম ডেটাটাইপগুলির জন্য ব্যবহৃত হয়। সমর্থিত ফর্ম্যাটগুলি: সংখ্যার প্রকারের জন্য: ভাসমান, পূর্ণসংখ্যার জন্য ডাবল: আইএনটি 32, স্ট্রিং প্রকারের জন্য INT64: এনাম, তারিখ-সময়

title string

ঐচ্ছিক। স্কিমার শিরোনাম।

description string

ঐচ্ছিক। পরামিতি একটি সংক্ষিপ্ত বিবরণ. এটি ব্যবহারের উদাহরণ থাকতে পারে। প্যারামিটারের বিবরণ মার্কডাউন হিসাবে ফর্ম্যাট করা যেতে পারে।

nullable boolean

ঐচ্ছিক। মানটি বাতিল হতে পারে কিনা তা নির্দেশ করে।

enum[] string

ঐচ্ছিক। এনাম ফর্ম্যাট সহ প্রকারের উপাদানগুলির সম্ভাব্য মানগুলি। উদাহরণস্বরূপ আমরা একটি এনাম দিকনির্দেশ হিসাবে সংজ্ঞায়িত করতে পারি: {প্রকার: স্ট্রিং, ফর্ম্যাট: এনাম, এনাম: ["পূর্ব", উত্তর "," দক্ষিণ "," পশ্চিম "]}

maxItems string ( int64 format)

ঐচ্ছিক। টাইপ.আরাইয়ের জন্য উপাদানগুলির সর্বাধিক সংখ্যা।

minItems string ( int64 format)

ঐচ্ছিক। টাইপ.আরাইয়ের জন্য উপাদানগুলির সর্বনিম্ন সংখ্যা।

properties map (key: string, value: object ( Schema ))

ঐচ্ছিক। টাইপ.অবজেক্টের বৈশিষ্ট্য।

"key": value জোড়। উদাহরণ: { "name": "wrench", "mass": "1.3kg", "count": "3" }

required[] string

ঐচ্ছিক। টাইপ.অবজেক্টের প্রয়োজনীয় বৈশিষ্ট্য।

minProperties string ( int64 format)

ঐচ্ছিক। টাইপ.অবজেক্টের জন্য সম্পত্তিগুলির সর্বনিম্ন সংখ্যা।

maxProperties string ( int64 format)

ঐচ্ছিক। টাইপ.অবজেক্টের জন্য বৈশিষ্ট্যগুলির সর্বাধিক সংখ্যা।

minLength string ( int64 format)

ঐচ্ছিক। টাইপ স্ট্রিং এর জন্য স্কিমা ক্ষেত্রগুলি টাইপের ন্যূনতম দৈর্ঘ্য.স্ট্রিং

maxLength string ( int64 format)

ঐচ্ছিক। টাইপ.স্ট্রিংয়ের সর্বাধিক দৈর্ঘ্য

pattern string

Al চ্ছিক। একটি স্ট্রিংকে নিয়মিত প্রকাশের মধ্যে সীমাবদ্ধ করতে টাইপের প্যাটার্ন।

example value ( Value format)

ঐচ্ছিক। বস্তুর উদাহরণ। কেবল তখনই পপুলেট হবে যখন বস্তুটি মূল হয়।

anyOf[] object ( Schema )

Al চ্ছিক। তালিকার সাবমেমার যে কোনও (এক বা একাধিক) এর বিরুদ্ধে মানটি বৈধ করা উচিত।

propertyOrdering[] string

Al চ্ছিক। সম্পত্তি অর্ডার। ওপেন এপিআই স্পেসে কোনও স্ট্যান্ডার্ড ক্ষেত্র নয়। প্রতিক্রিয়াতে বৈশিষ্ট্যগুলির ক্রম নির্ধারণ করতে ব্যবহৃত হয়।

default value ( Value format)

Al চ্ছিক। ক্ষেত্রের ডিফল্ট মান। জেএসএন স্কিমা অনুযায়ী, এই ক্ষেত্রটি ডকুমেন্টেশন জেনারেটরগুলির জন্য তৈরি এবং বৈধতা প্রভাবিত করে না। সুতরাং এটি এখানে অন্তর্ভুক্ত রয়েছে এবং উপেক্ষা করা হয়েছে যাতে বিকাশকারীরা যারা default ক্ষেত্রের সাথে স্কিমা প্রেরণ করেন তারা অজানা-ক্ষেত্রের ত্রুটিগুলি পান না।

items object ( Schema )

Al চ্ছিক। টাইপ.আরাইয়ের উপাদানগুলির স্কিমা।

minimum number

Al চ্ছিক। টাইপ পূর্ণসংখ্যার জন্য স্কিমা ক্ষেত্রগুলি এবং প্রকারের ন্যূনতম মান এবং প্রকারের ন্যূনতম মান।

maximum number

Al চ্ছিক। প্রকারের সর্বাধিক মান।

JSON প্রতিনিধিত্ব
{
  "type": enum (Type),
  "format": string,
  "title": string,
  "description": string,
  "nullable": boolean,
  "enum": [
    string
  ],
  "maxItems": string,
  "minItems": string,
  "properties": {
    string: {
      object (Schema)
    },
    ...
  },
  "required": [
    string
  ],
  "minProperties": string,
  "maxProperties": string,
  "minLength": string,
  "maxLength": string,
  "pattern": string,
  "example": value,
  "anyOf": [
    {
      object (Schema)
    }
  ],
  "propertyOrdering": [
    string
  ],
  "default": value,
  "items": {
    object (Schema)
  },
  "minimum": number,
  "maximum": number
}

টাইপ

টাইপটিতে https://spec.openapis.org/oas/v3.0.3#data- টাইপস দ্বারা সংজ্ঞায়িত ওপেনাপি ডেটা প্রকারের তালিকা রয়েছে

Enums
TYPE_UNSPECIFIED নির্দিষ্ট করা হয়নি, ব্যবহার করা উচিত নয়।
STRING স্ট্রিং টাইপ।
NUMBER সংখ্যা প্রকার।
INTEGER পূর্ণসংখ্যার ধরণ।
BOOLEAN বুলিয়ান প্রকার।
ARRAY অ্যারে টাইপ।
OBJECT বস্তুর ধরন।
NULL নাল টাইপ।

GoogleSearch Retrieval

গুগল দ্বারা চালিত গ্রাউন্ডিংয়ের জন্য পাবলিক ওয়েব ডেটা পুনরুদ্ধার করার সরঞ্জাম।

ক্ষেত্র
dynamicRetrievalConfig object ( DynamicRetrievalConfig )

প্রদত্ত উত্সটির জন্য গতিশীল পুনরুদ্ধার কনফিগারেশন নির্দিষ্ট করে।

JSON প্রতিনিধিত্ব
{
  "dynamicRetrievalConfig": {
    object (DynamicRetrievalConfig)
  }
}

DynamicRetrievalConfig

গতিশীল পুনরুদ্ধার কাস্টমাইজ করার বিকল্পগুলি বর্ণনা করে।

ক্ষেত্র
mode enum ( Mode )

গতিশীল পুনরুদ্ধারে ব্যবহার করার জন্য ভবিষ্যদ্বাণীকারীর মোড।

dynamicThreshold number

গতিশীল পুনরুদ্ধারে ব্যবহৃত প্রান্তিকতা। যদি সেট না করা হয় তবে একটি সিস্টেম ডিফল্ট মান ব্যবহৃত হয়।

JSON প্রতিনিধিত্ব
{
  "mode": enum (Mode),
  "dynamicThreshold": number
}

মোড

গতিশীল পুনরুদ্ধারে ব্যবহার করার জন্য ভবিষ্যদ্বাণীকারীর মোড।

Enums
MODE_UNSPECIFIED সর্বদা পুনরুদ্ধার ট্রিগার।
MODE_DYNAMIC সিস্টেমটি যখন সিদ্ধান্ত নেয় তখনই পুনরুদ্ধার চালান।

কোডেক্সিকিউশন

এই ধরণের কোনও ক্ষেত্র নেই।

সরঞ্জাম যা মডেল দ্বারা উত্পাদিত কোড কার্যকর করে এবং স্বয়ংক্রিয়ভাবে ফলাফলটি মডেলটিতে ফিরিয়ে দেয়।

ExecutableCode এবং CodeExecutionResult দেখুন যা কেবল এই সরঞ্জামটি ব্যবহার করার সময় উত্পন্ন হয়।

গুগল সার্চ

এই ধরণের কোনও ক্ষেত্র নেই।

গুগলস অনুসন্ধান সরঞ্জাম প্রকার। মডেলটিতে গুগল অনুসন্ধান সমর্থন করার সরঞ্জাম। গুগল দ্বারা চালিত.

টুল কনফিগারেশন

অনুরোধে Tool ব্যবহার নির্দিষ্ট করার জন্য প্যারামিটারযুক্ত সরঞ্জাম কনফিগারেশন।

ক্ষেত্র
functionCallingConfig object ( FunctionCallingConfig )

Al চ্ছিক। ফাংশন কলিং কনফিগারেশন।

JSON প্রতিনিধিত্ব
{
  "functionCallingConfig": {
    object (FunctionCallingConfig)
  }
}

FunctionCallingConfig

ফাংশন কলিং আচরণ নির্দিষ্ট করার জন্য কনফিগারেশন।

ক্ষেত্র
mode enum ( Mode )

Al চ্ছিক। ফাংশন কলিং কার্যকর করা উচিত এমন মোডটি নির্দিষ্ট করে। যদি অনির্ধারিত হয় তবে ডিফল্ট মানটি অটোতে সেট করা হবে।

allowedFunctionNames[] string

Al চ্ছিক। ফাংশন নামগুলির একটি সেট যা সরবরাহ করা হলে মডেলটি কল করবে এমন ফাংশনগুলিকে সীমাবদ্ধ করে।

এটি কেবল তখনই সেট করা উচিত যখন মোডটি থাকে। ফাংশনের নামগুলি মেলে [ফাংশনডেক্লারেশন.নাম]। মোড যে কোনওটিতে সেট করে, মডেল প্রদত্ত ফাংশন নামগুলির সেট থেকে একটি ফাংশন কলের পূর্বাভাস দেবে।

JSON প্রতিনিধিত্ব
{
  "mode": enum (Mode),
  "allowedFunctionNames": [
    string
  ]
}

মোড

এক্সিকিউশন মোডটি সংজ্ঞায়িত করে ফাংশন কলিংয়ের জন্য এক্সিকিউশন আচরণকে সংজ্ঞায়িত করে।

Enums
MODE_UNSPECIFIED অনির্ধারিত ফাংশন কলিং মোড। এই মানটি ব্যবহার করা উচিত নয়।
AUTO ডিফল্ট মডেল আচরণ, মডেল কোনও ফাংশন কল বা প্রাকৃতিক ভাষার প্রতিক্রিয়া পূর্বাভাস দেওয়ার সিদ্ধান্ত নেয়।
ANY মডেল সর্বদা কেবল একটি ফাংশন কল পূর্বাভাস দিতে বাধ্য। যদি "অনুমোদিত ফাংশননামস" সেট করা থাকে তবে পূর্বাভাসিত ফাংশন কলটি "অনুমোদিত ফাংশন নামগুলি" এর মধ্যে সীমাবদ্ধ থাকবে, অন্যথায় পূর্বাভাসিত ফাংশন কলটি সরবরাহিত "ফাংশনডিক্লারেশনস" এর কোনও একটি হবে।
NONE মডেল কোনও ফাংশন কল পূর্বাভাস দেবে না। কোনও ফাংশন ঘোষণা পাস না করার সময় মডেল আচরণটি একই।
VALIDATED মডেল কোনও ফাংশন কল বা প্রাকৃতিক ভাষার প্রতিক্রিয়ার পূর্বাভাস দেওয়ার সিদ্ধান্ত নিয়েছে, তবে সীমাবদ্ধ ডিকোডিংয়ের সাথে ফাংশন কলগুলি বৈধ করবে।

মেটাডেটা ব্যবহার

ক্যাশেড সামগ্রী ব্যবহারের উপর মেটাডেটা।

ক্ষেত্র
totalTokenCount integer

ক্যাশেড সামগ্রী যে মোট টোকেন গ্রহণ করে।

JSON প্রতিনিধিত্ব
{
  "totalTokenCount": integer
}
,

প্রসঙ্গে ক্যাচিং আপনাকে বারবার ব্যবহার করতে চান এমন প্রাকপম্পিউটেড ইনপুট টোকেনগুলি সংরক্ষণ এবং পুনরায় ব্যবহার করতে দেয়, উদাহরণস্বরূপ একই মিডিয়া ফাইল সম্পর্কে বিভিন্ন প্রশ্ন জিজ্ঞাসা করার সময়। এটি ব্যবহারের উপর নির্ভর করে ব্যয় এবং গতি সাশ্রয় হতে পারে। বিশদ পরিচিতির জন্য, প্রসঙ্গে ক্যাচিং গাইড দেখুন।

পদ্ধতি: ক্যাশেডকন্টেন্টস.ক্রিয়েট

ক্যাশেড কনটেন্ট রিসোর্স তৈরি করে।

শেষবিন্দু

পোস্ট https: / /generativelanguage.googleapis.com /v1beta /cachedContents

শরীরের অনুরোধ

অনুরোধ বডিটিতে CachedContent একটি উদাহরণ রয়েছে।

ক্ষেত্র
contents[] object ( Content )

Al চ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। ক্যাশে সামগ্রী।

tools[] object ( Tool )

Al চ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। মডেলটি পরবর্তী প্রতিক্রিয়া উত্পন্ন করতে Tools ব্যবহার করতে পারে এমন একটি তালিকা

expiration Union type
এই সংস্থানটি কখন শেষ হবে তা নির্দিষ্ট করে। expiration নিম্নলিখিতগুলির মধ্যে একটি হতে পারে:
expireTime string ( Timestamp format)

ইউটিসিতে টাইমস্ট্যাম্প যখন এই সংস্থানটি মেয়াদোত্তীর্ণ হিসাবে বিবেচিত হয়। ইনপুটটিতে যা প্রেরণ করা হয়েছিল তা নির্বিশেষে এটি সর্বদা আউটপুটে সরবরাহ করা হয়।

আরএফসি 3339 ব্যবহার করে, যেখানে উত্পন্ন আউটপুট সর্বদা জেড-সাধারণীকরণ করা হবে এবং 0, 3, 6 বা 9 ভগ্নাংশের সংখ্যা ব্যবহার করে। "জেড" ব্যতীত অন্যান্য অফসেটগুলিও গৃহীত হয়। উদাহরণ: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" বা "2014-10-02T15:01:23+05:30"

ttl string ( Duration format)

শুধুমাত্র ইনপুট। এই সংস্থানটির জন্য নতুন টিটিএল, কেবল ইনপুট।

' s ' দিয়ে শেষ হওয়া নয়টি ভগ্নাংশের সংখ্যা সহ সেকেন্ডে একটি সময়কাল। উদাহরণ: "3.5s"

displayName string

Al চ্ছিক। অপরিবর্তনীয়। ক্যাশেড সামগ্রীর ব্যবহারকারী-উত্পাদিত অর্থপূর্ণ ডিসপ্লে নাম। সর্বাধিক 128 ইউনিকোড অক্ষর।

model string

প্রয়োজন। অপরিবর্তনীয়। ক্যাশেড সামগ্রী ফর্ম্যাটের জন্য Model নাম: models/{model}

systemInstruction object ( Content )

Al চ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। বিকাশকারী সেট সিস্টেম নির্দেশ। বর্তমানে কেবল পাঠ্য।

toolConfig object ( ToolConfig )

Al চ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। সরঞ্জাম কনফিগারেশন। এই কনফিগারেশনটি সমস্ত সরঞ্জামের জন্য ভাগ করা হয়েছে।

উদাহরণ অনুরোধ

from google import genai
from google.genai import types

client = genai.Client()
document = client.files.upload(file=media / "a11.txt")
model_name = "gemini-1.5-flash-001"

cache = client.caches.create(
    model=model_name,
    config=types.CreateCachedContentConfig(
        contents=[document],
        system_instruction="You are an expert analyzing transcripts.",
    ),
)
print(cache)

response = client.models.generate_content(
    model=model_name,
    contents="Please summarize this transcript",
    config=types.GenerateContentConfig(cached_content=cache.name),
)
print(response.text)
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);
const modelName = "gemini-1.5-flash-001";

const contents = [
  createUserContent(createPartFromUri(document.uri, document.mimeType)),
];

const cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: contents,
    systemInstruction: "You are an expert analyzing transcripts.",
  },
});
console.log("Cache created:", cache);

const response = await ai.models.generateContent({
  model: modelName,
  contents: "Please summarize this transcript",
  config: { cachedContent: cache.name },
});
console.log("Response text:", response.text);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"), 
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}
parts := []*genai.Part{
	genai.NewPartFromURI(document.URI, document.MIMEType),
}
contents := []*genai.Content{
	genai.NewContentFromParts(parts, "user"),
}
cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents: contents,
	SystemInstruction: genai.NewContentFromText(
		"You are an expert analyzing transcripts.", "user",
	),
})
if err != nil {
	log.Fatal(err)
}
fmt.Println("Cache created:")
fmt.Println(cache)

// Use the cache for generating content.
response, err := client.Models.GenerateContent(
	ctx,
	modelName,
	genai.Text("Please summarize this transcript"),
	&genai.GenerateContentConfig{
		CachedContent: cache.Name,
	},
)
if err != nil {
	log.Fatal(err)
}
printResponse(response)
wget https://storage.googleapis.com/generativeai-downloads/data/a11.txt
echo '{
  "model": "models/gemini-1.5-flash-001",
  "contents":[
    {
      "parts":[
        {
          "inline_data": {
            "mime_type":"text/plain",
            "data": "'$(base64 $B64FLAGS a11.txt)'"
          }
        }
      ],
    "role": "user"
    }
  ],
  "systemInstruction": {
    "parts": [
      {
        "text": "You are an expert at analyzing transcripts."
      }
    ]
  },
  "ttl": "300s"
}' > request.json

curl -X POST "https://generativelanguage.googleapis.com/v1beta/cachedContents?key=$GEMINI_API_KEY" \
 -H 'Content-Type: application/json' \
 -d @request.json \
 > cache.json

CACHE_NAME=$(cat cache.json | grep '"name":' | cut -d '"' -f 4 | head -n 1)

curl -X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-001:generateContent?key=$GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
      "contents": [
        {
          "parts":[{
            "text": "Please summarize this transcript"
          }],
          "role": "user"
        },
      ],
      "cachedContent": "'$CACHE_NAME'"
    }'
from google import genai
from google.genai import types

client = genai.Client()
document = client.files.upload(file=media / "a11.txt")
model_name = "gemini-1.5-flash-001"

cache = client.caches.create(
    model=model_name,
    config=types.CreateCachedContentConfig(
        contents=[document],
        system_instruction="You are an expert analyzing transcripts.",
    ),
)
cache_name = cache.name  # Save the name for later

# Later retrieve the cache
cache = client.caches.get(name=cache_name)
response = client.models.generate_content(
    model=model_name,
    contents="Find a lighthearted moment from this transcript",
    config=types.GenerateContentConfig(cached_content=cache.name),
)
print(response.text)
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);
const modelName = "gemini-1.5-flash-001";

const contents = [
  createUserContent(createPartFromUri(document.uri, document.mimeType)),
];

const cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: contents,
    systemInstruction: "You are an expert analyzing transcripts.",
  },
});
const cacheName = cache.name; // Save the name for later

// Later retrieve the cache
const retrievedCache = await ai.caches.get({ name: cacheName });
const response = await ai.models.generateContent({
  model: modelName,
  contents: "Find a lighthearted moment from this transcript",
  config: { cachedContent: retrievedCache.name },
});
console.log("Response text:", response.text);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"),
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}
parts := []*genai.Part{
	genai.NewPartFromURI(document.URI, document.MIMEType),
}
contents := []*genai.Content{
	genai.NewContentFromParts(parts, "user"),
}
cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents:          contents,
	SystemInstruction: genai.NewContentFromText(
		"You are an expert analyzing transcripts.", "user",
	),
})
if err != nil {
	log.Fatal(err)
}
cacheName := cache.Name

// Later retrieve the cache.
cache, err = client.Caches.Get(ctx, cacheName, &genai.GetCachedContentConfig{})
if err != nil {
	log.Fatal(err)
}

response, err := client.Models.GenerateContent(
	ctx,
	modelName,
	genai.Text("Find a lighthearted moment from this transcript"),
	&genai.GenerateContentConfig{
		CachedContent: cache.Name,
	},
)
if err != nil {
	log.Fatal(err)
}
fmt.Println("Response from cache (create from name):")
printResponse(response)
from google import genai
from google.genai import types

client = genai.Client()
model_name = "gemini-1.5-flash-001"
system_instruction = "You are an expert analyzing transcripts."

# Create a chat session with the given system instruction.
chat = client.chats.create(
    model=model_name,
    config=types.GenerateContentConfig(system_instruction=system_instruction),
)
document = client.files.upload(file=media / "a11.txt")

response = chat.send_message(
    message=["Hi, could you summarize this transcript?", document]
)
print("\n\nmodel:  ", response.text)
response = chat.send_message(
    message=["Okay, could you tell me more about the trans-lunar injection"]
)
print("\n\nmodel:  ", response.text)

# To cache the conversation so far, pass the chat history as the list of contents.
cache = client.caches.create(
    model=model_name,
    config={
        "contents": chat.get_history(),
        "system_instruction": system_instruction,
    },
)
# Continue the conversation using the cached content.
chat = client.chats.create(
    model=model_name,
    config=types.GenerateContentConfig(cached_content=cache.name),
)
response = chat.send_message(
    message="I didn't understand that last part, could you explain it in simpler language?"
)
print("\n\nmodel:  ", response.text)
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const modelName = "gemini-1.5-flash-001";
const systemInstruction = "You are an expert analyzing transcripts.";

// Create a chat session with the system instruction.
const chat = ai.chats.create({
  model: modelName,
  config: { systemInstruction: systemInstruction },
});
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);

let response = await chat.sendMessage({
  message: createUserContent([
    "Hi, could you summarize this transcript?",
    createPartFromUri(document.uri, document.mimeType),
  ]),
});
console.log("\n\nmodel:", response.text);

response = await chat.sendMessage({
  message: "Okay, could you tell me more about the trans-lunar injection",
});
console.log("\n\nmodel:", response.text);

// To cache the conversation so far, pass the chat history as the list of contents.
const chatHistory = chat.getHistory();
const cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: chatHistory,
    systemInstruction: systemInstruction,
  },
});

// Continue the conversation using the cached content.
const chatWithCache = ai.chats.create({
  model: modelName,
  config: { cachedContent: cache.name },
});
response = await chatWithCache.sendMessage({
  message:
    "I didn't understand that last part, could you explain it in simpler language?",
});
console.log("\n\nmodel:", response.text);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"),
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
systemInstruction := "You are an expert analyzing transcripts."

// Create initial chat with a system instruction.
chat, err := client.Chats.Create(ctx, modelName, &genai.GenerateContentConfig{
	SystemInstruction: genai.NewContentFromText(systemInstruction, "user"),
}, nil)
if err != nil {
	log.Fatal(err)
}

document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}

// Send first message with the transcript.
parts := make([]genai.Part, 2)
parts[0] = genai.Part{Text: "Hi, could you summarize this transcript?"}
parts[1] = genai.Part{
	FileData: &genai.FileData{
		FileURI :      document.URI,
		MIMEType: document.MIMEType,
	},
}

// Send chat message.
resp, err := chat.SendMessage(ctx, parts...)
if err != nil {
	log.Fatal(err)
}
fmt.Println("\n\nmodel: ", resp.Text())

resp, err = chat.SendMessage(
	ctx, 
	genai.Part{
		Text: "Okay, could you tell me more about the trans-lunar injection",
	},
)
if err != nil {
	log.Fatal(err)
}
fmt.Println("\n\nmodel: ", resp.Text())

// To cache the conversation so far, pass the chat history as the list of contents.
cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents:          chat.History(false),
	SystemInstruction: genai.NewContentFromText(systemInstruction, "user"),
})
if err != nil {
	log.Fatal(err)
}

// Continue the conversation using the cached history.
chat, err = client.Chats.Create(ctx, modelName, &genai.GenerateContentConfig{
	CachedContent: cache.Name,
}, nil)
if err != nil {
	log.Fatal(err)
}

resp, err = chat.SendMessage(
	ctx, 
	genai.Part{
		Text: "I didn't understand that last part, could you explain it in simpler language?",
	},
)
if err != nil {
	log.Fatal(err)
}
fmt.Println("\n\nmodel: ", resp.Text())

প্রতিক্রিয়া শরীর

যদি সফল হয় তবে প্রতিক্রিয়া বডিটিতে CachedContent একটি নতুন তৈরি উদাহরণ রয়েছে।

পদ্ধতি: ক্যাশেড কনটেন্টস.লিস্ট

ক্যাশেড কনটেন্টগুলি তালিকা করে।

শেষবিন্দু

https: / /generativelanguage.googleapis.com /v1beta /cachedContents পান

ক্যোয়ারী প্যারামিটার

pageSize integer

Al চ্ছিক। প্রত্যাবর্তনের জন্য সর্বাধিক সংখ্যক ক্যাশেড সামগ্রী। পরিষেবাটি এই মানের চেয়ে কম ফিরে আসতে পারে। যদি অনির্ধারিত হয় তবে কিছু ডিফল্ট (সর্বাধিক নিচে) আইটেমের সংখ্যা ফিরে আসবে। সর্বাধিক মান 1000; 1000 এর উপরে মানগুলি 1000 এ জোর করা হবে।

pageToken string

Al চ্ছিক। একটি পৃষ্ঠা টোকেন, পূর্ববর্তী cachedContents.list কল থেকে প্রাপ্ত। পরবর্তী পৃষ্ঠাটি পুনরুদ্ধার করতে এটি সরবরাহ করুন।

প্যাগিনেট করার সময়, cachedContents.list সরবরাহ করা অন্যান্য সমস্ত পরামিতি.লিস্ট অবশ্যই কলটির সাথে মেলে যা পৃষ্ঠাটি টোকেন সরবরাহ করে।

শরীরের অনুরোধ

অনুরোধের বডি খালি হতে হবে।

প্রতিক্রিয়া শরীর

ক্যাশেড কনটেন্টেন্টস তালিকার সাথে প্রতিক্রিয়া।

যদি সফল হয় তবে প্রতিক্রিয়া বডিটিতে নিম্নলিখিত কাঠামোর সাথে ডেটা রয়েছে:

ক্ষেত্র
cachedContents[] object ( CachedContent )

ক্যাশেড সামগ্রীগুলির তালিকা।

nextPageToken string

একটি টোকেন, যা পরবর্তী পৃষ্ঠাটি পুনরুদ্ধার করতে pageToken হিসাবে প্রেরণ করা যেতে পারে। যদি এই ক্ষেত্রটি বাদ দেওয়া হয় তবে পরবর্তী কোনও পৃষ্ঠা নেই।

JSON প্রতিনিধিত্ব
{
  "cachedContents": [
    {
      object (CachedContent)
    }
  ],
  "nextPageToken": string
}

পদ্ধতি: ক্যাশেড কনটেন্টস.জেট

ক্যাশেড কনটেন্ট রিসোর্স পড়ে।

শেষবিন্দু

https: / /generativelanguage.googleapis.com /v1beta /{name=cachedContents /*} পান

পাথ প্যারামিটার

name string

প্রয়োজন। সামগ্রীর ক্যাশে প্রবেশের উল্লেখ করে রিসোর্সের নাম। ফর্ম্যাট: cachedContents/{id} এটি ফর্ম cachedContents/{cachedcontent} নেয়}

শরীরের অনুরোধ

অনুরোধের বডি খালি হতে হবে।

উদাহরণ অনুরোধ

from google import genai

client = genai.Client()
document = client.files.upload(file=media / "a11.txt")
model_name = "gemini-1.5-flash-001"

cache = client.caches.create(
    model=model_name,
    config={
        "contents": [document],
        "system_instruction": "You are an expert analyzing transcripts.",
    },
)
print(client.caches.get(name=cache.name))
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);
const modelName = "gemini-1.5-flash-001";

const contents = [
  createUserContent(createPartFromUri(document.uri, document.mimeType)),
];

const cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: contents,
    systemInstruction: "You are an expert analyzing transcripts.",
  },
});
const retrievedCache = await ai.caches.get({ name: cache.name });
console.log("Retrieved Cache:", retrievedCache);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"),
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}
parts := []*genai.Part{
	genai.NewPartFromURI(document.URI, document.MIMEType),
}
contents := []*genai.Content{
	genai.NewContentFromParts(parts, "user"),
}

cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents:          contents,
	SystemInstruction: genai.NewContentFromText(
		"You are an expert analyzing transcripts.", "user",
	),
})
if err != nil {
	log.Fatal(err)
}

cache, err = client.Caches.Get(ctx, cache.Name, &genai.GetCachedContentConfig{})
if err != nil {
	log.Fatal(err)
}
fmt.Println("Retrieved cache:")
fmt.Println(cache)
curl "https://generativelanguage.googleapis.com/v1beta/$CACHE_NAME?key=$GEMINI_API_KEY"

প্রতিক্রিয়া শরীর

যদি সফল হয় তবে প্রতিক্রিয়া বডিটিতে CachedContent একটি উদাহরণ রয়েছে।

পদ্ধতি: ক্যাশেড কনটেন্টস.প্যাচ

আপডেটগুলি ক্যাশেড কনটেন্ট রিসোর্স (কেবলমাত্র মেয়াদ শেষ হওয়া আপডেটযোগ্য)।

শেষবিন্দু

প্যাচ https: / /generativelanguage.googleapis.com /v1beta /{cachedContent.name=cachedContents /*}
PATCH https://generativelanguage.googleapis.com/v1beta/{cachedContent.name=cachedContents/*}

পাথ প্যারামিটার

cachedContent.name string

শুধুমাত্র আউটপুট। সনাক্তকারী ক্যাশেড সামগ্রী উল্লেখ করে রিসোর্সের নাম। ফর্ম্যাট: cachedContents/{id} এটি ফর্ম cachedContents/{cachedcontent} নেয়}

ক্যোয়ারী প্যারামিটার

updateMask string ( FieldMask format)

আপডেট করার জন্য ক্ষেত্রগুলির তালিকা।

এটি ক্ষেত্রগুলির সম্পূর্ণরূপে যোগ্য নামগুলির একটি কমা-বিচ্ছিন্ন তালিকা। উদাহরণ: "user.displayName,photo"

শরীরের অনুরোধ

অনুরোধ বডিটিতে CachedContent একটি উদাহরণ রয়েছে।

ক্ষেত্র
expiration Union type
এই সংস্থানটি কখন শেষ হবে তা নির্দিষ্ট করে। expiration নিম্নলিখিতগুলির মধ্যে একটি হতে পারে:
expireTime string ( Timestamp format)

ইউটিসিতে টাইমস্ট্যাম্প যখন এই সংস্থানটি মেয়াদোত্তীর্ণ হিসাবে বিবেচিত হয়। ইনপুটটিতে যা প্রেরণ করা হয়েছিল তা নির্বিশেষে এটি সর্বদা আউটপুটে সরবরাহ করা হয়।

আরএফসি 3339 ব্যবহার করে, যেখানে উত্পন্ন আউটপুট সর্বদা জেড-সাধারণীকরণ করা হবে এবং 0, 3, 6 বা 9 ভগ্নাংশের সংখ্যা ব্যবহার করে। "জেড" ব্যতীত অন্যান্য অফসেটগুলিও গৃহীত হয়। উদাহরণ: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" বা "2014-10-02T15:01:23+05:30"

ttl string ( Duration format)

শুধুমাত্র ইনপুট। এই সংস্থানটির জন্য নতুন টিটিএল, কেবল ইনপুট।

' s ' দিয়ে শেষ হওয়া নয়টি ভগ্নাংশের সংখ্যা সহ সেকেন্ডে একটি সময়কাল। উদাহরণ: "3.5s"

উদাহরণ অনুরোধ

from google import genai
from google.genai import types
import datetime

client = genai.Client()
document = client.files.upload(file=media / "a11.txt")
model_name = "gemini-1.5-flash-001"

cache = client.caches.create(
    model=model_name,
    config={
        "contents": [document],
        "system_instruction": "You are an expert analyzing transcripts.",
    },
)

# Update the cache's time-to-live (ttl)
ttl = f"{int(datetime.timedelta(hours=2).total_seconds())}s"
client.caches.update(
    name=cache.name, config=types.UpdateCachedContentConfig(ttl=ttl)
)
print(f"After update:\n {cache}")

# Alternatively, update the expire_time directly
# Update the expire_time directly in valid RFC 3339 format (UTC with a "Z" suffix)
expire_time = (
    (
        datetime.datetime.now(datetime.timezone.utc)
        + datetime.timedelta(minutes=15)
    )
    .isoformat()
    .replace("+00:00", "Z")
)
client.caches.update(
    name=cache.name,
    config=types.UpdateCachedContentConfig(expire_time=expire_time),
)
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);
const modelName = "gemini-1.5-flash-001";

const contents = [
  createUserContent(createPartFromUri(document.uri, document.mimeType)),
];

let cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: contents,
    systemInstruction: "You are an expert analyzing transcripts.",
  },
});

// Update the cache's time-to-live (ttl)
const ttl = `${2 * 3600}s`; // 2 hours in seconds
cache = await ai.caches.update({
  name: cache.name,
  config: { ttl },
});
console.log("After update (TTL):", cache);

// Alternatively, update the expire_time directly (in RFC 3339 format with a "Z" suffix)
const expireTime = new Date(Date.now() + 15 * 60000)
  .toISOString()
  .replace(/\.\d{3}Z$/, "Z");
cache = await ai.caches.update({
  name: cache.name,
  config: { expireTime: expireTime },
});
console.log("After update (expire_time):", cache);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"),
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}
parts := []*genai.Part{
	genai.NewPartFromURI(document.URI, document.MIMEType),
}
contents := []*genai.Content{
	genai.NewContentFromParts(parts, "user"),
}

cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents:          contents,
	SystemInstruction: genai.NewContentFromText(
		"You are an expert analyzing transcripts.", "user",
	),
})
if err != nil {
	log.Fatal(err)
}

_, err = client.Caches.Delete(ctx, cache.Name, &genai.DeleteCachedContentConfig{})
if err != nil {
	log.Fatal(err)
}
fmt.Println("Cache deleted:", cache.Name)
curl -X PATCH "https://generativelanguage.googleapis.com/v1beta/$CACHE_NAME?key=$GEMINI_API_KEY" \
 -H 'Content-Type: application/json' \
 -d '{"ttl": "600s"}'

প্রতিক্রিয়া শরীর

যদি সফল হয় তবে প্রতিক্রিয়া বডিটিতে CachedContent একটি উদাহরণ রয়েছে।

পদ্ধতি: ক্যাশেডকন্টেন্টস.ডিলিট

ক্যাশেড কনটেন্ট রিসোর্স মুছে ফেলেছে।

শেষবিন্দু

https: / /generativelanguage.googleapis.com /v1beta /{name=cachedContents /*} মুছুন

পাথ প্যারামিটার

name string

প্রয়োজন। সামগ্রীর ক্যাশে প্রবেশের ফর্ম্যাটটি উল্লেখ করে রিসোর্স নাম: cachedContents/{id} এটি ফর্ম cachedContents/{cachedcontent} নেয়}

শরীরের অনুরোধ

অনুরোধের বডি খালি হতে হবে।

উদাহরণ অনুরোধ

from google import genai

client = genai.Client()
document = client.files.upload(file=media / "a11.txt")
model_name = "gemini-1.5-flash-001"

cache = client.caches.create(
    model=model_name,
    config={
        "contents": [document],
        "system_instruction": "You are an expert analyzing transcripts.",
    },
)
client.caches.delete(name=cache.name)
// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const filePath = path.join(media, "a11.txt");
const document = await ai.files.upload({
  file: filePath,
  config: { mimeType: "text/plain" },
});
console.log("Uploaded file name:", document.name);
const modelName = "gemini-1.5-flash-001";

const contents = [
  createUserContent(createPartFromUri(document.uri, document.mimeType)),
];

const cache = await ai.caches.create({
  model: modelName,
  config: {
    contents: contents,
    systemInstruction: "You are an expert analyzing transcripts.",
  },
});
await ai.caches.delete({ name: cache.name });
console.log("Cache deleted:", cache.name);
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:  os.Getenv("GEMINI_API_KEY"),
	Backend: genai.BackendGeminiAPI,
})
if err != nil {
	log.Fatal(err)
}

modelName := "gemini-1.5-flash-001"
document, err := client.Files.UploadFromPath(
	ctx, 
	filepath.Join(getMedia(), "a11.txt"), 
	&genai.UploadFileConfig{
		MIMEType : "text/plain",
	},
)
if err != nil {
	log.Fatal(err)
}
parts := []*genai.Part{
	genai.NewPartFromURI(document.URI, document.MIMEType),
}
contents := []*genai.Content{
	genai.NewContentFromParts(parts, "user"),
}

cache, err := client.Caches.Create(ctx, modelName, &genai.CreateCachedContentConfig{
	Contents:          contents,
	SystemInstruction: genai.NewContentFromText(
		"You are an expert analyzing transcripts.", "user",
	),
})
if err != nil {
	log.Fatal(err)
}

_, err = client.Caches.Delete(ctx, cache.Name, &genai.DeleteCachedContentConfig{})
if err != nil {
	log.Fatal(err)
}
fmt.Println("Cache deleted:", cache.Name)
curl -X DELETE "https://generativelanguage.googleapis.com/v1beta/$CACHE_NAME?key=$GEMINI_API_KEY"

প্রতিক্রিয়া শরীর

যদি সফল হয় তবে প্রতিক্রিয়া বডিটি একটি খালি JSON অবজেক্ট।

বিশ্রাম সংস্থান: ক্যাশেড কনটেন্টস

সংস্থান: ক্যাশেড কনটেন্ট

যে বিষয়বস্তু প্রাক -প্রসেস করা হয়েছে এবং পরবর্তীকালে জেনারেটর সার্ভিসে অনুরোধে ব্যবহার করা যেতে পারে।

ক্যাশেড সামগ্রী কেবল এটির জন্য তৈরি করা মডেল দিয়ে ব্যবহার করা যেতে পারে।

ক্ষেত্র
contents[] object ( Content )

Al চ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। ক্যাশে সামগ্রী।

tools[] object ( Tool )

Al চ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। মডেলটি পরবর্তী প্রতিক্রিয়া উত্পন্ন করতে Tools ব্যবহার করতে পারে এমন একটি তালিকা

createTime string ( Timestamp format)

শুধুমাত্র আউটপুট। ক্যাশে প্রবেশের তৈরির সময়।

আরএফসি 3339 ব্যবহার করে, যেখানে উত্পন্ন আউটপুট সর্বদা জেড-সাধারণীকরণ করা হবে এবং 0, 3, 6 বা 9 ভগ্নাংশের সংখ্যা ব্যবহার করে। "জেড" ব্যতীত অন্যান্য অফসেটগুলিও গৃহীত হয়। উদাহরণ: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" বা "2014-10-02T15:01:23+05:30"

updateTime string ( Timestamp format)

শুধুমাত্র আউটপুট। যখন ক্যাশে এন্ট্রিটি সর্বশেষ ইউটিসি সময়ে আপডেট হয়েছিল।

আরএফসি 3339 ব্যবহার করে, যেখানে উত্পন্ন আউটপুট সর্বদা জেড-সাধারণীকরণ করা হবে এবং 0, 3, 6 বা 9 ভগ্নাংশের সংখ্যা ব্যবহার করে। "জেড" ব্যতীত অন্যান্য অফসেটগুলিও গৃহীত হয়। উদাহরণ: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" বা "2014-10-02T15:01:23+05:30"

usageMetadata object ( UsageMetadata )

শুধুমাত্র আউটপুট। ক্যাশেড সামগ্রী ব্যবহারের উপর মেটাডেটা।

expiration Union type
এই সংস্থানটি কখন শেষ হবে তা নির্দিষ্ট করে। expiration নিম্নলিখিতগুলির মধ্যে একটি হতে পারে:
expireTime string ( Timestamp format)

ইউটিসিতে টাইমস্ট্যাম্প যখন এই সংস্থানটি মেয়াদোত্তীর্ণ হিসাবে বিবেচিত হয়। ইনপুটটিতে যা প্রেরণ করা হয়েছিল তা নির্বিশেষে এটি সর্বদা আউটপুটে সরবরাহ করা হয়।

আরএফসি 3339 ব্যবহার করে, যেখানে উত্পন্ন আউটপুট সর্বদা জেড-সাধারণীকরণ করা হবে এবং 0, 3, 6 বা 9 ভগ্নাংশের সংখ্যা ব্যবহার করে। "জেড" ব্যতীত অন্যান্য অফসেটগুলিও গৃহীত হয়। উদাহরণ: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" বা "2014-10-02T15:01:23+05:30"

ttl string ( Duration format)

শুধুমাত্র ইনপুট। এই সংস্থানটির জন্য নতুন টিটিএল, কেবল ইনপুট।

A duration in seconds with up to nine fractional digits, ending with ' s '. Example: "3.5s" .

name string

Output only. Identifier. The resource name referring to the cached content. Format: cachedContents/{id}

displayName string

Al চ্ছিক। অপরিবর্তনীয়। The user-generated meaningful display name of the cached content. Maximum 128 Unicode characters.

model string

প্রয়োজন। অপরিবর্তনীয়। The name of the Model to use for cached content Format: models/{model}

systemInstruction object ( Content )

Al চ্ছিক। Input only. অপরিবর্তনীয়। Developer set system instruction. Currently text only.

toolConfig object ( ToolConfig )

Al চ্ছিক। Input only. অপরিবর্তনীয়। Tool config. This config is shared for all tools.

JSON প্রতিনিধিত্ব
{
  "contents": [
    {
      object (Content)
    }
  ],
  "tools": [
    {
      object (Tool)
    }
  ],
  "createTime": string,
  "updateTime": string,
  "usageMetadata": {
    object (UsageMetadata)
  },

  // expiration
  "expireTime": string,
  "ttl": string
  // Union type
  "name": string,
  "displayName": string,
  "model": string,
  "systemInstruction": {
    object (Content)
  },
  "toolConfig": {
    object (ToolConfig)
  }
}

বিষয়বস্তু

The base structured datatype containing multi-part content of a message.

A Content includes a role field designating the producer of the Content and a parts field containing multi-part data that contains the content of the message turn.

ক্ষেত্র
parts[] object ( Part )

Ordered Parts that constitute a single message. Parts may have different MIME types.

role string

Al চ্ছিক। The producer of the content. Must be either 'user' or 'model'.

Useful to set for multi-turn conversations, otherwise can be left blank or unset.

JSON representation
{
  "parts": [
    {
      object (Part)
    }
  ],
  "role": string
}

অংশ

A datatype containing media that is part of a multi-part Content message.

A Part consists of data which has an associated datatype. A Part can only contain one of the accepted types in Part.data .

A Part must have a fixed IANA MIME type identifying the type and subtype of the media if the inlineData field is filled with raw bytes.

ক্ষেত্র
thought boolean

Al চ্ছিক। Indicates if the part is thought from the model.

data Union type
data can be only one of the following:
text string

Inline text.

inlineData object ( Blob )

Inline media bytes.

functionCall object ( FunctionCall )

A predicted FunctionCall returned from the model that contains a string representing the FunctionDeclaration.name with the arguments and their values.

functionResponse object ( FunctionResponse )

The result output of a FunctionCall that contains a string representing the FunctionDeclaration.name and a structured JSON object containing any output from the function is used as context to the model.

fileData object ( FileData )

URI based data.

executableCode object ( ExecutableCode )

Code generated by the model that is meant to be executed.

codeExecutionResult object ( CodeExecutionResult )

Result of executing the ExecutableCode .

JSON representation
{
  "thought": boolean,

  // data
  "text": string,
  "inlineData": {
    object (Blob)
  },
  "functionCall": {
    object (FunctionCall)
  },
  "functionResponse": {
    object (FunctionResponse)
  },
  "fileData": {
    object (FileData)
  },
  "executableCode": {
    object (ExecutableCode)
  },
  "codeExecutionResult": {
    object (CodeExecutionResult)
  }
  // Union type
}

ব্লব

Raw media bytes.

Text should not be sent as raw bytes, use the 'text' field.

ক্ষেত্র
mimeType string

The IANA standard MIME type of the source data. Examples: - image/png - image/jpeg If an unsupported MIME type is provided, an error will be returned. For a complete list of supported types, see Supported file formats .

data string ( bytes format)

Raw bytes for media formats.

A base64-encoded string.

JSON representation
{
  "mimeType": string,
  "data": string
}

ফাংশনকল

A predicted FunctionCall returned from the model that contains a string representing the FunctionDeclaration.name with the arguments and their values.

ক্ষেত্র
id string

Al চ্ছিক। The unique id of the function call. If populated, the client to execute the functionCall and return the response with the matching id .

name string

প্রয়োজন। The name of the function to call. Must be az, AZ, 0-9, or contain underscores and dashes, with a maximum length of 63.

args object ( Struct format)

Al চ্ছিক। The function parameters and values in JSON object format.

JSON representation
{
  "id": string,
  "name": string,
  "args": {
    object
  }
}

ফাংশন রেসপন্স

The result output from a FunctionCall that contains a string representing the FunctionDeclaration.name and a structured JSON object containing any output from the function is used as context to the model. This should contain the result of a FunctionCall made based on model prediction.

ক্ষেত্র
id string

Al চ্ছিক। The id of the function call this response is for. Populated by the client to match the corresponding function call id .

name string

প্রয়োজন। The name of the function to call. Must be az, AZ, 0-9, or contain underscores and dashes, with a maximum length of 63.

response object ( Struct format)

প্রয়োজন। The function response in JSON object format.

JSON representation
{
  "id": string,
  "name": string,
  "response": {
    object
  }
}

FileData

URI based data.

ক্ষেত্র
mimeType string

Al চ্ছিক। The IANA standard MIME type of the source data.

fileUri string

প্রয়োজন। ইউআরআই।

JSON representation
{
  "mimeType": string,
  "fileUri": string
}

এক্সিকিউটেবল কোড

Code generated by the model that is meant to be executed, and the result returned to the model.

Only generated when using the CodeExecution tool, in which the code will be automatically executed, and a corresponding CodeExecutionResult will also be generated.

ক্ষেত্র
language enum ( Language )

প্রয়োজন। Programming language of the code .

code string

প্রয়োজন। The code to be executed.

JSON representation
{
  "language": enum (Language),
  "code": string
}

ভাষা

Supported programming languages for the generated code.

Enums
LANGUAGE_UNSPECIFIED Unspecified language. This value should not be used.
PYTHON Python >= 3.10, with numpy and simpy available.

CodeExecutionResult

Result of executing the ExecutableCode .

Only generated when using the CodeExecution , and always follows a part containing the ExecutableCode .

ক্ষেত্র
outcome enum ( Outcome )

প্রয়োজন। Outcome of the code execution.

output string

Al চ্ছিক। Contains stdout when code execution is successful, stderr or other description otherwise.

JSON representation
{
  "outcome": enum (Outcome),
  "output": string
}

ফলাফল

Enumeration of possible outcomes of the code execution.

Enums
OUTCOME_UNSPECIFIED Unspecified status. This value should not be used.
OUTCOME_OK Code execution completed successfully.
OUTCOME_FAILED Code execution finished but with a failure. stderr should contain the reason.
OUTCOME_DEADLINE_EXCEEDED Code execution ran for too long, and was cancelled. There may or may not be a partial output present.

টুল

Tool details that the model may use to generate response.

A Tool is a piece of code that enables the system to interact with external systems to perform an action, or set of actions, outside of knowledge and scope of the model.

ক্ষেত্র
functionDeclarations[] object ( FunctionDeclaration )

Al চ্ছিক। A list of FunctionDeclarations available to the model that can be used for function calling.

The model or system does not execute the function. Instead the defined function may be returned as a FunctionCall with arguments to the client side for execution. The model may decide to call a subset of these functions by populating FunctionCall in the response. The next conversation turn may contain a FunctionResponse with the Content.role "function" generation context for the next model turn.

googleSearchRetrieval object ( GoogleSearchRetrieval )

Al চ্ছিক। Retrieval tool that is powered by Google search.

codeExecution object ( CodeExecution )

Al চ্ছিক। Enables the model to execute code as part of generation.

JSON representation
{
  "functionDeclarations": [
    {
      object (FunctionDeclaration)
    }
  ],
  "googleSearchRetrieval": {
    object (GoogleSearchRetrieval)
  },
  "codeExecution": {
    object (CodeExecution)
  },
  "googleSearch": {
    object (GoogleSearch)
  }
}

ফাংশন ঘোষণা

Structured representation of a function declaration as defined by the OpenAPI 3.03 specification . Included in this declaration are the function name and parameters. This FunctionDeclaration is a representation of a block of code that can be used as a Tool by the model and executed by the client.

ক্ষেত্র
name string

প্রয়োজন। The name of the function. Must be az, AZ, 0-9, or contain underscores and dashes, with a maximum length of 63.

description string

প্রয়োজন। A brief description of the function.

parameters object ( Schema )

Al চ্ছিক। Describes the parameters to this function. Reflects the Open API 3.03 Parameter Object string Key: the name of the parameter. প্যারামিটারের নামগুলি কেস সংবেদনশীল৷ Schema Value: the Schema defining the type used for the parameter.

response object ( Schema )

Al চ্ছিক। Describes the output from this function in JSON Schema format. Reflects the Open API 3.03 Response Object. The Schema defines the type used for the response value of the function.

JSON representation
{
  "name": string,
  "description": string,
  "parameters": {
    object (Schema)
  },
  "response": {
    object (Schema)
  }
}

স্কিমা

The Schema object allows the definition of input and output data types. এই ধরনের বস্তু হতে পারে, কিন্তু আদিম এবং অ্যারেও হতে পারে। Represents a select subset of an OpenAPI 3.0 schema object .

ক্ষেত্র
type enum ( Type )

প্রয়োজন। Data type.

format string

Al চ্ছিক। The format of the data. This is used only for primitive datatypes. Supported formats: for NUMBER type: float, double for INTEGER type: int32, int64 for STRING type: enum, date-time

title string

Al চ্ছিক। The title of the schema.

description string

Al চ্ছিক। পরামিতি একটি সংক্ষিপ্ত বিবরণ. এটি ব্যবহারের উদাহরণ থাকতে পারে। Parameter description may be formatted as Markdown.

nullable boolean

Al চ্ছিক। Indicates if the value may be null.

enum[] string

Al চ্ছিক। Possible values of the element of Type.STRING with enum format. For example we can define an Enum Direction as : {type:STRING, format:enum, enum:["EAST", NORTH", "SOUTH", "WEST"]}

maxItems string ( int64 format)

Al চ্ছিক। Maximum number of the elements for Type.ARRAY.

minItems string ( int64 format)

Al চ্ছিক। Minimum number of the elements for Type.ARRAY.

properties map (key: string, value: object ( Schema ))

Al চ্ছিক। Properties of Type.OBJECT.

An object containing a list of "key": value pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" } .

required[] string

Al চ্ছিক। Required properties of Type.OBJECT.

minProperties string ( int64 format)

Al চ্ছিক। Minimum number of the properties for Type.OBJECT.

maxProperties string ( int64 format)

Al চ্ছিক। Maximum number of the properties for Type.OBJECT.

minLength string ( int64 format)

Al চ্ছিক। SCHEMA FIELDS FOR TYPE STRING Minimum length of the Type.STRING

maxLength string ( int64 format)

Al চ্ছিক। Maximum length of the Type.STRING

pattern string

Al চ্ছিক। Pattern of the Type.STRING to restrict a string to a regular expression.

example value ( Value format)

Al চ্ছিক। Example of the object. Will only populated when the object is the root.

anyOf[] object ( Schema )

Al চ্ছিক। The value should be validated against any (one or more) of the subschemas in the list.

propertyOrdering[] string

Al চ্ছিক। The order of the properties. Not a standard field in open api spec. Used to determine the order of the properties in the response.

default value ( Value format)

Al চ্ছিক। Default value of the field. Per JSON Schema, this field is intended for documentation generators and doesn't affect validation. Thus it's included here and ignored so that developers who send schemas with a default field don't get unknown-field errors.

items object ( Schema )

Al চ্ছিক। Schema of the elements of Type.ARRAY.

minimum number

Al চ্ছিক। SCHEMA FIELDS FOR TYPE INTEGER and NUMBER Minimum value of the Type.INTEGER and Type.NUMBER

maximum number

Al চ্ছিক। Maximum value of the Type.INTEGER and Type.NUMBER

JSON representation
{
  "type": enum (Type),
  "format": string,
  "title": string,
  "description": string,
  "nullable": boolean,
  "enum": [
    string
  ],
  "maxItems": string,
  "minItems": string,
  "properties": {
    string: {
      object (Schema)
    },
    ...
  },
  "required": [
    string
  ],
  "minProperties": string,
  "maxProperties": string,
  "minLength": string,
  "maxLength": string,
  "pattern": string,
  "example": value,
  "anyOf": [
    {
      object (Schema)
    }
  ],
  "propertyOrdering": [
    string
  ],
  "default": value,
  "items": {
    object (Schema)
  },
  "minimum": number,
  "maximum": number
}

টাইপ

Type contains the list of OpenAPI data types as defined by https://spec.openapis.org/oas/v3.0.3#data-types

Enums
TYPE_UNSPECIFIED Not specified, should not be used.
STRING স্ট্রিং টাইপ।
NUMBER Number type.
INTEGER Integer type.
BOOLEAN Boolean type.
ARRAY Array type.
OBJECT বস্তুর ধরন।
NULL Null type.

GoogleSearch Retrieval

Tool to retrieve public web data for grounding, powered by Google.

ক্ষেত্র
dynamicRetrievalConfig object ( DynamicRetrievalConfig )

Specifies the dynamic retrieval configuration for the given source.

JSON representation
{
  "dynamicRetrievalConfig": {
    object (DynamicRetrievalConfig)
  }
}

DynamicRetrievalConfig

Describes the options to customize dynamic retrieval.

ক্ষেত্র
mode enum ( Mode )

The mode of the predictor to be used in dynamic retrieval.

dynamicThreshold number

The threshold to be used in dynamic retrieval. If not set, a system default value is used.

JSON representation
{
  "mode": enum (Mode),
  "dynamicThreshold": number
}

মোড

The mode of the predictor to be used in dynamic retrieval.

Enums
MODE_UNSPECIFIED Always trigger retrieval.
MODE_DYNAMIC Run retrieval only when system decides it is necessary.

CodeExecution

This type has no fields.

Tool that executes code generated by the model, and automatically returns the result to the model.

See also ExecutableCode and CodeExecutionResult which are only generated when using this tool.

গুগল সার্চ

This type has no fields.

GoogleSearch tool type. Tool to support Google Search in Model. গুগল দ্বারা চালিত.

টুল কনফিগারেশন

The Tool configuration containing parameters for specifying Tool use in the request.

ক্ষেত্র
functionCallingConfig object ( FunctionCallingConfig )

Al চ্ছিক। Function calling config.

JSON representation
{
  "functionCallingConfig": {
    object (FunctionCallingConfig)
  }
}

FunctionCallingConfig

Configuration for specifying function calling behavior.

ক্ষেত্র
mode enum ( Mode )

Al চ্ছিক। Specifies the mode in which function calling should execute. If unspecified, the default value will be set to AUTO.

allowedFunctionNames[] string

Al চ্ছিক। A set of function names that, when provided, limits the functions the model will call.

This should only be set when the Mode is ANY. Function names should match [FunctionDeclaration.name]. With mode set to ANY, model will predict a function call from the set of function names provided.

JSON representation
{
  "mode": enum (Mode),
  "allowedFunctionNames": [
    string
  ]
}

মোড

Defines the execution behavior for function calling by defining the execution mode.

Enums
MODE_UNSPECIFIED Unspecified function calling mode. This value should not be used.
AUTO Default model behavior, model decides to predict either a function call or a natural language response.
ANY Model is constrained to always predicting a function call only. If "allowedFunctionNames" are set, the predicted function call will be limited to any one of "allowedFunctionNames", else the predicted function call will be any one of the provided "functionDeclarations".
NONE Model will not predict any function call. Model behavior is same as when not passing any function declarations.
VALIDATED Model decides to predict either a function call or a natural language response, but will validate function calls with constrained decoding.

মেটাডেটা ব্যবহার

Metadata on the usage of the cached content.

ক্ষেত্র
totalTokenCount integer

Total number of tokens that the cached content consumes.

JSON representation
{
  "totalTokenCount": integer
}