MCPcopy Create free account
hub / github.com/analyticswithadam/App_Script / askGemini

Function askGemini

Gemini_Functions.js:34–67  ·  view source on GitHub ↗
(inputText)

Source from the content-addressed store, hash-verified

32}
33
34function askGemini(inputText) {
35 cache = CacheService.getUserCache();
36 token = cache.get("token");
37 if (token == "") return "ERROR";
38 Logger.log(`Token = ${token}`);
39 url = `https://us-central1-aiplatform.googleapis.com/v1/projects/${project}/locations/us-central1/publishers/google/models/gemini-1.0-pro:generateContent`
40 data = {
41 contents: {
42 role: "USER",
43 parts: { "text": inputText }
44 },
45 generation_config: {
46 temperature: 0.3,
47 topP: 1,
48 maxOutputTokens: 256
49 }
50 }
51 const options = {
52 method: "post",
53 contentType: 'application/json',
54 headers: {
55 Authorization: `Bearer ${token}`,
56 },
57 payload: JSON.stringify(data)
58 };
59
60 const response = UrlFetchApp.fetch(url, options);
61 if (response.getResponseCode() == 200) {
62 json = JSON.parse(response.getContentText());
63 answer = json.candidates[0].content.parts[0].text;
64 return answer;
65 }
66 return "ERROR";
67}
68
69
70function translate(inputText) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected