시작하기 전에
이 튜토리얼에서는 사용자가 다음 안내를 읽고 따랐다고 가정합니다.
- LlamaIndexQueryPipeline 에이전트 개발:
agent
를LlamaIndexQueryPipelineAgent
의 인스턴스로 개발합니다. - 사용자 인증: 에이전트 쿼리를 위해 사용자로 인증을 수행합니다.
- SDK 가져오기 및 초기화: 필요한 경우 배포된 인스턴스를 가져올 수 있도록 클라이언트를 초기화합니다.
에이전트 인스턴스 가져오기
LlamaIndexQueryPipelineAgent
를 쿼리하려면 먼저 새 인스턴스를 만들거나 기존 인스턴스를 가져와야 합니다.
특정 리소스 ID에 해당하는 LlamaIndexQueryPipelineAgent
를 가져오려면 다음 안내를 따르세요.
Python용 Vertex AI SDK
다음 코드를 실행합니다.
import vertexai
client = vertexai.Client( # For service interactions via client.agent_engines
project="PROJECT_ID",
location="LOCATION",
)
agent = client.agent_engines.get(name="projects/PROJECT_ID/locations/LOCATION/reasoningEngines/RESOURCE_ID")
print(agent)
각 항목의 의미는 다음과 같습니다.
PROJECT_ID
는 에이전트를 개발하고 배포하는 데 사용되는 Google Cloud 프로젝트 ID입니다.LOCATION
: 지원되는 리전 중 하나입니다.RESOURCE_ID
는 배포된 에이전트의 ID이며reasoningEngine
리소스로 등록되어 있습니다.
Python 요청 라이브러리
다음 코드를 실행합니다.
from google import auth as google_auth
from google.auth.transport import requests as google_requests
import requests
def get_identity_token():
credentials, _ = google_auth.default()
auth_request = google_requests.Request()
credentials.refresh(auth_request)
return credentials.token
response = requests.get(
f"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/reasoningEngines/RESOURCE_ID",
headers={
"Content-Type": "application/json; charset=utf-8",
"Authorization": f"Bearer {get_identity_token()}",
},
)
REST API
curl \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/reasoningEngines/RESOURCE_ID
Python용 Vertex AI SDK를 사용하는 경우 agent
객체는 다음을 포함하는 AgentEngine
클래스에 해당합니다.
- 배포된 에이전트에 관한 정보가 포함된
agent.api_resource
agent.operation_schemas()
를 호출하여 에이전트가 지원하는 작업 목록을 반환할 수도 있습니다. 자세한 내용은 지원되는 작업을 참고하세요. - 동기 서비스 상호작용을 허용하는
agent.api_client
- 비동기 서비스 상호작용을 허용하는
agent.async_api_client
이 섹션의 나머지 부분에서는 agent
라는 이름의 AgentEngine
인스턴스가 있다고 가정합니다.
지원되는 작업
LlamaIndexQueryPipelineAgent
에 지원되는 작업은 다음과 같습니다.
query
: 쿼리에 대한 응답을 동기식으로 가져옵니다.
query
메서드는 다음 유형의 인수를 지원합니다.
input
: 에이전트에게 전송할 메시지입니다.
에이전트 쿼리
명령어:
agent.query(input="What is Paul Graham's life in college?")
다음과 동일합니다(전체 형식).
agent.query(input={"input": "What is Paul Graham's life in college?"})
입력 사전을 맞춤설정하려면 프롬프트 템플릿 맞춤설정을 참조하세요.
query()
에 추가 키워드 인수를 전달하여 input
이외의 에이전트 동작을 맞춤설정할 수도 있습니다.
response = agent.query(
input={
"input" = [
"What is Paul Graham's life in college?",
"How did Paul Graham's college experience shape his career?",
"How did Paul Graham's college experience shape his entrepreneurial mindset?",
],
},
batch=True # run the pipeline in batch mode and pass a list of inputs.
)
print(response)
사용 가능한 파라미터의 전체 목록은 QueryPipeline.run
코드를 참조하세요.