GPT-3.5 python에서 사용하기

  • Post author:
  • Post category:Coding
  • Post comments:0 Comments
You are currently viewing GPT-3.5 python에서 사용하기

GPT-3 는 OpenAI 가 개발한 대형 언어 모델 (Large Language Model, LLM )이다.

12Billion (120억)개의 paramter를 가지는것이 특징이고

Github Copiliot에 사용되어 유명해졌다.

최근 각광받는 chatGPT 가 GPT-3.5 에 해당하며

무려 170B( 1700억) 개의 parmeter를 가진다.

chatGPT는 23년 2월 기준 아직 python api 가 공개되지 않았지만

같은 GPT-3.5에 속하는 davinci 모델은 python에서 사용 가능하다.

text-davinci-003 는 21년 4분기까지의 데이터로 학습되었기 때문에

chatGPT 에 비해 약간 떨어지지만 충분히 훌륭한 성능을 보여준다.

그래서 사용법은?

링크에서 회원가입이 가능하고 문서 도 잘 만들어져 있다.

openai 패키지 사용법은 해당 문서에 잘 나와 있으니

패키지 없이 사용하는 법을 설명하겠다.

우선 가입 후 링크 에 들어가 api-key를 발급받는다.

api 키만 있으면 코드는 정말 간단하다.

import requests
import json
headers={"Authorization":"Bearer 발급받은API키","Content-Type":"application/json"}
link="https://api.openai.com/v1/completions"
data={"model": "text-davinci-003", "prompt": "let me know how to cook scones ", "temperature": 0.9, "max_tokens": 300}
res=requests.post(link,data=json.dumps(data),headers=headers)
print(res.json()['choices'][0]['text'])

input에 대해 설명하자면 다음과 같다.

  • link:질문에 해당하는 링크이며 image 생성 등에는 다른 링크가 필요하다.
  • prompt: 질문이나 요청을 적으면 된다.
  • temperature: 높을수록 창의적이지만 부정확한 답이 출력될 수 있다. (기본값:1)
  • top_p: 방법은 다르지만 temperature와 같은 역할, temperature와 top_p 둘 중 하나만 사용 (기본값:1)
  • max_tokens: 답변 문장의 최대 길이를 결정함
  • 이외는 링크 참조바람

GPT 3.5 사용결과

상식

질문: let me know how to cook scones.

\rightarrow Ingredients

  • 3 cups all-purpose flour
  • 1 tablespoon baking powder
  • 1/2 teaspoon salt
  • 3/4 cup butter, melted
  • 2 eggs
  • 1/2 cup milk
  • 1/2 cup sugar

Directions

  1. Preheat oven to 400 degrees F (200 degrees C). Grease a baking sheet.
  2. In a large bowl, sift together flour, baking powder and salt.
  3. In a separate bowl, stir together melted butter, eggs and milk.
  4. Make a well in the center of the flour mixture, and pour in the wet ingredients.
  5. Stir together until a soft dough forms. Stir in sugar.
  6. Roll out dough on a lightly floured surface, and cut into desired shapes (e.g. circles or wedges).
  7. Place on prepared baking sheet, and bake for 10 to 12 minutes. Remove from oven, and cool. Serve warm.

굽는 시간, 재료의 양에 차이가 있지만 충분히 조리 가능한 레시피이며

chatGPT로부터 받은 답변도 대동소이 했다.

코딩

질문: suggest me top 5 alternatives of pyqt.

\rightarrow

  1. GTK+
  2. wxPython
  3. Kivy
  4. Tkinter
  5. PySide

사용가능한 라이브러리들을 잘 보여준다.

ChatGPT 에 물어보면 부연설명을 넣어주지만 pyside가 빠지는 점이 아쉽다.

질문: What’s the difference between pyside and pyqt

\rightarrow PySide and PyQt are both Python bindings for the popular Qt cross-platform application and UI framework. The main difference between the two is that PySide is free and open source, while PyQt is proprietary and subject to a commercial license. PySide also has a more liberal license than PyQt, which allows developers to use it for both open source and commercial projects. PySide also has a more modern API, which makes it easier to use than PyQt.

마지막에 엉뚱한 말이 붙었지만 전반적으로 핵심을 잘 파악한 훌륭한 답변이다.

chatGPT가 community 규모에 대해 좀 더 정확한 정보를 덧붙였다.

질문: can you give me streamlit example for python? It’s for drawing graph

\rightarrow

import streamlit as st
import matplotlib.pyplot as plt

#Create some data

x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]

#Create the plot

plt.plot(x, y)

#Add the plot to the Streamlit app

st.pyplot()

pyplot의 argument가 빠졌다는 warning이 뜨지만 잘 plot 된다.

chatGPT 의 답변에는 무의미한 코드가 한줄 있지만 좀 더 상세했다.

GPT 3.5 단점은 없어?

현재 Davinci 모델은 유료이며 1k token(750 단어)당 0.02$의 사용료가

책정되어있다. 그리고 돌아올 수 있는 답변은 최대 4000token(3000단어)이다.

저렴한 가격이지만 chatGPT가 앞으로도 무료 서비스를 제공한다면

일반 사용자에게 merit이 떨어 진다.

또한 chatGPT와 달리 답변에 추가적인 질문이 불가능하다.

유료면 이걸 왜써?

가입시 3개월간 사용가능한 18$의 credit을 제공하기때문에

계정을 만들어가며 사용하면 무한대로 사용이 가능 하다.

게다가 현재 davinci모델은 추가학습( fine-tuning) 이 가능하다.

즉, 업체나 개인별로 자신에게 필요한 데이터 일부를

추가적으로 학습시킬 수 있는 강력한 기능을 제공한다.

현재 chatGPT 는 추후 활용을 위해 피드백을 수집할 뿐

추가적으로 학습이 이루어지지 않는다.

GPT3.5의 추가 학습 및 사용에는 각각

1k token 당 0.03$,0.12$의 비용이 부과된다.

그렇다면 학습에 별도 비용이 발생하지 않는 대체재는 없을까?

다음글에서 chatGPT의 한계점을 짚어보며 대체재에 대해 소개하겠다.


ChatGPT의 python API가 출시 되었다. (23.03.01)

GPT3.5 Turbo – ChatGPT python API 소개

chat GPT 하이브리드 앱 만들기 C# python

관련글

GPT-4 뭐가 달라 졌을까?

빙 생성 AI 까지 넘보는 중

Leave a Reply