다음을 통해 공유


Azure OpenAI 도우미 함수 호출

도우미 API는 함수 호출을 지원합니다. 이를 통해 함수의 구조를 도우미에 설명한 다음 인수와 함께 호출해야 하는 함수를 반환할 수 있습니다.

참고 항목

  • 파일 검색은 도우미당 최대 10,000개의 파일을 수집할 수 있으며, 이는 이전보다 500배 이상 높은 수치입니다. 빠르고 다중 스레드 검색을 통해 병렬 쿼리를 지원하며 향상된 순위 재지정 및 쿼리 다시 쓰기 기능을 제공합니다.
    • 벡터 저장소는 API의 새 개체입니다. 파일이 벡터 저장소에 추가되면 자동으로 구문 분석, 청크 분할, 포함되어 검색할 수 있는 상태가 됩니다. 벡터 저장소는 도우미와 스레드에서 사용할 수 있으므로 파일 관리 및 청구를 간소화합니다.
  • 특정 실행에서 특정 도구(예: 파일 검색, 코드 인터프리터, 함수)를 강제로 사용하는 데 사용할 수 있는 tool_choice 매개 변수에 대한 지원이 추가되었습니다.

함수 호출 지원

지원되는 모델

모델 페이지에는 도우미가 지원되는 지역/모델에 대한 최신 정보가 포함되어 있습니다.

병렬 함수를 포함한 함수 호출의 모든 함수를 사용하려면 2023년 11월 6일 이후 릴리스된 모델을 사용해야 합니다.

API 버전

  • 2024-02-15-preview
  • 2024-05-01-preview

함수 예 정의

참고 항목

  • 특정 실행에서 특정 도구(예: file_search, code_interpreter 또는 function)를 강제로 사용하는 데 사용할 수 있는 tool_choice 매개 변수에 대한 지원이 추가되었습니다.
  • 실행은 만든 후 10분 후에 만료됩니다. 만료되기 전에 도구 출력을 제출해야 합니다.
  • Azure Logic Apps를 사용하여 함수 호출을 수행할 수도 있습니다.
from openai import AzureOpenAI
    
client = AzureOpenAI(
    api_key=os.getenv("AZURE_OPENAI_API_KEY"),  
    api_version="2024-02-15-preview",
    azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
    )

assistant = client.beta.assistants.create(
  instructions="You are a weather bot. Use the provided functions to answer questions.",
  model="gpt-4-1106-preview", #Replace with model deployment name
  tools=[{
      "type": "function",
    "function": {
      "name": "getCurrentWeather",
      "description": "Get the weather in location",
      "parameters": {
        "type": "object",
        "properties": {
          "location": {"type": "string", "description": "The city and state e.g. San Francisco, CA"},
          "unit": {"type": "string", "enum": ["c", "f"]}
        },
        "required": ["location"]
      }
    }
  }, {
    "type": "function",
    "function": {
      "name": "getNickname",
      "description": "Get the nickname of a city",
      "parameters": {
        "type": "object",
        "properties": {
          "location": {"type": "string", "description": "The city and state e.g. San Francisco, CA"},
        },
        "required": ["location"]
      }
    } 
  }]
)

함수 읽기

함수를 트리거하는 사용자 메시지로 실행을 시작하면 실행이 보류 상태로 전환됩니다. 실행이 처리된 후 실행은 실행을 검색하여 확인할 수 있는 require_action 상태로 전환됩니다.

{
  "id": "run_abc123",
  "object": "thread.run",
  "assistant_id": "asst_abc123",
  "thread_id": "thread_abc123",
  "status": "requires_action",
  "required_action": {
    "type": "submit_tool_outputs",
    "submit_tool_outputs": {
      "tool_calls": [
        {
          "id": "call_abc123",
          "type": "function",
          "function": {
            "name": "getCurrentWeather",
            "arguments": "{\"location\":\"San Francisco\"}"
          }
        },
        {
          "id": "call_abc456",
          "type": "function",
          "function": {
            "name": "getNickname",
            "arguments": "{\"location\":\"Los Angeles\"}"
          }
        }
      ]
    }
  },
...

함수 출력 제출

그런 다음 호출한 함수의 도구 출력을 제출하여 실행을 완료할 수 있습니다. 위의 required_action 개체에서 참조된 tool_call_id를 전달하여 출력을 각 함수 호출과 일치시킵니다.

from openai import AzureOpenAI
    
client = AzureOpenAI(
    api_key=os.getenv("AZURE_OPENAI_API_KEY"),  
    api_version="2024-02-15-preview",
    azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
    )


run = client.beta.threads.runs.submit_tool_outputs(
  thread_id=thread.id,
  run_id=run.id,
  tool_outputs=[
      {
        "tool_call_id": call_ids[0],
        "output": "22C",
      },
      {
        "tool_call_id": call_ids[1],
        "output": "LA",
      },
    ]
)

도구 출력을 제출한 후 실행은 실행을 계속하기 전에 queued 상태로 전환됩니다.

참고 항목