로컬 Ollama 환경에서 도구 호출 기능 테스트(using. gpt-oss model)

반응형

OpenAI 에서 드디어 오픈했다. gpt-oss 오픈소스 모델이 공개한 것이다.

https://huggingface.co/openai/gpt-oss-120b

 

openai/gpt-oss-120b · Hugging Face

Try gpt-oss · Guides · Model card · OpenAI blog Welcome to the gpt-oss series, OpenAI’s open-weight models designed for powerful reasoning, agentic tasks, and versatile developer use cases. We’re releasing two flavors of these open models: gpt-oss-1

huggingface.co

 

오늘은 로컬 Ollama 환경에서 gpt-oss 모델을 사용하여 도구사용(function-call, tool-call) 기능을 테스트 해보고자 한다. 

 

도구사용 시나리오
회사에서 연차 사용을 위한 자연어 질의를 Tool Calling 으로 판별이 가능할까?

 

예제

from openai import OpenAI
import json

client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")

 

도구를 정의한다.

파라미터로는 휴가시작과 종료의 날짜정보와 시간정보를 넣었고,

추가적으로 해당 자연어가 어떤 액션(휴가올리기, 취소하기, 조회하기 등)에 해당할지 판별하는 파라미터도 넣었다. 

# 도구 정의 (OpenAI 형식에 맞게 수정)
tools = [
    {
        "type": "function",
        "function": {
            "name": "leave_bot",
            "description": "휴가를 신청할 일시(날짜, 시간)를 파악합니다.",
            "parameters": {
                "type": "object",
                "properties": {
                    "str_date": {
                        "type": "string",
                        "description": "시작 날짜 파악하기(날짜관련 프롬프트 포함되어 있지 않다면 null)"
                    },
                    "str_time": {
                        "type": "string",
                        "description": "시작 시간 파악하기(시간관련 프롬프트 포함되어 있지 않다면 null)"
                    },
                    "end_date": {
                        "type": "string",
                        "description": "종료 날짜 파악하기(날짜관련 프롬프트 포함되어 있지 않다면 null)"
                    },
                    "end_time": {
                        "type": "string",
                        "description": "종료 시간 파악하기(시간관련 프롬프트 포함되어 있지 않다면 null)"
                    },
                    "action_name": {
                        "type": "string",
                        "description": "의도 파악하기(휴가상신/휴가삭제/휴가조회)"
                    }
                },
                "required": ["action_name"]  # null 허용하려면 required에서 제외
            }
        }
    }
]
# 테스트
msg = "다음달 첫째주 수요일 9-11시 휴가 쓸래"

response = client.chat.completions.create(
    model="gpt-oss:120b",
    messages=[{"role": "user", "content": msg}],
    tools=tools
    # functions = json.loads(json.dumps(tools, ensure_ascii = False))
)
print(response.choices[0].message)
if response.choices[0].message.tool_calls:
    args = json.loads(response.choices[0].message.tool_calls[0].function.arguments)
    print(f"--- 파악된 정보 ---")
    for key, value in args.items():
        print(f"  {key}: {value}")
    print(f"-"*15)
else:
    print(response.choices[0].message.content)

 

실행결과 

120b 모델의 경우 복잡한 쿼리(eg. 다음달 첫째주 수요일 등)에도 좋은 응답 성능을 보여주는 것을 확인 했다. 

--- 파악된 정보 ---
  action_name: 휴가상신
  end_date: 2025-09-03
  end_time: 11:00
  str_date: 2025-09-03
  str_time: 09:00
---------------
반응형