Skip to content

Commit

Permalink
feat: switch from Text Bison to Gemini (#271)
Browse files Browse the repository at this point in the history
* Switch from Text Bison to Gemini

* Remove extra spaces

---------

Co-authored-by: pierrick <[email protected]>
  • Loading branch information
PierrickVoulet and pierrick authored Mar 21, 2024
1 parent 81d0ba6 commit d4f6b1f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,39 @@
// This script contains the Google Vertex AI-specific utilities functions.

/**
* Summarizes a Google Chat space history using the text-bison model using Vertex AI API.
* Summarizes a Google Chat space history with the Gemini Pro model using Vertex AI API.
*
* @param {string} history the history
* @return {string} the summary
*/
function summarizeSpace(history) {
const url = `https://${VERTEX_AI_LOCATION_ID}-aiplatform.googleapis.com/v1`
+ `/projects/${PROJECT_ID}/locations/${VERTEX_AI_LOCATION_ID}`
+ "/publishers/google/models/text-bison:predict";
+ "/publishers/google/models/gemini-1.0-pro:generateContent";
const options = {
method: "POST",
headers: { Authorization: "Bearer " + ScriptApp.getOAuthToken() },
contentType: "application/json",
payload: JSON.stringify({
instances: [{
prompt: "Summarize the following conversation between engineers resolving an issue"
+ " in a few sentences. Use only the information from the conversation.\n\n"
+ history
}],
parameters: {
maxOutputTokens: 256,
contents: {
role: "user",
parts: {
text: "Summarize the following conversation between engineers resolving an issue"
+ " in a few sentences.\n\n" + history
}
},
safetySettings: {
category: "HARM_CATEGORY_SEXUALLY_EXPLICIT",
threshold: "BLOCK_LOW_AND_ABOVE"
},
generationConfig: {
temperature: 0.2,
topP: 0.95,
topP: 0.8,
topK: 40
}
})
};

return JSON.parse(UrlFetchApp.fetch(url, options).getContentText())
.predictions[0].content;
.candidates[0].content.parts[0].text;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,39 @@
// This script contains the Google Vertex AI-specific utilities functions.

/**
* Summarizes a Google Chat space history using the text-bison model using Vertex AI API.
* Summarizes a Google Chat space history with the Gemini Pro model using Vertex AI API.
*
* @param {string} history the history
* @return {string} the summary
*/
function summarizeSpace(history) {
const url = `https://${VERTEX_AI_LOCATION_ID}-aiplatform.googleapis.com/v1`
+ `/projects/${PROJECT_ID}/locations/${VERTEX_AI_LOCATION_ID}`
+ "/publishers/google/models/text-bison:predict";
+ "/publishers/google/models/gemini-1.0-pro:generateContent";
const options = {
method: "POST",
headers: { Authorization: "Bearer " + ScriptApp.getOAuthToken() },
contentType: "application/json",
payload: JSON.stringify({
instances: [{
prompt: "Summarize the following conversation between engineers resolving an issue"
+ " in a few sentences. Use only the information from the conversation.\n\n"
+ history
}],
parameters: {
maxOutputTokens: 256,
contents: {
role: "user",
parts: {
text: "Summarize the following conversation between engineers resolving an issue"
+ " in a few sentences.\n\n" + history
}
},
safetySettings: {
category: "HARM_CATEGORY_SEXUALLY_EXPLICIT",
threshold: "BLOCK_LOW_AND_ABOVE"
},
generationConfig: {
temperature: 0.2,
topP: 0.95,
topP: 0.8,
topK: 40
}
})
};

return JSON.parse(UrlFetchApp.fetch(url, options).getContentText())
.predictions[0].content;
.candidates[0].content.parts[0].text;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,45 @@
// This script contains the Google Vertex AI-specific utilities functions.

/**
* Summarizes a Google Chat space history using the text-bison model using Vertex AI API.
* Summarizes a Google Chat space history with the Gemini Pro model using Vertex AI API.
*
* @param {string} history the history
* @return {string} the summary
*/
function summarizeSpace(history) {
const url = `https://${VERTEX_AI_LOCATION_ID}-aiplatform.googleapis.com/v1`
+ `/projects/${PROJECT_ID}/locations/${VERTEX_AI_LOCATION_ID}`
+ "/publishers/google/models/text-bison:predict";
+ "/publishers/google/models/gemini-1.0-pro:generateContent";
const options = {
method: "POST",
headers: { Authorization: "Bearer " + ScriptApp.getOAuthToken() },
contentType: "application/json",
payload: JSON.stringify({
instances: [{
prompt: "Summarize the following conversation between engineers resolving an issue"
+ " in a few sentences. Use only the information from the conversation.\n\n"
+ history
}],
parameters: {
maxOutputTokens: 256,
contents: {
role: "user",
parts: {
text: "Summarize the following conversation between engineers resolving an issue"
+ " in a few sentences.\n\n" + history
}
},
safetySettings: {
category: "HARM_CATEGORY_SEXUALLY_EXPLICIT",
threshold: "BLOCK_LOW_AND_ABOVE"
},
generationConfig: {
temperature: 0.2,
topP: 0.95,
topP: 0.8,
topK: 40
}
})
};

return JSON.parse(UrlFetchApp.fetch(url, options).getContentText())
.predictions[0].content;
.candidates[0].content.parts[0].text;
}

/**
* Gets feedback on inclusivity for a text using the text-bison model using Vertex AI API.
* Gets feedback on inclusivity for a text with the Gemini Pro model using Vertex AI API.
*
* Returns "It's inclusive!" when it is otherwise a list of word(s) that might not be optimal.
*
Expand All @@ -61,7 +66,7 @@ function getInclusivityFeedback(text) {
const url = `https://${VERTEX_AI_LOCATION_ID}-aiplatform.googleapis.com/v1`
+ `/projects/${PROJECT_ID}/locations/${VERTEX_AI_LOCATION_ID}`
+ "/publishers/google/models/gemini-1.0-pro:generateContent";
const options = {
const options = {
method: "POST",
headers: { Authorization: "Bearer " + ScriptApp.getOAuthToken() },
contentType: "application/json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,45 @@
// This script contains the Google Vertex AI-specific utilities functions.

/**
* Summarizes a Google Chat space history using the text-bison model using Vertex AI API.
* Summarizes a Google Chat space history with the Gemini Pro model using Vertex AI API.
*
* @param {string} history the history
* @return {string} the summary
*/
function summarizeSpace(history) {
const url = `https://${VERTEX_AI_LOCATION_ID}-aiplatform.googleapis.com/v1`
+ `/projects/${PROJECT_ID}/locations/${VERTEX_AI_LOCATION_ID}`
+ "/publishers/google/models/text-bison:predict";
+ "/publishers/google/models/gemini-1.0-pro:generateContent";
const options = {
method: "POST",
headers: { Authorization: "Bearer " + ScriptApp.getOAuthToken() },
contentType: "application/json",
payload: JSON.stringify({
instances: [{
prompt: "Summarize the following conversation between engineers resolving an issue"
+ " in a few sentences. Use only the information from the conversation.\n\n"
+ history
}],
parameters: {
maxOutputTokens: 256,
contents: {
role: "user",
parts: {
text: "Summarize the following conversation between engineers resolving an issue"
+ " in a few sentences.\n\n" + history
}
},
safetySettings: {
category: "HARM_CATEGORY_SEXUALLY_EXPLICIT",
threshold: "BLOCK_LOW_AND_ABOVE"
},
generationConfig: {
temperature: 0.2,
topP: 0.95,
topP: 0.8,
topK: 40
}
})
};

return JSON.parse(UrlFetchApp.fetch(url, options).getContentText())
.predictions[0].content;
.candidates[0].content.parts[0].text;
}

/**
* Gets feedback on inclusivity for a text using the text-bison model using Vertex AI API.
* Gets feedback on inclusivity for a text with the Gemini Pro model using Vertex AI API.
*
* Returns "It's inclusive!" when it is otherwise a list of word(s) that might not be optimal.
*
Expand All @@ -61,7 +66,7 @@ function getInclusivityFeedback(text) {
const url = `https://${VERTEX_AI_LOCATION_ID}-aiplatform.googleapis.com/v1`
+ `/projects/${PROJECT_ID}/locations/${VERTEX_AI_LOCATION_ID}`
+ "/publishers/google/models/gemini-1.0-pro:generateContent";
const options = {
const options = {
method: "POST",
headers: { Authorization: "Bearer " + ScriptApp.getOAuthToken() },
contentType: "application/json",
Expand Down

0 comments on commit d4f6b1f

Please sign in to comment.