Utilizzare un agente della pipeline di query LlamaIndex

Prima di iniziare

Questo tutorial presuppone che tu abbia letto e seguito le istruzioni riportate in:

Ottieni un'istanza di un agente

Per eseguire query su un LlamaIndexQueryPipelineAgent, devi prima creare una nuova istanza o ottenerne una esistente.

Per ottenere il LlamaIndexQueryPipelineAgent che corrisponde a un ID risorsa specifico:

SDK Agent Platform

Esegui questo codice:

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)

dove

Libreria delle richieste Python

Esegui questo codice:

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()}",
    },
)

API REST

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

Quando utilizzi l'SDK Agent Platform, l'oggetto agent corrisponde a una AgentEngine classe che contiene quanto segue:

Il resto di questa sezione presuppone che tu abbia un'istanza AgentEngine, denominata agent.

Operazioni supportate

Le seguenti operazioni sono supportate per LlamaIndexQueryPipelineAgent:

  • query: per ottenere una risposta a una query in modo sincrono.

Esegui query sull'agente

Per eseguire query sull'agente, utilizza il .query metodo:

agent.query(input="What is Paul Graham's life in college?")

è equivalente a quanto segue (in forma completa):

agent.query(input={"input": "What is Paul Graham's life in college?"})

Per personalizzare il dizionario di input, vedi Personalizzare il modello di prompt.

Puoi anche personalizzare il comportamento dell'agente oltre a input passando argomenti con parole chiave aggiuntivi a query().

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)

Per un elenco completo dei parametri disponibili, consulta il codice QueryPipeline.run.

Passaggi successivi