WorryFree Computers   »   [go: up one dir, main page]

Custom Gemini integration

How can i integrate a fine tuned gemini model into my appscript project

1 2 242
2 REPLIES 2

Hey

To integrate a fine-tuned Gemini model into your Apps Script project, you'll need to follow these steps:

  1. Create a project in the AI Platform:

    • Go to the AI Platform Console and sign in with your Google Cloud Platform (GCP) credentials.
    • Create a new project or select an existing one where you want to deploy your Gemini model.
  2. Deploy the fine-tuned Gemini model:

    • Upload your fine-tuned Gemini model files to the AI Platform Model Registry.
    • Create a model deployment using the model files you uploaded.
    • Make sure the model deployment is set to "Online" and has an appropriate endpoint URL.
  3. Install the AI Platform Apps Script Library:

    • In your Apps Script project, open the Script Editor.
    • Go to Resources > Libraries > Add Library.
    • Search for and install the "AI Platform Apps Script Library".
  4. Access the deployed Gemini model from Apps Script:

    • In your Apps Script code, use the aiplatform.prediction service to make predictions using the deployed Gemini model.
    • Replace <MODEL_NAME> with the name of your deployed model and <ENDPOINT_URL> with the endpoint URL you obtained in step 2.
JavaScript
// 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" } }

 

 

Top Labels in this Space