코드 인터프리터를 사용하면 에이전트가 샌드박스 실행 환경에서 Python 코드를 작성하고 실행할 수 있습니다. 코드 인터프리터를 사용하도록 설정하면 에이전트가 코드를 반복적으로 실행하여 더 까다로운 코드, 수학 및 데이터 분석 문제를 해결하거나 그래프 및 차트를 만들 수 있습니다. 에이전트가 실행되지 않는 코드를 작성하면 코드 실행이 성공할 때까지 다른 코드를 수정하고 실행하여 이 코드를 반복할 수 있습니다.
중요합니다
코드 인터프리터에는 Azure OpenAI 사용량에 대한 토큰 기반 요금 외에 추가 요금이 부과됩니다. 에이전트가 서로 다른 두 스레드에서 동시에 코드 인터프리터를 호출하는 경우 두 개의 코드 인터프리터 세션이 만들어집니다. 각 세션은 기본적으로 1시간 동안 활성화되며 유휴 시간 제한은 30분입니다.
필수 조건
- 기본 또는 표준 에이전트 환경입니다.
코드 샘플
코드 인터프리터를 사용하여 에이전트 만들기
code_interpreter = CodeInterpreterTool()
# An agent is created with the Code Interpreter capabilities:
agent = project_client.agents.create_agent(
model=os.environ["MODEL_DEPLOYMENT_NAME"],
name="my-agent",
instructions="You are helpful agent",
tools=code_interpreter.definitions,
tool_resources=code_interpreter.resources,
)
사용할 코드 인터프리터용 파일 첨부
파일이 코드 인터프리터와 함께 사용되도록 하려면 이 함수를 upload_and_poll 사용할 수 있습니다.
file = agents_client.files.upload_and_poll(file_path=asset_file_path, purpose=FilePurpose.AGENTS)
print(f"Uploaded file, file ID: {file.id}")
code_interpreter = CodeInterpreterTool(file_ids=[file.id])
코드 인터프리터를 사용하여 에이전트 만들기
var projectEndpoint = System.Environment.GetEnvironmentVariable("ProjectEndpoint");
var modelDeploymentName = System.Environment.GetEnvironmentVariable("ModelDeploymentName");
PersistentAgentsClient client = new(projectEndpoint, new DefaultAzureCredential());
PersistentAgent agent = client.Administration.CreateAgent(
model: modelDeploymentName,
name: "My Friendly Test Agent",
instructions: "You politely help with math questions. Use the code interpreter tool when asked to visualize numbers.",
tools: [new CodeInterpreterToolDefinition()]
);
사용할 코드 인터프리터용 파일 첨부
코드 인터프리터와 함께 파일을 사용하려는 경우 메시지에 첨부할 수 있습니다.
PersistentAgentFileInfo uploadedAgentFile = client.Files.UploadFile(
filePath: "sample_file_for_upload.txt",
purpose: PersistentAgentFilePurpose.Agents);
var fileId = uploadedAgentFile.Id;
var attachment = new MessageAttachment(
fileId: fileId,
tools: tools
);
// attach the file to the message
PersistentThreadMessage message = client.Messages.CreateMessage(
threadId: thread.Id,
role: MessageRole.User,
content: "Can you give me the documented information in this file?",
attachments: [attachment]
);
코드 인터프리터를 사용하여 에이전트 만들기
// Create the code interpreter tool
const codeInterpreterTool = ToolUtility.createCodeInterpreterTool();
// Enable the code interpreter tool during agent creation
const agent = await client.createAgent("gpt-4o", {
name: "my-agent",
instructions: "You are a helpful agent",
tools: [codeInterpreterTool.definition],
toolResources: codeInterpreterTool.resources,
});
console.log(`Created agent, agent ID: ${agent.id}`);
사용할 코드 인터프리터용 파일 첨부
코드 인터프리터와 함께 파일을 사용하려는 경우 도구에 첨부할 수 있습니다.
// Upload file and wait for it to be processed
const filePath = "./examplefile.csv";
const localFileStream = fs.createReadStream(filePath);
const localFile = await client.files.upload(localFileStream, "assistants", {
fileName: "localFile",
});
// Create code interpreter tool
const codeInterpreterTool = ToolUtility.createCodeInterpreterTool([localFile.id]);
코드 인터프리터 도구를 사용하여 에이전트 만들기
curl --request POST \
--url $AZURE_AI_FOUNDRY_PROJECT_ENDPOINT/assistants?api-version=$API_VERSION \
-H "Authorization: Bearer $AGENT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"instructions": "You are an AI assistant that can write code to help answer math questions.",
"tools": [
{ "type": "code_interpreter" }
],
"model": "gpt-4o-mini",
"tool_resources"{
"code interpreter": {
}
}
}'
String agentName = "code_interpreter_agent";
CodeInterpreterToolDefinition ciTool = new CodeInterpreterToolDefinition();
CreateAgentOptions createAgentOptions = new CreateAgentOptions(modelName).setName(agentName).setInstructions("You are a helpful agent").setTools(Arrays.asList(ciTool));
PersistentAgent agent = administrationClient.createAgent(createAgentOptions);
사용할 코드 인터프리터용 파일 첨부
코드 인터프리터와 함께 파일을 사용하려는 경우 도구에 첨부할 수 있습니다.
FileInfo uploadedFile = filesClient.uploadFile(new UploadFileRequest(
new FileDetails(BinaryData.fromFile(htmlFile))
.setFilename("sample.html"), FilePurpose.AGENTS));
MessageAttachment messageAttachment = new MessageAttachment(Arrays.asList(BinaryData.fromObject(ciTool))).setFileId(uploadedFile.getId());
PersistentAgentThread thread = threadsClient.createThread();
ThreadMessage createdMessage = messagesClient.createMessage(
thread.getId(),
MessageRole.USER,
"What does the attachment say?",
Arrays.asList(messageAttachment),
null);
지원되는 모델
모델 페이지에는 에이전트와 코드 인터프리터가 지원되는 지역/모델에 대한 최신 정보가 포함되어 있습니다.
최신 기능, 더 넓은 컨텍스트 창, 최신 학습 데이터의 이점을 활용하려면 최신 모델을 갖춘 에이전트를 사용하는 것이 좋습니다.
지원되는 파일 형식
| 파일 형식 | 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 |
.pdf |
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 |
.tex |
text/x-tex |
.txt |
text/plain |
.css |
text/css |
.jpeg |
image/jpeg |
.jpg |
image/jpeg |
.js |
text/javascript |
.gif |
image/gif |
.png |
image/png |
.tar |
application/x-tar |
.ts |
application/typescript |
.xlsx |
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
.xml |
application/xml 또는 text/xml |
.zip |
application/zip |