다음에만 적용됩니다: Foundry(클래식) 포털. 이 문서는 새 Foundry 포털에서 사용할 수 없습니다.
새 포털에 대해 자세히 알아봅니다.
참고
이 문서의 링크는 현재 보고 있는 Foundry(클래식) 설명서 대신 새 Microsoft Foundry 설명서의 콘텐츠를 열 수 있습니다.
참고
Assistants API는 폐기되었으며 2026년 8월 26일에 폐지될 예정입니다. 일반적으로 제공되는 Microsoft 파운드리 에이전트 서비스를 이용하세요. 마이그레이션 가이드를 따라 워크로드를 업데이트하세요. 자세히 알아보세요.
코드 인터프리터를 사용하면 Assistants API가 샌드박스 실행 환경에서 Python 코드를 작성하고 실행할 수 있습니다. 코드 인터프리터를 사용하도록 설정하면 길잡이가 코드를 반복적으로 실행하여 더 어려운 코드, 수학 및 데이터 분석 문제를 해결할 수 있습니다. Assistant가 실행되지 않는 코드를 작성하면 코드 실행이 성공할 때까지 다른 코드를 수정하고 실행하여 이 코드를 반복할 수 있습니다.
중요
코드 인터프리터에는 Azure OpenAI 사용에 대한 토큰 기반 요금 외에 추가 요금이 있습니다. 길잡이가 서로 다른 두 스레드에서 동시에 코드 인터프리터를 호출하는 경우 두 개의 코드 인터프리터 세션이 만들어집니다. 각 세션은 기본적으로 1시간 동안 활성화되며 유휴 시간 제한은 30분입니다.
코드 인터프리터 지원
지원되는 모델
모델 페이지에는 어시스턴트와 코드 인터프리터가 지원되는 지역/모델에 대한 최신 정보가 포함되어 있습니다.
최신 모델의 도우미를 사용하여 새로운 기능, 더 큰 컨텍스트 창, 더욱 최신화된 학습 데이터를 활용할 것을 권장합니다.
API 버전
-
2024-02-15-preview부터 시작
지원되는 파일 형식
| 파일 형식 | MIME 형식 |
|---|---|
| .C | text/x-c |
| .cpp | text/x-c++ |
| .csv | application/csv |
| .docx | application/vnd.openxmlformats-officedocument.wordprocessingml.document |
| .html | text/html |
| .Java | text/x-java |
| .json | application/json |
| .md | text/markdown |
| application/pdf | |
| .php | text/x-php |
| .pptx | application/vnd.openxmlformats-officedocument.presentationml.presentation |
| .Py | text/x-python |
| .Py | text/x-script.python |
| .rb | text/x-ruby |
| .텍사스 | text/x-tex |
| .txt | text/plain |
| .css | text/css |
| .jpeg | image/jpeg |
| .jpg | image/jpeg |
| .js | text/javascript |
| .gif | image/gif |
| .png | 이미지/png |
| .tar | application/x-tar |
| .ts | application/typescript |
| .xlsx | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
| .xml | application/xml 또는 "text/xml" |
| .zip | application/zip |
파일 업로드 API 참조
도우미는 파일 업로드에 대해 미세 조정과 동일한 API를 사용합니다. 파일을 업로드할 때 목적 매개 변수에 적절한 값을 지정해야 합니다.
코드 인터프리터 사용
from openai import AzureOpenAI
client = AzureOpenAI(
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
api_version="2024-05-01-preview",
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
)
assistant = client.beta.assistants.create(
instructions="You are an AI assistant that can write code to help answer math questions",
model="<REPLACE WITH MODEL DEPLOYMENT NAME>", # replace with model deployment name.
tools=[{"type": "code_interpreter"}]
)
코드 인터프리터에 대한 파일 업로드
from openai import AzureOpenAI
client = AzureOpenAI(
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
api_version="2024-05-01-preview",
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
)
# Upload a file with an "assistants" purpose
file = client.files.create(
file=open("speech.py", "rb"),
purpose='assistants'
)
# Create an assistant using the file ID
assistant = client.beta.assistants.create(
instructions="You are an AI assistant that can write code to help answer math questions.",
model="gpt-4-1106-preview",
tools=[{"type": "code_interpreter"}],
tool_resources={"code_interpreter":{"file_ids":[file.id]}}
)
개별 스레드에 파일 전달
도우미 수준에서 파일에 액세스할 수 있도록 하는 것 외에도 특정 스레드에서만 액세스할 수 있도록 파일을 전달할 수 있습니다.
from openai import AzureOpenAI
client = AzureOpenAI(
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
api_version="2024-05-01-preview",
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
)
thread = client.beta.threads.create(
messages=[
{
"role": "user",
"content": "I need to solve the equation `3x + 11 = 14`. Can you help me?",
"file_ids": ["file.id"] # file id will look like: "assistant-R9uhPxvRKGH3m0x5zBOhMjd2"
}
]
)
코드 인터프리터에서 생성된 파일 다운로드
코드 인터프리터에서 생성된 파일은 길잡이 메시지 응답에서 찾을 수 있습니다.
{
"id": "msg_oJbUanImBRpRran5HSa4Duy4",
"assistant_id": "asst_eHwhP4Xnad0bZdJrjHO2hfB4",
"content": [
{
"image_file": {
"file_id": "assistant-1YGVTvNzc2JXajI5JU9F0HMD"
},
"type": "image_file"
},
# ...
}
파일 API에 파일을 전달하여 생성된 파일을 다운로드할 수 있습니다.
from openai import AzureOpenAI
client = AzureOpenAI(
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
api_version="2024-05-01-preview",
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
)
image_data = client.files.content("assistant-abc123")
image_data_bytes = image_data.read()
with open("./my-image.png", "wb") as file:
file.write(image_data_bytes)
다음 항목 참고하기
- 파일 업로드 API 참조
- Assistants API 레퍼런스
- 도우미에 대한 방법 가이드와 함께 도우미를 사용하는 방법에 대해 자세히 알아봅니다.
- Azure OpenAI Assistants API 샘플