জেমিনি এবং অন্যান্য জেনারেটিভ এআই মডেল অ্যাক্সেস করুন।
ভার্টেক্স এআই পরিষেবা আপনাকে গুগল অ্যাপস স্ক্রিপ্টে ভার্টেক্স এআই এপিআই ব্যবহার করার সুযোগ দেয়। এই এপিআই আপনাকে টেক্সট জেনারেশন, ইমেজ জেনারেশন এবং আরও অনেক কিছুর জন্য জেমিনি ও অন্যান্য জেনারেটিভ এআই মডেল ব্যবহারের সুযোগ দেয়।
এই উন্নত পরিষেবাটি শুরু করতে, কুইকস্টার্ট ব্যবহার করে দেখুন।
পূর্বশর্ত
বিলিং সক্ষম করা একটি গুগল ক্লাউড প্রজেক্ট। কোনো বিদ্যমান প্রজেক্টে বিলিং সক্ষম করা আছে কিনা তা পরীক্ষা করতে, আপনার প্রজেক্টগুলোর বিলিং স্ট্যাটাস যাচাই করুন দেখুন। একটি প্রজেক্ট তৈরি করতে এবং বিলিং সেট আপ করতে, একটি গুগল ক্লাউড প্রজেক্ট তৈরি করুন দেখুন।
গুগল ক্লাউড কনসোলে, আপনার ক্লাউড প্রজেক্টে যান এবং Vertex AI API সক্রিয় করুন:
আপনার অ্যাপস স্ক্রিপ্ট প্রজেক্টে ভার্টেক্স এআই সার্ভিসটি চালু করুন। এর ধাপগুলো জানতে অ্যাডভান্সড গুগল সার্ভিসেস দেখুন।
রেফারেন্স
এই পরিষেবা সম্পর্কে আরও তথ্যের জন্য, Vertex AI API রেফারেন্স ডকুমেন্টেশন দেখুন। Apps Script-এর সমস্ত উন্নত পরিষেবার মতো, Vertex AI পরিষেবাটিও পাবলিক API-এর মতোই একই অবজেক্ট, মেথড এবং প্যারামিটার ব্যবহার করে।
নমুনা কোড
নিম্নলিখিত নমুনা কোডটি ভার্টেক্স এআই এপিআই-এর সংস্করণ ১ ব্যবহার করে।
টেক্সট তৈরি করুন
এই নমুনা কোডটি দেখায় কিভাবে জেমিনি ২.৫ ফ্ল্যাশ মডেলকে টেক্সট তৈরি করতে নির্দেশ দেওয়া যায়। ফাংশনটি অ্যাপস স্ক্রিপ্টের এক্সিকিউশন লগে আউটপুট ফেরত দেয়।
/**
* Main entry point to test the Vertex AI integration.
*/
function main() {
const prompt = 'What is Apps Script in one sentence?';
try {
const response = callVertexAI(prompt);
console.log(`Response: ${response}`);
} catch (error) {
console.error(`Failed to call Vertex AI: ${error.message}`);
}
}
/**
* Calls the Vertex AI Gemini model.
*
* @param {string} prompt - The user's input prompt.
* @return {string} The text generated by the model.
*/
function callVertexAI(prompt) {
// Configuration
const projectId = 'GOOGLE_CLOUD_PROJECT_ID';
const region = 'us-central1';
const modelName = 'gemini-2.5-flash';
const model = `projects/${projectId}/locations/${region}/publishers/google/models/${modelName}`;
const payload = {
contents: [{
role: 'user',
parts: [{
text: prompt
}]
}],
generationConfig: {
temperature: 0.1,
maxOutputTokens: 2048
}
};
// Execute the request using the Vertex AI Advanced Service
const response = VertexAI.Endpoints.generateContent(payload, model);
// Use optional chaining for safe property access
return response?.candidates?.[0]?.content?.parts?.[0]?.text || 'No response generated.';
}
GOOGLE_CLOUD_PROJECT_ID জায়গায় আপনার ক্লাউড প্রজেক্টের প্রজেক্ট আইডিটি বসান।
একটি পরিষেবা অ্যাকাউন্ট ব্যবহার করে টেক্সট তৈরি করুন
নিম্নলিখিত উদাহরণটি দেখায় কিভাবে একটি সার্ভিস অ্যাকাউন্ট ব্যবহার করে অ্যাপস স্ক্রিপ্ট প্রজেক্ট হিসাবে প্রমাণীকরণের মাধ্যমে টেক্সট তৈরি করতে হয়।
/**
* Main entry point to test the Vertex AI integration.
*/
function main() {
const prompt = 'What is Apps Script in one sentence?';
try {
const response = callVertexAI(prompt);
console.log(`Response: ${response}`);
} catch (error) {
console.error(`Failed to call Vertex AI: ${error.message}`);
}
}
/**
* Calls the Vertex AI Gemini model.
*
* @param {string} prompt - The user's input prompt.
* @return {string} The text generated by the model.
*/
function callVertexAI(prompt) {
const service = getServiceAccountService();
// Configuration
const projectId = 'GOOGLE_CLOUD_PROJECT_ID';
const region = 'us-central1';
const modelName = 'gemini-2.5-flash';
const model = `projects/${projectId}/locations/${region}/publishers/google/models/${modelName}`;
const payload = {
contents: [{
role: 'user',
parts: [{
text: prompt
}]
}],
generationConfig: {
temperature: 0.1,
maxOutputTokens: 2048
}
};
// Execute the request using the Vertex AI Advanced Service
const response = VertexAI.Endpoints.generateContent(
payload,
model,
{},
// Authenticate with the service account token.
{ Authorization: `Bearer ${service.getAccessToken()}` },
);
// Use optional chaining for safe property access
return response?.candidates?.[0]?.content?.parts?.[0]?.text || 'No response generated.';
}
/**
* Get a new OAuth2 service for a given service account.
*/
function getServiceAccountService() {
const serviceAccountKeyString = PropertiesService.getScriptProperties().getProperty('SERVICE_ACCOUNT_KEY');
if (!serviceAccountKeyString) {
throw new Error('SERVICE_ACCOUNT_KEY property is not set. Please follow the setup instructions.');
}
const serviceAccountKey = JSON.parse(serviceAccountKeyString);
const CLIENT_EMAIL = serviceAccountKey.client_email;
const PRIVATE_KEY = serviceAccountKey.private_key;
const SCOPES = ['https://www.googleapis.com/auth/cloud-platform'];
return OAuth2.createService('ServiceAccount')
.setTokenUrl('https://oauth2.googleapis.com/token')
.setPrivateKey(PRIVATE_KEY)
.setIssuer(CLIENT_EMAIL)
.setPropertyStore(PropertiesService.getScriptProperties())
.setScope(SCOPES);
}