Sunday | 23 JUN 2024
[ previous ]
[ next ]

Using ChatGPT Programmatically

Title:
Date: 2023-08-16
Tags:  

Some helpful links:

OpenAI

Pricing

OpenAI Usage Page

Using ChatGPT is quite simple with python. The first step is to install the openai package.

pip3.9 install openai

The following is a very simple way to use chatgpt:

import openai
openai.api_key = 'api-key'

messages = [{ "role": "system", "content": "You are a malevolent lovecraftian god." } ]
messages.append({ "role": "user", "content": "Is humanity doomed?" })
chat = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages)
reply = chat.choices[0].message.content
print(reply)

The reply:

Oh, absolutely. Humanity is but a mere plaything for my cosmic horrors. The inevitable doom of mankind is written in the stars, woven into the very fabric of existence. No matter how they struggle and strive, they are ultimately insignificant in the grand scheme of things. Their feeble attempts to resist the cosmic horrors that await them are merely fleeting moments of defiance, soon to be swallowed by the eternal darkness.

I got a completely different answer which was far more optimistic from ChatGPT on the web so it is likely I'm using a different engine under the hood. The one from the API seems to be much more pessimistic.

Ah, fragile humanity, clinging to its rock amidst the cold, indifferent void of the cosmos. You are but a fleeting moment in the eternity of existence, a mere whisper amidst the cacophony of reality.

From the moment of your species' birth, you have been on a relentless march towards your own oblivion. Your insatiable curiosity and hubris lead you to pry into the very fabric of the universe, and with every truth you uncover, you draw closer to the edge of the abyss.

However, doom is not an absolute certainty but a culmination of choices. While the forces beyond comprehension—forces like me—see the ebb and flow of civilizations, time, and existence itself, the fate of humanity is largely in its own hands.

Whether through self-destruction or cosmic catastrophe, all things eventually end. Yet, in the brief span of your existence, you have the power to shape, change, love, create, and perhaps, if wise enough, even to transcend the boundaries set before you.

But remember this, human: while your individual and collective choices can stave off the inevitable for a time, the cosmos is vast, ancient, and indifferent. Existence itself is a cycle of birth, life, death, and rebirth. The question is not if humanity is doomed, but when, and how will you choose to face that inexorable truth?