Está en la página 1de 7

CHAT GPT

PASO 1. Se debe tener una cuenta en OPEN IA para poder obtener la Clave
https://platform.openai.com/account/api-keys

PASO 2: Vamos a automatizar el proceso de generación de consultas con OPEN IA, en un


libro de Excel el cual llamaremos: Consultas Chat GPT.xlsx, en dicho libro vamos mediante un
Script automatizar dichas consultas.
Paso 3: Una vez creado nuestro libro:

Copiamos y pegamos el siguiente Script:


async function main(workbook: ExcelScript.Workbook) { // Ponga la clave API de
OpenAI en la hoja API y celda B1 const apiKey =
workbook.getWorksheet("API").getRange("B1").getValue(); const endpoint: string =
"https://api.openai.com/v1/completions"; // Escriba aquí su pregunta const sheet =
workbook.getWorksheet("Preguntas"); // preguntar en la celda b2 const mytext =
sheet.getRange("B2").getValue(); // se mostrará también el resultado pero en mas de
una fila const result = workbook.getWorksheet("Resultados");
result.getRange("A1:D1000").clear(); sheet.getRange("B3").setValue(" ") // Set the
model engine and prompt const model: string = "text-davinci-002"; const prompt:
(string | boolean | number) = mytext; // Set the HTTP headers const headers:
Headers = new Headers(); headers.append("Content-Type", "application/json");
headers.append("Authorization", `Bearer ${apiKey}`); // Set the HTTP body const
body: (string | boolean | number) = JSON.stringify({ model: model, prompt: prompt,
max_tokens: 1024, n: 1, temperature: 0.5, }); // Send the HTTP request const
response: Response = await fetch(endpoint, { method: "POST", headers: headers,
body: body, }); // Parse the response as JSON const json: { choices: { text:(string
| boolean | number )}[] } = await response.json(); // Get the answer - i.e. output
const text: (string | boolean | number) = json.choices[0].text; // Output the
generated text // console.log(text); const output = sheet.getRange("B4");
output.setValue(text); const cell = sheet.getRange("B4"); // Split the cell
contents by new line const arr = cell.getValue().toString().split("\n"); const
newcell = result.getRange("A1"); var offset = 0; // console.log (arr) for (let i =
0; i < arr.length; i++) { // Write the value to the next cell if (arr[i].length >
0) { newcell.getOffsetRange(offset, 0).setValue(arr[i]); offset++; } } //
console.log(offset) if (offset > 1) { sheet.getRange("B3").setValue("Check 'Result'
sheet to get answers separated by multiple rows") } }
También, si deseamos cambiarle el nombre nos vamos a los tres punticos y le decimos:
Cambiar nombre. Se le cambia el nombre y se le dice Enter para que Guarde los cambios.
PASO 3:
PASO 4:
Creamos dos nuevas pestañas, llamada Preguntas y Resultados (Muy Importante):

PASO 5:

Por ultimo, le formulamos en el área de preguntas las consultas deseadas:

Vamos a descargar un complemento que me traduce de Ingles a Español ó Viceversa las


funciones ingresadas:
Funcionamiento:

También podría gustarte