728x90
๋ฐ์ํ
๋ชจ๋ ์ค์น
pip install openai
~/dev/gpt.py
import openai
import sys
openai.api_key = "์์ ์ API ํ ํฐ์ ์ฌ๊ธฐ์ ์
๋ ฅ"
messages = [
{"role": "system", "content": "You are a helpful assistant."},
]
def request(text:str):
global messages
if len(messages) >= 30:
messages = messages[-10:]
query = text
messages.append({"role": "user", "content": query})
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages,
stream=True,
max_tokens=255
)
answer = ""
for chunk in response:
if "content" in chunk['choices'][0]['delta']:
word = chunk['choices'][0]['delta']['content']
print(word, end="")
request(" ".join(sys.argv[1:]))
bash ํ๊ฒฝ๋ณ์ ๋ฑ๋ก
$ nano ~/.bashrc
# ๋งจ ํ๋จ์ ์๋ ๋ช
๋ น์ด ์ถ๊ฐ
alias gpt="python3 ~/dev/gpt.py"
$ source ~/.bashrc
์ฌ์ฉ ๋ฐฉ๋ฒ
$ gpt ํ์ด์ฌ์ผ๋ก hello world๋ฅผ ์ถ๋ ฅ์ ํ๋ ค๋ฉด?
๋ค์๊ณผ ๊ฐ์ด ์ฝ๋๋ฅผ ์์ฑํ์ธ์.
```
print("hello world")
```
์ด ์ฝ๋๋ฅผ ์คํํ๋ฉด "hello world" ๋ผ๋ ๋ฉ์์ง๊ฐ ์ถ๋ ฅ๋ฉ๋๋ค.
728x90
๋ฐ์ํ
'๐จ๐ผโ๐ป๊ฐ๋ฐ > ํ์ด์ฌ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ํ์ด์ฌ - ๋ก๋ฉ๋ฐ(Progress Bar) ๊ตฌํ ๋ชจ๋(tqdm) (0) | 2023.07.17 |
---|---|
ํ์ด์ฌ - PyAutoGUI๊ฐ ์๋ ๊ฒฝ์ฐ ๋์ฒด ๊ฐ๋ฅํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ(PyDirectInput) (0) | 2023.07.15 |
ํ์ด์ฌ - ๋ ์ง์คํธ๋ฆฌ ์กฐ์(winreg) (0) | 2023.05.05 |
ํ์ด์ฌ - pyinstaller ๊ด๋ฆฌ์ ๊ถํ์ผ๋ก ์คํ ํ๊ธฐ (0) | 2023.05.05 |
ํ์ด์ฌ - ๋งฅ ์ฃผ์ ๋ณ๊ฒฝ(changeMAC) (0) | 2023.05.02 |