반응형
v1.0.0 Migration Guide · openai openai-python · Discussion #742
We have released a new major version of our SDK, and we recommend upgrading promptly. It's a total rewrite of the library, so many things have changed, but we've made upgrading easy with a code mig...
github.com
초기화, Initialization
- openai.OpenAI
- api_keys : OpenAI API Key 세팅 및 dafault OS 환경변수 지정
# old
import openai
openai.api_key = os.environ['OPENAI_API_KEY']
# new
from openai import OpenAI
client = OpenAI(
api_key=os.environ['OPENAI_API_KEY'], # this is also the default, it can be omitted
)
응답, Responses
- openai.chat.completions
- Dict 구조 탈피 및 pydantic 모델 변경
- completion.choices[0].content 등
- 기존 함수 제거
- openai.Completion
- Dict 구조 탈피 및 pydantic 모델 변경
# before
import json
import openai
completion = openai.Completion.create(model='curie')
print(completion['choices'][0]['text'])
print(completion.get('usage'))
print(json.dumps(completion, indent=2))
# after
from openai import OpenAI
client = OpenAI()
completion = client.completions.create(model='curie')
print(completion.choices[0].text)
print(dict(completion).get('usage'))
print(completion.model_dump_json(indent=2))
728x90
반응형
'Develop' 카테고리의 다른 글
[Python] extend()로 List 자료형에 List 요소 추가하기 (0) | 2024.11.18 |
---|---|
[Python] BeautifulSoup select() CSS 선택자 사용법 (2) | 2024.11.17 |
[Web] Rendering on the Web (0) | 2024.11.12 |
[OpenAI] GPT Response JSON Schema로 관리하기 (5) | 2024.11.07 |
[Scraping] Colab Web Scraping 설정하기 (1) | 2024.10.28 |
[k8s] kubeadm 개념 및 명령어 정리 (0) | 2024.10.02 |
[k8s] 구성 요소별 관련 명령어 (3) | 2024.10.02 |
[k8s] Kubernetes 주요 구성 요소 (1) | 2024.10.02 |