Azure 컨테이너 앱 동적 세션 통합
Azure 컨테이너 앱 동적 세션 통합
LangChain JavaScript로 Azure 컨테이너 앱 동적 세션 도구와 통합하는 방법을 알아봅니다.
Azure Container Apps dynamic sessions은 다른 워크로드와의 강한 격리를 요구하는 코드나 애플리케이션을 실행하는 데 이상적인 안전한 샌드박스 환경에 빠르게 접근할 수 있게 합니다.
Azure Container Apps dynamic sessions과 그 코드 해석 기능에 대해 더 자세히 알아보려면 이 페이지를 참조하세요. Azure 계정이 없다면 무료 계정을 만들어 시작할 수 있습니다.
출처: 문서
본문
설정
먼저 @langchain/azure-dynamic-sessions 패키지를 설치해야 합니다:
LangChain 패키지 설치에 대한 일반적인 지침은 이 섹션을 참조하세요.
npm install @langchain/azure-dynamic-sessions @langchain/core
또한 실행 중인 코드 해석기 세션 풀 인스턴스가 있어야 합니다. Azure CLI를 사용해 이 가이드를 따라 버전을 배포할 수 있습니다.
인스턴스가 실행되면 그것에 대한 Azure Entra 인증을 제대로 설정했는지 확인해야 합니다.
신원에 역할을 추가한 후 세션 풀 관리 엔드포인트(session pool management endpoint) 를 검색해야 합니다. Azure Portal의 인스턴스 "Overview" 섹션에서 찾을 수 있습니다. 그런 다음 다음 환경 변수를 설정하세요:
AZURE_CONTAINER_APP_SESSION_POOL_MANAGEMENT_ENDPOINT=<your_endpoint>
사용 예시(Usage example)
아래는 새 Python 코드 해석기 세션을 만들고, 도구를 호출하고, 결과를 출력하는 간단한 예시입니다.
import { SessionsPythonREPLTool } from "@langchain/azure-dynamic-sessions";
const tool = new SessionsPythonREPLTool({
poolManagementEndpoint:
process.env.AZURE_CONTAINER_APP_SESSION_POOL_MANAGEMENT_ENDPOINT || "",
});
const result = await tool.invoke("print('Hello, World!')\n1+2");
console.log(result);
// {
// stdout: "Hello, World!\n",
// stderr: "",
// result: 3,
// }
여기서는 Azure OpenAI 채팅 모델을 사용해 Python 코드 해석기 세션 도구를 호출해 코드를 실행하고 결과를 얻는 완전한 예시입니다:
import type { ChatPromptTemplate } from "@langchain/core/prompts";
import { pull } from "@langchain/classic/hub";
import { AgentExecutor, createToolCallingAgent } from "@langchain/classic/agents";
import { SessionsPythonREPLTool } from "@langchain/azure-dynamic-sessions";
import { AzureChatOpenAI } from "@langchain/openai";
const tools = [
new SessionsPythonREPLTool({
poolManagementEndpoint:
process.env.AZURE_CONTAINER_APP_SESSION_POOL_MANAGEMENT_ENDPOINT || "",
}),
];
// Note: you need a model deployment that supports function calling,
// like `gpt-35-turbo` version `1106`.
const llm = new AzureChatOpenAI({
temperature: 0,
});
// Get the prompt to use - you can modify this!
// If you want to see the prompt in full, you can at:
// https://smith.langchain.com/hub/jacob/tool-calling-agent
const prompt = await pull<ChatPromptTemplate>("jacob/tool-calling-agent");
const agent = await createToolCallingAgent({
llm,
tools,
prompt,
});
const agentExecutor = new AgentExecutor({
agent,
tools,
});
const result = await agentExecutor.invoke({
input:
"Create a Python program that prints the Python version and return the result.",
});
console.log(result);
관련 자료(Related)
- 도구 개념 가이드
- 도구 how-to 가이드
더 알아보기 (Learn more)
- 이 문서를 MCP로 연결하면 Claude, VSCode 등에서 실시간 답변을 받을 수 있어요.
- GitHub에서 이 페이지 편집하기 또는 이슈 제출하기.