| 36번째 줄: |
36번째 줄: |
| | |요금정보 | | |요금정보 |
| | |Fine Tunning도 가능하다. 다양한 모델과 미세조정을 위한 요금은 비고를 참고하자. | | |Fine Tunning도 가능하다. 다양한 모델과 미세조정을 위한 요금은 비고를 참고하자. |
| − | |https://openai.com/pricing#language-models | + | [https://platform.openai.com/account/billing/overview 결제는 이곳에서.] |
| | + | |요금표. https://openai.com/pricing#language-models |
| | |} | | |} |
| | | | |
| − | == 사용 ==
| + | = 사용 = |
| | | | |
| − | === 기본 형태 === | + | = 사용(구버전) = |
| | + | 나온지 얼마나 됐다고, 호출하는 형태가 달라졌다; 굉장히 귀찮은 일이다;; 아래의 방식을 그대로 사용하고 싶다면 <code>pip install openai==0.28</code>을 사용하자. |
| | + | |
| | + | === 기본 형태(채팅) === |
| | 기본 형태가... 결과물에 따라 천차만별이 된다. https://platform.openai.com/docs/introduction<nowiki/>를 보며 만들어가는 게 좋을듯. | | 기본 형태가... 결과물에 따라 천차만별이 된다. https://platform.openai.com/docs/introduction<nowiki/>를 보며 만들어가는 게 좋을듯. |
| | {| class="wikitable" | | {| class="wikitable" |
| 54번째 줄: |
58번째 줄: |
| | | | |
| | openai.api_key = "API키 넣을 자리" | | openai.api_key = "API키 넣을 자리" |
| − | completion = openai.Completion()
| |
| | | | |
| − | response = completion.create( | + | response = openai.ChatCompletion.create( |
| | model="gpt-3.5-turbo" | | model="gpt-3.5-turbo" |
| | messages=[ | | messages=[ |
| 86번째 줄: |
89번째 줄: |
| | ] | | ] |
| | </syntaxhighlight>위처럼 assistant와 user를 추가해 전달하면 이전 대화를 기억하는 것처럼 작동한다. | | </syntaxhighlight>위처럼 assistant와 user를 추가해 전달하면 이전 대화를 기억하는 것처럼 작동한다. |
| | + | |} |
| | + | |
| | + | === 기본 형태(채팅이 아닌 단답 문장 완성형) === |
| | + | 위와 다른 점만 기입하겠다. |
| | + | {| class="wikitable" |
| | + | !채팅형 |
| | + | !단답형 |
| | + | |- |
| | + | |<syntaxhighlight lang="python"> |
| | + | import openai |
| | + | |
| | + | openai.api_key = "API키 넣을 자리" |
| | + | |
| | + | response = openai.ChatCompletion.create( |
| | + | model="gpt-3.5-turbo" |
| | + | messages=[ |
| | + | {'role':'user', 'content':'작성하고 싶은 프롬프트'} |
| | + | ] |
| | + | ) |
| | + | |
| | + | print(response['choices'][0]['message']['content']) # 응답 중 답변만 추출한다. |
| | + | </syntaxhighlight> |
| | + | | |
| | + | # openai.ChatCompletion.create 대신 openai.Completion.create을 사용한다. |
| | + | # model이 아닌, engine에 모델명을 기입한다. |
| | + | # messages가 아닌 prompt가 텍스트 형태로 input이 된다. |
| | + | <syntaxhighlight lang="python3"> |
| | + | import openai |
| | + | openai.api_key = "API키 넣기." |
| | + | # 조건 |
| | + | model = 'text-davinci-003' # 선택할 수 있게! ex) gpt-3.5-turbo |
| | + | max_tokens = 1700 # 입력에 1000정도 사용해서. 출력은 700 이하가 되게끔. |
| | + | |
| | + | response = openai.Completion.create( |
| | + | engine=model, |
| | + | prompt='api 사용을 시도해보고 있어. 아무 말이나 해봐~', |
| | + | max_tokens=max_tokens |
| | + | ) |
| | + | print(response) |
| | + | print('답변') |
| | + | print(response['choices'][0]['text']) # 응답 중 답변만 추출한다. |
| | + | response = response['choices'][0]['text'] |
| | + | </syntaxhighlight> |
| | |} | | |} |
| | [[분류:ChatGPT]] | | [[분류:ChatGPT]] |
| | + | [[분류:인공지능 라이브러리]] |