How can i integrate a fine tuned gemini model into my appscript project
Hey
To integrate a fine-tuned Gemini model into your Apps Script project, you'll need to follow these steps:
Create a project in the AI Platform:
Deploy the fine-tuned Gemini model:
Install the AI Platform Apps Script Library:
Access the deployed Gemini model from Apps Script:
// Import the AI Platform Apps Script Library var aiplatform = AppsScript.getAiPlatformService(); // Create a prediction request for the Gemini model var request = { model: { name: '<MODEL_NAME>', version: 'default' }, inputs: { 'text': 'This is the text you want to process with the Gemini model' } }; // Send the prediction request and get the response var response = aiplatform.prediction.predict(request); // Access the prediction results var predictions = response.predictions; console.log(predictions);
This code snippet demonstrates the basic steps of integrating a fine-tuned Gemini model into your Apps Script project. You can further customize the code to fit your specific use case and requirements.
Thanks.Any idea why the predict int he following scripts yields the error below?
function askGeminii(inputText) {
const BASE = "https://us-central1-aiplatform.googleapis.com";
const url = `${BASE}/v1/projects/${PROJECT_ID}/locations/us-central1/endpoints/1645825970269061120:predict`;
const data = {
"instances": [
{"content": inputText}
]
};
const options = {
method: "post",
headers: { "Authorization": `Bearer ${ACCESS_TOKEN}`, "Content-Type": "application/json" },
muteHttpExceptions: true,
payload: JSON.stringify(data)
};
const response = UrlFetchApp.fetch(url, options);
if (response.getResponseCode() === 200) {
const jsonResponse = JSON.parse(response.getContentText());
// Assuming that the model returns an array of predictions
if (jsonResponse.predictions && jsonResponse.predictions.length > 0) {
return jsonResponse.predictions[0].generatedText; // Adjust according to the actual key in the response
}
return "No valid response from model.";
}
return "ERROR: " + response.getContentText(); // Better error handling
}
ERROR: { "error": { "code": 400, "message": "Gemini cannot be accessed through Vertex Predict/RawPredict API. Please follow https://cloud.google.com/vertex-ai/docs/generative-ai/start/quickstarts/quickstart-multimodal for Gemini usage.", "status": "FAILED_PRECONDITION" } }