Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- overloaed
- vram
- Backoff
- OpenAI
- Flask
- Gunicorn
- onnx #openvino #tf2onnx #openvinokeras
- NLP
- pytorch
- MySQL
- leetcode
- 고유값
- DataLoader
- CentOS
- Python #open #read #파이썬
- ML #머신러닝
- GPU
- GPT API
- docker
- Mecab
- 파이썬 #기초 #응애
- ML
- BitCoin
- Python #for문 #while문 #응애
- UUID
- Anaconda
- GPT
- python
- GCP
- 매매봇
Archives
- Today
- Total
람쥐썬더
[PYTHON] AttributeError: module 'openai' has no attribute 'ChatCompletion' 본문
파이썬
[PYTHON] AttributeError: module 'openai' has no attribute 'ChatCompletion'
람쥐썬더123 2023. 11. 7. 14:31Openai api 이용 시 기존 코드대로 했을 때 해당 클래스가 없다고 나왔다
11월 6일 업데이트 이후(?) 방식이 바뀐 듯 한데 document 참고해서 이용 가능하게 기존 코드를 잡아줬다
기존 )
import openai
import configs
openai.organization = configs.ORGANIZATION
openai.api_key = configs.OPENAI_API_KEY
completion = openai.ChatCompletion()
messages = [{"role": "system", "content": 'message']
gpt_model = 'gpt-4-1106-preview'
response = completion.create(
model = gpt_model,
messages = messages,
temperature = 0.5,
top_p = 0.5
)
message = response["choices"][0]["message"]["content"]
json.loads(message)
변경 )
from openai import OpenAI # 변경 부분
import configs
import json
client = OpenAI(api_key = configs.OPENAI_API_KEY,
organization = configs.ORGANIZATION) # 변경부분
completion = client.chat.completions # 변경부분
messages = [{"role": "system", "content": "message"}]
gpt_model = 'gpt-4-1106-preview'
response = completion.create(
model = gpt_model,
messages = messages,
temperature = 0.5,
top_p = 0.5
)
message = json.loads(response.json())['choices'][0]['message'] # Load Json
message = response.dict()['choices'][0]['message'] # Load Dict in Python
이번 업데이트 이후 동작 방법이 바뀐 것 같고 (1.1.1 추정임)
기존 버전은 정상 작동 (0.27.8)
'파이썬' 카테고리의 다른 글
[PYTHON] FLASK - GUNICORN (0) | 2023.12.31 |
---|---|
[PYTHON] PYTORCH 이미지 DataLoader 구축 플로우 정리 (0) | 2023.11.20 |
[Leetcode] 1337. The K Weakest Rows in a Matrix (0) | 2023.09.18 |
[Leetcode] 1282. Group the People Given the Group Size They Belong To (0) | 2023.09.11 |
[Leetcode] 377. Combination Sum IV (0) | 2023.09.10 |