Professional Documents
Culture Documents
Tutorial IA
Tutorial IA
Inicio rápido
OpenAI ha entrenado modelos de lenguaje de vanguardia que son muy buenos para
comprender y generar texto. Nuestra API brinda acceso a estos modelos y puede usarse
para resolver prácticamente cualquier tarea que involucre lenguaje de procesamiento.
En este tutorial de inicio rápido, creará una aplicación de muestra simple. En el camino,
aprenderá conceptos y técnicas clave que son fundamentales para usar la API para
cualquier tarea, que incluyen:
Generación de contenido
resumen
Clasificación, categorización y análisis de sentimiento
Extracción de datos
Traducción
¡Mucho mas!
Introducción
El punto final de finalización es el núcleo de nuestra API y proporciona una interfaz simple
que es extremadamente flexible y poderosa. Ingresa un texto como mensaje y la API
devolverá un texto completo que intenta coincidir con las instrucciones o el contexto que
le dio.
Primero, necesitará un aviso que deje en claro lo que quiere. Comencemos con una
instrucción. Envíe este aviso para generar su primera finalización.
https://platform.openai.com/docs/quickstart/adjust-your-settings 1/6
11/4/23, 11:41 Quickstart tutorial - OpenAI API
Compañero
Charley alegre
Como puede ver, agregar un simple adjetivo a nuestro indicador cambia la finalización
resultante. Diseñar su indicador es esencialmente cómo "programa" el modelo.
En muchos casos, es útil mostrar y decirle al modelo lo que quiere. Agregar ejemplos a su
aviso puede ayudar a comunicar patrones o matices. Intente enviar este mensaje que
incluye un par de ejemplos.
https://platform.openai.com/docs/quickstart/adjust-your-settings 2/6
11/4/23, 11:41 Quickstart tutorial - OpenAI API
Animal: Cat
Names: Captain Sharpclaw, Agent Fluffball, The Incredible Feline
Animal: Dog
Names: Ruff the Protector, Wonder Canine, Sir Barks-a-Lot
Animal: Horse
Names:
¡Lindo! Agregar ejemplos de la salida que esperaríamos para una entrada dada ayudó al
modelo a proporcionar los tipos de nombres que buscábamos.
3 Ajusta tu configuración
El diseño rápido no es la única herramienta que tiene a su disposición. También puede
controlar las finalizaciones ajustando su configuración. Uno de los ajustes más
importantes se llama temperatura .
Es posible que haya notado que si envió el mismo aviso varias veces en los ejemplos
anteriores, el modelo siempre devolvería resultados idénticos o muy similares. Esto se
debe a que su temperatura se fijó en 0 .
Intente volver a enviar el mismo aviso varias veces con la temperatura establecida en 1 .
Temperatura 1
Animal: Cat
Names: Captain Sharpclaw, Agent Fluffball, The Incredible Feline
Animal: Dog
Names: Ruff the Protector, Wonder Canine, Sir Barks-a-Lot
Animal: Horse
Names:
https://platform.openai.com/docs/quickstart/adjust-your-settings 3/6
11/4/23, 11:41 Quickstart tutorial - OpenAI API
¿Ves lo que pasó? Cuando la temperatura está por encima de 0, enviar el mismo aviso da
como resultado diferentes finalizaciones cada vez.
Recuerde que el modelo predice qué texto es más probable que siga al texto que lo
precede. La temperatura es un valor entre 0 y 1 que esencialmente le permite controlar la
confianza que debe tener el modelo al hacer estas predicciones. Bajar la temperatura
significa que se correrán menos riesgos y las terminaciones serán más precisas y
deterministas. El aumento de la temperatura dará como resultado terminaciones más
diversas.
BUCEAR PROFUNDO
4 Cree su aplicación
Now that you’ve found a good prompt and settings, you’re ready to build your pet name
generator! We’ve written some code to get you started — follow the instructions below to
download the code and run the app.
Setup
If you don’t have Node.js installed, install it from here. Then download the code by cloning
this repository.
If you prefer not to use git, you can alternatively download the code using this zip file.
Navigate into the project directory and make a copy of the example environment variables
file.
https://platform.openai.com/docs/quickstart/adjust-your-settings 4/6
11/4/23, 11:41 Quickstart tutorial - OpenAI API
cd openai-quickstart-node
cp .env.example .env
Copy your secret API key and set it as the OPENAI_API_KEY in your newly created .env
file. If you haven't created a secret key yet, you can do so below.
You currently do not have any API keys. Please create one below.
Create new secret key
Important note: When using Javascript, all API calls should be made on the server-side
only, since making calls in client-side browser code will expose your API key. See here for
more details.
npm install
npm run dev
Open http://localhost:3000 in your browser and you should see the pet name generator!
1 function generatePrompt(animal) {
2 const capitalizedAnimal = animal[0].toUpperCase() + animal.slice(1)
3 return `Suggest three names for an animal that is a superhero.
4
5 Animal: Cat
6 Names: Captain Sharpclaw, Agent Fluffball, The Incredible Feline
7 Animal: Dog
8 Names: Ruff the Protector, Wonder Canine, Sir Barks-a-Lot
9 Animal: ${capitalizedAnimal}
https://platform.openai.com/docs/quickstart/adjust-your-settings 5/6
11/4/23, 11:41 Quickstart tutorial - OpenAI API
10 Names:`;
11 }
On line 9 in generate.js , you’ll see the code that sends the actual API request. As
mentioned above, it uses the completions endpoint with a temperature of 0.6.
And that’s it! You should now have a full understanding of how your (superhero) pet name
generator uses the OpenAI API!
Closing
These concepts and techniques will go a long way in helping you build your own
application. That said, this simple example demonstrates just a sliver of what’s possible!
The completions endpoint is flexible enough to solve virtually any language processing
task, including content generation, summarization, semantic search, topic tagging,
sentiment analysis, and so much more.
One limitation to keep in mind is that, for most models, a single API request can only
process up to 2,048 tokens (roughly 1,500 words) between your prompt and completion.
DEEP DIVE
For more advanced tasks, you might find yourself wishing you could provide more
examples or context than you can fit in a single prompt The fine-tuning API is a great
https://platform.openai.com/docs/quickstart/adjust-your-settings 6/6