검색
검색
공개 노트 검색
회원가입로그인

클로드 API 에서 이제 도구를 사용할 수 있네요.

요약
  • 클로드 API에서는 다양한 도구를 사용할 수 있음
  • 도구를 사용해야 할 때는 stop_reason에 tool_use를 응답
  • 내, 외부 도구를 이용해 값 추출 및 함수 사용 가능

Claude tools

클로드 API 에서 도구를 사용할 수 있습니다. 사용할 도구를 프롬프트에 같이 보내면 도구를 사용해야 하는 상황일 때 클로드가 stop_reason 에 tool_use 를 응답하는 형식입니다. 이 때 내, 외부 도구를 사용해서 필요한 값을 추출해 함수를 사용하면 됩니다. (ChatGPT의 fuction calling 이랑 똑같군요.)

요청 보내기 예시

curl https://api.anthropic.com/v1/messages \
  -H "content-type: application/json" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "anthropic-beta: tools-2024-04-04" \
  -d '{
    "model": "claude-3-opus-20240229",
    "max_tokens": 1024,
    "tools": [
      {
        "name": "get_weather",
        "description": "Get the current weather in a given location",
        "input_schema": {
          "type": "object",
          "properties": {
            "location": {
              "type": "string",
              "description": "The city and state, e.g. San Francisco, CA"
            }
          },
          "required": ["location"]
        }
      }
    ],
    "messages": [
      {
        "role": "user",
        "content": "What is the weather like in San Francisco?"
      }
    ]
  }'

응답 예시

{
  "name": "get_weather",
  "description": "Get the current weather in a given location",
  "input_schema": {
    "type": "object", 
    "properties": {
      "location": {
        "type": "string",
        "description": "The city and state, e.g. San Francisco, CA"
      },
      "unit": {
        "type": "string",
        "enum": ["celsius", "fahrenheit"],
        "description": "The unit of temperature, either 'celsius' or 'fahrenheit'"
      }
    },
    "required": ["location"]
  }
}

다양한 도구를 만들어서 사용할 수 있습니다. 웹의 내용 가져오기, 파이썬 REPL 돌리기, 검색, 함수 등 다양한 커스텀 도구를 만들어서 사용할 수 있을 것 같습니다.

공유하기
카카오로 공유하기
페이스북 공유하기
트위터로 공유하기
url 복사하기
조회수 : 368
heart
T
페이지 기반 대답
AI Chat