Saltar al contenido principal

Usar ChatGPT

Totalum permite usar algunos endpoints de openai como el de chatgpt o el generador de imágenes.

What happens if you are not programming in javascript?

If you are not programming in javascript, you can use the api directly, see TOTALUM API DOCUMENTATION

If you are programming in javascript, you can use the totalumSdk

Note: If you use totalumSdk inside a totalum plugin, you don't need to authenticate, you can start using totalum sdk functions like this: modules.totalumSdk.ocr.ocrOfImage(fileName); etc...

Si tienes dudas de como instalar y usar TotalumSdk mira la documentación: Instalación SDK de Totalum, y Uso del SDK

No hace falta que te registres en openai

Functions for call OpenAI API without need to have an OpenAI account

Create a chat completion


//body the openai chat completion body, more info here: https://platform.openai.com/docs/api-reference/chat/create
const bodyExample={
// see the openai api docs for more info
messages: [
{content: 'You are a math specialist assistant', role: 'system'},
{content: 'how I can resolve a matrix', role: 'user'}
//etc...
],
model: 'gpt-3.5-turbo',
max_tokens: 30,
}

const result = await totalumClient.openai.createChatCompletion(bodyExample);
const chatCompletion = result.data.data;
// returns the completion provided by openai api

Create a completion (deprecated, use createChatCompletion instead)


//body the openai completion body, more info here: https://platform.openai.com/docs/api-reference/completions/create
const body={
// see the openai api docs for more info
}

const result = await totalumClient.openai.createCompletion(body);
const gptCompletion = result.data.data;

// returns the completion provided by openai api

Generate an image


//body the openai chat completion body, more info here: https://platform.openai.com/docs/api-reference/chat/create
const bodyExample={
prompt:'your prompt',
size: '256x256' | '512x512' | '1024x1024',
fileName: 'file-name-of-file-saved.png' // CAUTION: if you use the same name for multiple images, the images will be overwritten
}

const result = await totalumClient.openai.generateImage(bodyExample);
const imageCompletion = result.data.data;
// returns the file name with the file generated by openai, if is not an url, you can download it using files.getDownloadUrl(imageCompletion);