가볍게 배우고 깊게 즐기고 오래 남기기
[OpenAI & GPT | Error 해결방안] APIRemovedInV1 : no longer supported in openai>=1.0.0 (Azure OpenAI ) 본문
[OpenAI & GPT | Error 해결방안] APIRemovedInV1 : no longer supported in openai>=1.0.0 (Azure OpenAI )
Awesomist 2023. 12. 7. 18:08
APIRemovedInV1:
You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the API.
You can run `openai migrate` to automatically upgrade your codebase to use the 1.0.0 interface.
Alternatively, you can pin your installation to the old version, e.g. `pip install openai==0.28`
A detailed migration guide is available here: https://github.com/openai/openai-python/discussions/742
The OpenAI Python library provides convenient access to the OpenAI REST API from any Python 3.7+ application. The library includes type definitions for all request params and response fields, and offers both synchronous and asynchronous clients powered by httpx.
The SDK was rewritten in v1, which was released November 6th 2023. See the v1 migration guide, which includes scripts to automatically update your code.
[번역]
OpenAI 파이썬 라이브러리는 파이썬 3.7+ 애플리케이션 버전에 상관없이 OpenAI REST API임.
SDK는 2023년 11월 6일에 출시된 v1에서 다시 작성됨.
코드를 자동으로 업데이트하는 스크립트가 포함된 v1 migration guide 를 참조해서 코드를 바꾸시길!
★ Azure OpenAI 유저는 이걸 참고 Microsoft's Azure-specific migration guide.
내가 뭐 힘있나, 쓰고 싶으면 바꿔야지.
해당 변경 건은 파이썬에만 해당되는 내용이라 C#이나 기타 언어에는 아직 해당되지 않는 영역이다.
[As-is - openai ver. 0.28]
# openai == 0.28 인 경우 / print(openai.VERSION)으로 확인할 것
import openai
import json #개인적선호
openai_response = openai.ChatCompletion.create(
api_type = "azure",
deployment_id = 'gpt-35-turbo-16k',
messages = [{'role': 'user', 'content': {prompt}]
)
data = response['choices'][0]['message']['content']
# Function Call을 사용하는 경우
# data = json.loads(response['choices'][0]['message']['function_call']['arguments'])
print(data)
[To-be - openai ver. 1.X (1.3.7 기준)]
# openai == 0.28 인 경우 / print(openai.VERSION)으로 확인할 것
import openai
import json #개인적선호
openai_response = openai.ChatCompletion.create(
api_type = "azure",
deployment_id = 'gpt-35-turbo-16k',
messages = [{'role': 'user', 'content': {prompt}]
)
data = response.choices[0].message.content
# Function Call을 사용하는 경우
# data = json.loads(response.choices[0].message.function_call.arguments)
print(data)
무엇이 바뀌었나
변경사항 1 : Client 중심으로 변경 (인스턴스화)
* Client 하위 객체로 변경되면서 내부적으로 보다 정규화된 문법으로 구조가 변경되었다
(ex) openai.ChatCompletion.create / openai.Embedding.create (X)
→ client.chat.competions.create() / client.embeddings.create() (O)
* Azure OpenAI 호출해야 하는 모듈도 변경되었다
(ex) create 함수 내에서 openai.api_type = "azure" (X)
→ from openai import AzureOpenAI + AzureOpenAI() 호출 (O)
import os
from openai import AzureOpenAI #모듈 명시적 분리
# Client 중심 문법으로 변경
client = AzureOpenAI(
api_key = os.getenv("AZURE_OPENAI_KEY"),
api_version = "2023-07-01-preview",
azure_endpoint =os.getenv("AZURE_OPENAI_ENDPOINT")
)
변경사항 2 : Naming ! 함수 호출 규약과 파라미터가 보다 명시적으로 변경되었다
* 기존에 Azure OpenAI API의 경우는 여러모로 차이가 있었던 파라미터도 통일되었다. (개인적으로 가장 반가운 변화
(ex) engine / deployement_id (X) → model (O)
* 전체 변경점 공유
OpenAI Python 0.28.1 | OpenAI Python 1.x |
openai.api_base | openai.base_url |
openai.proxy | openai.proxies |
openai.InvalidRequestError | openai.BadRequestError |
openai.Audio.transcribe() | client.audio.transcriptions.create() |
openai.Audio.translate() | client.audio.translations.create() |
openai.ChatCompletion.create() | client.chat.completions.create() |
openai.Completion.create() | client.completions.create() |
openai.Edit.create() | client.edits.create() |
openai.Embedding.create() | client.embeddings.create() |
openai.File.create() | client.files.create() |
openai.File.list() | client.files.list() |
openai.File.retrieve() | client.files.retrieve() |
openai.File.download() | client.files.retrieve_content() |
openai.FineTune.cancel() | client.fine_tunes.cancel() |
openai.FineTune.list() | client.fine_tunes.list() |
openai.FineTune.list_events() | client.fine_tunes.list_events() |
openai.FineTune.stream_events() | client.fine_tunes.list_events(stream=True) |
openai.FineTune.retrieve() | client.fine_tunes.retrieve() |
openai.FineTune.delete() | client.fine_tunes.delete() |
openai.FineTune.create() | client.fine_tunes.create() |
openai.FineTuningJob.create() | client.fine_tuning.jobs.create() |
openai.FineTuningJob.cancel() | client.fine_tuning.jobs.cancel() |
openai.FineTuningJob.delete() | client.fine_tuning.jobs.create() |
openai.FineTuningJob.retrieve() | client.fine_tuning.jobs.retrieve() |
openai.FineTuningJob.list() | client.fine_tuning.jobs.list() |
openai.FineTuningJob.list_events() | client.fine_tuning.jobs.list_events() |
openai.Image.create() | client.images.generate() |
openai.Image.create_variation() | client.images.create_variation() |
openai.Image.create_edit() | client.images.edit() |
openai.Model.list() | client.models.list() |
openai.Model.delete() | client.models.delete() |
openai.Model.retrieve() | client.models.retrieve() |
openai.Moderation.create() | client.moderations.create() |
openai.api_resources | openai.resources |
gpt 3.5가 모델과 문법을 정례화시키는 계기가 된 것처럼, 내부 최적문법 검증이 어느 정도 끝났다는 것으로 보인다.
11.6 마이그레이션도 개발 프레임워크를 정례화 시키는 시작점인 것 같다.
'솔루션 Tip > chatGPT & Prompt' 카테고리의 다른 글
[OpenAI||사담] Sora Week, 우리는 어디로 (1) | 2024.02.16 |
---|---|
AI for Fun || ChatGPT 신규 모델 테스트 - MS Azure OpenAI gpt-4-turbo-preview 대답비교 (2023.11.06 updated) (0) | 2023.11.29 |
[Study, ing] LLM의 컨텍스트를 확장시키는 MemGPT (Memory-GPT) (0) | 2023.11.10 |
Python & Bookmark || OpenAI와 Azure OpenAI 코드 문법 차이 (0) | 2023.11.02 |
Azure & OpenAI || 내년에 Azure OpenAI에서 서비스 OFF되는 모델들 (2023.10.11 Azure Article) (0) | 2023.10.12 |