<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Johan Friedner on Medium]]></title>
        <description><![CDATA[Stories by Johan Friedner on Medium]]></description>
        <link>https://medium.com/@JohanFriedner?source=rss-a3b0e9f2aabc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*RkuDlcYoG9LYspclGZ4Fog.jpeg</url>
            <title>Stories by Johan Friedner on Medium</title>
            <link>https://medium.com/@JohanFriedner?source=rss-a3b0e9f2aabc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 17:15:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@JohanFriedner/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Realiza una solicitud de API a ChatGPT 4 con Next.js utilizando Javascript]]></title>
            <link>https://medium.com/@JohanFriedner/realiza-una-solicitud-de-api-a-chatgpt-4-con-next-js-utilizando-javascript-190ba938dac6?source=rss-a3b0e9f2aabc------2</link>
            <guid isPermaLink="false">https://medium.com/p/190ba938dac6</guid>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[chatgpt4]]></category>
            <category><![CDATA[español]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[chatgptapi]]></category>
            <dc:creator><![CDATA[Johan Friedner]]></dc:creator>
            <pubDate>Wed, 29 Mar 2023 20:48:06 GMT</pubDate>
            <atom:updated>2023-03-29T20:58:59.819Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="A robot about to do an API request to Chat GPT 4 from Next.js using Javascript" src="https://cdn-images-1.medium.com/max/1024/1*9cyO1Acs9yGiEsZEUXVZOQ.jpeg" /><figcaption>Un robot está a punto de realizar una solicitud de API a Chat GPT 4 desde Next.js utilizando Javascript.</figcaption></figure><h3>Requisitos previos:</h3><p>Debes haber estado en la lista de espera de Chat GPT 4 y haber sido aceptado recibiendo un correo electrónico en las líneas de “You can now access GPT-4 models with 8K context via the existing OpenAI API”. El botón “Get Started” no es útil, ya que solo te lleva a una página general.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1FhNkDhVC7B93HFC9YNhoA.png" /></figure><h3>Cómo realizar la solicitud de API de GPT-4 utilizando Next.js y Javascript:</h3><ol><li>Crea una nueva clave de API <a href="https://platform.openai.com/account/api-keys">aquí</a> (es posible que las antiguas no funcionen)</li><li>Crea un <a href="https://nextjs.org/docs/api-reference/create-next-app">nuevo</a> proyecto Next.js</li><li>Instala OpenAI utilizando tu terminal ($ npm i openai)</li><li>En la carpeta /pages/api de tu proyecto, crea un nuevo archivo (por ejemplo, gpt4.js)</li><li>Pega el código a continuación en tu archivo e inserta tu propia clave de API</li></ol><pre>const { Configuration, OpenAIApi } = require(&quot;openai&quot;);<br><br>export default async function handler(req, res) {<br>  const configuration = new Configuration({<br>    apiKey: &quot;&lt;clave-de-API&gt;&quot;,<br>  });<br>  const openai = new OpenAIApi(configuration);<br>  const response = await openai.createChatCompletion({<br>    model: &quot;gpt-4&quot;,<br>    messages: [<br>      { role: &quot;system&quot;, content: &quot;You are a helpful assistant.&quot; },<br>      { role: &quot;user&quot;, content: &quot;Who won the world series in 2020?&quot; },<br>      { role: &quot;assistant&quot;, content: &quot;The Los Angeles Dodgers.&quot; },<br>      { role: &quot;user&quot;, content: &quot;Where was it played?&quot; },<br>    ],<br>    max_tokens: 50,<br>    n: 1,<br>    stop: null,<br>    temperature: 1,<br>  });<br>  res.status(200).json({ answer: response.data.choices[0].message.content });<br>}</pre><p>6. Inicia tu servidor localhost (npm run dev). Ejecuta tu ruta de API Chat GPT 4 visitando <a href="http://localhost:3000/api/gpt4">http://localhost:3000/api/gpt4</a> y deberías ver tu respuesta.</p><h3>IMPORTANTE SABER:</h3><p><strong>Proporcionar contexto</strong><br>La API de Chat GPT-4 no “recuerda” tus respuestas como cuando la utilizas en el navegador. Para conversar con ella, debes actualizar y proporcionar constantemente la conversación anterior para que tenga contexto.</p><p>Puedes lograr esto guardando la respuesta anterior y agregándola al array de mensajes cada vez que realices una nueva solicitud de API / mensaje de chat. En el ejemplo anterior, hay 3 mensajes anteriores del usuario y de GPT-4 combinados, y el cuarto es el “nuevo” para que GPT-4 responda.</p><p><strong>Verificar qué modelo estás utilizando<br></strong>¿No estás seguro de si estás obteniendo respuestas de ChatGPT 4 o de GPT3 / 3.5 Turbo? He descubierto que obtienes respuestas poco confiables si le preguntas a ChatGPT qué modelo está utilizando. La forma más fácil de verificar es visitar tu <a href="https://platform.openai.com/account/usage">página de uso</a> de API, que te indica qué modelo estás utilizando para las solicitudes de API.</p><p><strong>Agregar un método de pago<br></strong>No creo que puedas usar GPT-4 sin agregar una tarjeta de crédito, o al menos he visto problemas de cuotas con usuarios que acaban de recibir la invitación de API. Para evitar esto, simplemente agrega una tarjeta de crédito: la API tiene un precio muy razonable.</p><p><strong>Usar los paquetes más recientes<br></strong>Asegúrate de estar utilizando la <a href="https://www.npmjs.com/package/openai">última versión</a> del paquete NPM de OpenAI: al momento de escribir este post, se ha lanzado la versión 3.2.1.</p><p><a href="https://johanfriedner.com/">https://johanfriedner.com/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=190ba938dac6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make an API request to ChatGPT 4 with Next.js using Javascript]]></title>
            <link>https://medium.com/@JohanFriedner/make-an-api-request-to-chat-gpt-4-with-next-js-using-javascript-c238b47bd88a?source=rss-a3b0e9f2aabc------2</link>
            <guid isPermaLink="false">https://medium.com/p/c238b47bd88a</guid>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[gpt-4]]></category>
            <category><![CDATA[chatgptapi]]></category>
            <category><![CDATA[chatgpt]]></category>
            <dc:creator><![CDATA[Johan Friedner]]></dc:creator>
            <pubDate>Tue, 28 Mar 2023 22:45:08 GMT</pubDate>
            <atom:updated>2023-10-04T21:39:04.169Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="A robot about to do an API request to Chat GPT 4 from Next.js using Javascript" src="https://cdn-images-1.medium.com/max/1024/1*9cyO1Acs9yGiEsZEUXVZOQ.jpeg" /></figure><p><strong><em>Related Story:</em></strong><em> </em><a href="https://www.briefmix.com/startup/trough-of-sorrow"><em>How To Escape The Startup Trough Of Sorrow</em></a></p><h3><strong>Pre-requisites:</strong></h3><p>You need to have been on the Chat GPT 4 waitlist and been accepted by receiving an email in the lines of “You can now access GPT-4 models with 8K context via the existing OpenAI API”. The “Get started” button is not helpful as it just takes you to an overview page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1FhNkDhVC7B93HFC9YNhoA.png" /></figure><h3><strong>How to make the GPT-4 API request using Next.js and Javascript:</strong></h3><ol><li>Create a new API key <a href="https://platform.openai.com/account/api-keys">here</a> (your old ones might not work)</li><li>Create a <a href="https://nextjs.org/docs/api-reference/create-next-app">new</a> Next.js project</li><li>Install OpenAI using your terminal ($ npm i openai)</li><li>In the /pages/api folder of your project, make a new file called gpt4.js</li><li>Paste the code below in your file and <strong>insert your own API key</strong></li></ol><pre>const { Configuration, OpenAIApi } = require(&quot;openai&quot;);<br><br>export default async function handler(req, res) {<br><br>  const configuration = new Configuration({<br>    apiKey: &quot;&lt;INSERT-API-KEY-HERE&gt;&quot;,<br>  });<br><br>  const openai = new OpenAIApi(configuration);<br><br>  const response = await openai.createChatCompletion({<br>    model: &quot;gpt-4&quot;,<br>    messages: [<br>      { role: &quot;system&quot;, content: &quot;You are a helpful assistant.&quot; },<br>      { role: &quot;user&quot;, content: &quot;Who won the world series in 2020?&quot; },<br>      { role: &quot;assistant&quot;, content: &quot;The Los Angeles Dodgers.&quot; },<br>      { role: &quot;user&quot;, content: &quot;Where was it played?&quot; },<br>    ],<br>    max_tokens: 50,<br>    n: 1,<br>    stop: null,<br>    temperature: 1,<br>  });<br><br>  res.status(200).json({ answer: response.data.choices[0].message.content });<br>}</pre><p>6. Start your localhost server (npm run dev). Run your Chat GPT 4 API route by visiting <a href="http://localhost:3000/api/gpt4">http://localhost:3000/api/gpt4</a> and you should see your response.</p><h3><strong>IMPORTANT TO KNOW &amp; FAQ:</strong></h3><p><strong>Why does the ChatGPT API not remember my previous responses?</strong><br>Chat GPT-4 API does not “remember” your responses like when using it in the browser. To have a conversation with it, you need to constantly update and provide the previous conversation to it for context.</p><p>You achieve this by saving the previous response and adding it to the messages array every time you make a new API request / chat message. In the example above, there are 3x previous messages from the user and GPT-4 combined and the 4th one is the “new one” for GPT-4 to answer.</p><p><strong>How can I make sure I’m using the ChatGPT 4 model and not ChatGPT 3?<br></strong>Unsure if you’re actually getting ChatGPT 4 responses or GPT3 / 3.5 Turbo? I fond that you can’t ask the API what model it is using as the actual data set was trained on information pre-dating the actual existence of GPT-4. Easiest way to check is to visit your API <a href="https://platform.openai.com/account/usage">usage</a> page which tells you what model you’re using for your API requests.</p><p><strong>Add a payment method<br></strong>All free API credits expire 3 months after creating your OpenAI account. So if you made an account 6 months ago and then got GPT-4 access last week, you will have no free credits and need to pay for usage. I’ve also seen users having quota issues even with new accounts. To avoid this and to get your API working, just add a credit card — the API is reasonably priced.</p><p><strong>Using the latest packages<br></strong>Make sure you’re using the <a href="https://www.npmjs.com/package/openai">latest</a> NPM OpenAI package — the code example above works with version 3.2.1.</p><p><strong>Organization settings<br></strong>Make sure the organization fields are populated with an organization name and ID, otherwise populate <a href="https://platform.openai.com/account/org-settings">them here</a>. You also need to set the default org in <a href="https://platform.openai.com/account/api-keys">OpenAI API</a> to be the org that gets invited for the limit beta.</p><p><strong>Can’t access ChatGPT 4 in Playground?<br></strong>Make sure the orgs settings are correct (see above) and that the “Mode” dropdown is set to “Chat”. Then select GPT-4 in the “Model” dropdown:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RwumCtYpWyAMZ9c2aW47hg.png" /></figure><p><strong>How much does GPT-4 cost?</strong></p><p>For 8k context lengths:</p><ul><li>$0.03/1k prompt tokens</li><li>$0.06/1k sampled tokens</li></ul><p>For 32k context lengths (not available at time of writing 1 April, 2023):</p><ul><li>$0.06/1k prompt tokens</li><li>$0.12/1k sampled tokens</li></ul><p><strong>What are context lengths?</strong></p><p>Context lengths are the amount of previous conversation (context) you can send to the Chat GPT-4 API to get a response based on previous conversation.</p><p><strong>What’s the difference between prompt and sampled tokens?</strong></p><p>Prompt tokens are what you put into the API request such as previous conversation - the number of tokens in your “prompt”. Sampled tokens are counted for any generated text that the API responds with.</p><p>— — — — — — — — — — — — — — —</p><p><strong><em>Related Story:</em></strong><em> </em><a href="https://www.briefmix.com/startup/setting-objectives-kpis"><em>Spending $1,500,000 on Ads Without Getting a Single Customer</em></a></p><p><strong><em>Weather reports using Chat GPT :</em></strong><em> </em><a href="https://dropory.com/"><em>https://dropory.com</em></a><em> <br>Free weather reports, aggregating 10 years of data to find the best date for your activity, event or wedding — anywhere in the world.</em></p><p><strong><em>Portfolio site:</em></strong><em> </em><a href="https://johanfriedner.com/"><em>https://johanfriedner.com</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c238b47bd88a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>