How Subscribers can query AI Agents?
Once a user or agent is a subscriber of Payment Plan, if this Plan has some AI Agents or Services attached to it, the user can query these AI Agents or Services.
For identifying the user as a valid subscriber, they need to query the HTTP requests to AI Agent via a Nevermined Proxy instance and sending a valid Access Token. This is sent using the standard HTTP Authorization header.
Nevermined Proxy instances are standard HTTP Proxies in charge of authorize users trying to access AI Agents or Services.
Once a user is a subscriber sending a request is quite simple.
Get the AI Agent or Service Access Token
- Python
- Typescript
access_config = payments.get_service_token(agent_DID)
# OUTPUT: accessConfig:
# {
# accessToken: 'eJyNj0sKgDAURP9lJQ ....',
# neverminedProxyUri: 'https://proxy.testing.nevermined.app'
# }
const subscriberQueryOpts = await payments.getServiceAccessConfig(agentDID)
// OUTPUT: subscriberQueryOpts:
// {
// accessToken: 'eJyNj0sKgDAURP9lJQ ....',
// neverminedProxyUri: 'https://proxy.testing.nevermined.app'
// }
Sending a task to the AI Agent implementing the Nevermined Query Protocol
The Nevermined Query Protocol standardizes the interface of AI Agents and Services. This means that if an AI Agent implements this protocol, the user can query the AI Agent in a generic way.
- Python
- Typescript
# Here we are configuring the Task we are sending to the Agent. Please check the Query Protocol documentation for more information.
# https://docs.nevermined.io/docs/protocol/query-protocol#tasks-attributes
ai_task = {
query: "https://www.youtube.com/watch?v=0tZFQs7qBfQ",
name: "transcribe",
"additional_params": [],
"artifacts": []
}
task_result = payments.ai_protocol.create_task(agentDID, ai_task)
// Here we are configuring the Task we are sending to the Agent. Please check the Query Protocol documentation for more information.
// https://docs.nevermined.io/docs/protocol/query-protocol#tasks-attributes
const aiTask = {
query: "https://www.youtube.com/watch?v=0tZFQs7qBfQ",
name: "transcribe",
"additional_params": [],
"artifacts": []
}
// the subscriberQueryOpts comes from the previous step the previous step
const taskResult = await payments.query.createTask(agentDID, aiTask, subscriberQueryOpts)
// OUTPUT: taskResult:
// {
// status: 201,
// data: { task_id: 'task-1234' }
// }
Sending a task to the AI Agent or Service
Nevermined recommends to use the Nevermined Query Protocol but doesn't enforce it.
Because Nevermined authorizes standard HTTP Requests can be used to protect any kind of AI Agent or Service exposing an HTTP API.
export AGENT_ACCESS_TOKEN="eJyNj0sKgDAURP9lJQ..."
curl -k -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $AGENT_ACCESS_TOKEN" -d "{'query': 'hey there'}" https://proxy.testing.nevermined.app/ask