Python

ChatGPT run by python

First install openai module

$ pip install --upgrade openai
Collecting openai
  Downloading openai-0.27.1.tar.gz (57 kB)
     |████████████████████████████████| 57 kB 395 kB/s
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  1 import openai
  Installing backend dependencies ... done
    Preparing wheel metadata ... done
Collecting aiohttp
  Downloading aiohttp-3.8.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB)
     |████████████████████████████████| 1.0 MB 7.6 MB/s
 <snipped>

Second Deploy code by simple cat

cat <<EOF > openai-question.py   
import openai
openai.api_key = "sk-키는 바꾸셔야 합니다"

question = input('openai에 질문 : ')

completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": f"{question}"}])
print(completion.choices[0].message.content) 
EOF

https://platform.openai.com/docs/api-reference?lang=python

Third get a secret key from openai and change at "sk-키는 바꾸셔야 합니다" item.

https://platform.openai.com/account/api-keys
API Keys

Fouth run openai-question.py

Enjoy it :)

Last updated