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

Function translate

Gemini_Functions.js:70–104  ·  view source on GitHub ↗
(inputText)

Source from the content-addressed store, hash-verified

68
69
70function translate(inputText) {
71 cache = CacheService.getUserCache();
72 token = cache.get("token");
73 if (token == "") return "ERROR";
74 Logger.log(`Token = ${token}`);
75 url = `https://us-central1-aiplatform.googleapis.com/v1/projects/${project}/locations/us-central1/publishers/google/models/gemini-1.0-pro:generateContent`
76 textWithInstruction = "translate to Spanish: " + inputText;
77 data = {
78 contents: {
79 role: "USER",
80 parts: { "text": textWithInstruction }
81 },
82 generation_config: {
83 temperature: 0.3,
84 topP: 1,
85 maxOutputTokens: 256
86 }
87 }
88 const options = {
89 method: "post",
90 contentType: 'application/json',
91 headers: {
92 Authorization: `Bearer ${token}`,
93 },
94 payload: JSON.stringify(data)
95 };
96
97 const response = UrlFetchApp.fetch(url, options);
98 if (response.getResponseCode() == 200) {
99 json = JSON.parse(response.getContentText());
100 answer = json.candidates[0].content.parts[0].text;
101 return answer;
102 }
103 return "ERROR";
104}
105
106
107function report(inputText) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected