본문 바로가기
기타

2023.6.13 챗GPT4 API 오픈❗ 뭐가 달라졌을까❓

by 리틀홍콩 2023. 6. 17.
728x90

드디어 고대하던 chatGPT4 API가 오픈되었습니다.

그동안 gpt-3.5-turbo를 사용하였지만, 잘 쓰고 있었지만,, 그래도 언제 gpt4가 오픈되는지 기다리고 있던 저에게 한줄기 빛이었죠.😍😍

위처럼 waitlist에 신청했던 메일로 안내가 왔습니다. (다른 계정으로 신청했던 건 안 왔네요. 우선순위가 있는 건가?)

아주 따끈따끈한 버전입니다.

 

뭐가 달라졌을까❓

역시 자세한 건 공식사이트에서 보시는 게 가장 정확합니다.

 

https://platform.openai.com/docs/guides/gpt

 

OpenAI API

Explore developer resources, tutorials, API docs, and dynamic examples to get the most out of OpenAI's platform.

platform.openai.com

 

아직 현재까지는 기존에 gpt-3.5-turbo버전과 gpt4는 같이 묶여서 안내하고 있습니다.

 

아래 코드에서 gpt-4-0613으로 변경만 하면 최신 업데이트 된 gpt4가 적용됩니다.

(기존 gpt-3.5-turbo-0613 버전도 신규 출시했습니다.)

import openai

openai.ChatCompletion.create(
  model="gpt-4-0613",
  messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Who won the world series in 2020?"},
        {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
        {"role": "user", "content": "Where was it played?"}
    ]
)

학습된 데이터는 기존에 text-davinci-003과 같은 2021년 9월을 가리키고 있습니다.

(그럼 같은 학습된 데이터지만, 좀 더 정교하게 대답을 하는 모델이라고 생각하는 게 맞을 것 같습니다.)

 

다만, 이게 다는 아니라는 점🙏🙏

 

새로운 기능인 function call 

현재 채팅모델에 함수를 호출할 수 있는 기능이 추가되었습니다. chatGPT 플러그인과 비슷한 방식으로 호출할 때, Json형식으로 함수와 파라미터를 보낼 수 있습니다. 이 함수는 사용자의 백엔드 API나 써드파티 외부 API등을 호출 할 수 있습니다. 문맥에서 위 함수를 실행해야 함수를 호출 할 수 있습니다.

 

import openai
import json

# Example dummy function hard coded to return the same weather
# In production, this could be your backend API or an external API
def get_current_weather(location, unit="fahrenheit"):
    """Get the current weather in a given location"""
    weather_info = {
        "location": location,
        "temperature": "72",
        "unit": unit,
        "forecast": ["sunny", "windy"],
    }
    return json.dumps(weather_info)

# Step 1, send model the user query and what functions it has access to
def run_conversation():
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo-0613",
        messages=[{"role": "user", "content": "What's the weather like in Boston?"}],
        functions=[
            {
                "name": "get_current_weather",
                "description": "Get the current weather in a given location",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "location": {
                            "type": "string",
                            "description": "The city and state, e.g. San Francisco, CA",
                        },
                        "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
                    },
                    "required": ["location"],
                },
            }
        ],
        function_call="auto",
    )

    message = response["choices"][0]["message"]

    # Step 2, check if the model wants to call a function
    if message.get("function_call"):
        function_name = message["function_call"]["name"]
        function_args = json.loads(message["function_call"]["arguments"])

        # Step 3, call the function
        # Note: the JSON response from the model may not be valid JSON
        function_response = get_current_weather(
            location=function_args.get("location"),
            unit=function_args.get("unit"),
        )

        # Step 4, send model the info on the function call and function response
        second_response = openai.ChatCompletion.create(
            model="gpt-3.5-turbo-0613",
            messages=[
                {"role": "user", "content": "What is the weather like in boston?"},
                message,
                {
                    "role": "function",
                    "name": function_name,
                    "content": function_response,
                },
            ],
        )
        return second_response

print(run_conversation())

다르게 사용할 수 있는 코드가 바로 'role'에 함수를 추가할 수 있습니다.

 

"model": "gpt-4-0613",
"messages": [
  {"role": "user", "content": "What is the weather like in Boston?"},
  {"role": "assistant", "content": null, "function_call": {"name": "get_current_weather", "arguments": "{ "location\": "Boston, MA"}"}},
  {"role": "function", "name": "get_current_weather", "content": "{"temperature": "22", "unit": "celsius", "description": "Sunny"}"}
],

 

실제 서비스에 어떻게 적용할지는 좀 더 고민해 봐야겠습니다.

 

더 낮아진 API 사용 가격

gpt-3.5-turbo-16k는 가격이 두 배라고 하네요.

입력값은 1k 당 0.003 달러, 출력값은 0.004 달러.

 

 

 

어떤 모델을 사용해야 합니까?

(오역 주의) gpt-4일반적으로 또는 를 사용하는 것이 좋습니다 gpt-3.5-turbo. 이들 중 어느 것을 사용해야 하는지는 모델을 사용하는 작업의 복잡성에 따라 다릅니다. gpt-4일반적으로 다양한 평가 에서 더 잘 수행됩니다 . 특히 gpt-4복잡한 지시를 주의 깊게 따르는 능력이 더 뛰어납니다. 대조적으로 gpt-3.5-turbo복잡한 다중 부분 명령의 한 부분만 따를 가능성이 더 큽니다. "환각"으로 알려진 행동인 정보를 구성하는 것 gpt-4보다 가능성이 적습니다 . 또한 의 4,096개 토큰에 비해 최대 8,192개 토큰 크기로 더 큰 컨텍스트 창이 있습니다 . 그러나 대기 시간이 짧고 토큰당 비용이 훨씬 적은 출력을 반환합니다.gpt-3.5-turbogpt-4gpt-3.5-turbogpt-3.5-turbo

 

 


아직까진 chatGPT만큼 API까지 챙겨주는 서비스는 없는 것 같습니다.

이미 여러 서비스에서 chatGPT를 채택해서 서비스를 구현한 만큼 bard나 기타 서비스가 나온다고 하더라도 기존 서비스를 바꿀만한 혁신을 가져다주지 못한다면, chatGPT를 버릴 이유는 없어 보입니다.

 

개인적으로 3.5-turbo 모델을 쓰다가, 4 모델을 쓴 것 만하더라도 답변에 퀄리티가 꽤 좋다고 느껴졌습니다.

 

좀 더 튜닝을 해봐야 알겠지만, 만족스럽게 쓰고 있습니다.😎😎

 

오늘도 읽어주셔서 감사합니다.

댓글