API for interacting with paperqa.app
Project description
paperqa-api
Python client for interacting with the PaperQA server
Installation
Python 3.11+ is required for this package
pip install pqapi
Authentication
Make sure to set the environment variable PQA_API_KEY
to your API token:
export PQA_API_KEY=pqa-...
API keys generally have a rate limit associated with them that is based on queries per day. These are based on a rolling window, rather than resetting at a specific time. You will receive 429s if you have exceeded your rate limit on submission.
Basic Usage
Simple Synchronous Queries
The simplest way to use the API is with synchronous queries:
import pqapi
response = pqapi.agent_query("Are COVID-19 vaccines effective?")
print(response.answer)
Async Queries
You can also make asynchronous queries:
import pqapi
response = await pqapi.async_agent_query(query)
These still require an open connection though, so do not accumulate too many of them. Each query takes between 1 and 5 minutes generally.
Advanced Features
Batch Job Processing
For running multiple long-running queries efficiently, use the job submission API:
import asyncio
import pqapi
# Define multiple queries
queries = [
'What is the elastic modulus of gold?',
'What is the elastic modulus of silver?',
'What is the elastic modulus of copper?'
]
# Submit jobs
jobs = [pqapi.submit_agent_job(query=q) for q in queries]
# Poll for results
results = asyncio.run(pqapi.gather_pqa_results_via_polling(
[job['metadata']['query_id'] for job in jobs]
))
The results will include:
question
: Your original query textrequest
: Serialized settings used in your queryresponse
: Serializedpqapi.AnswerResponse
object
Using Templates
You can use predefined templates that you develop and save on paperqa.app:
# Single query with template
response = pqapi.agent_query(
'The melting point of gold is 1000F.',
named_template='check for contradiction'
)
# Batch jobs with templates
contradictions = [
{
'query': 'Gold can be transmuted into platinum.',
'named_template': 'check for contradiction'
},
]
contradiction_jobs = [pqapi.submit_agent_job(**c) for c in contradictions]
results = asyncio.run(pqapi.gather_pqa_results_via_polling(
[job['metadata']['query_id'] for job in contradiction_jobs]
))
AnswerResponse Object
The response object contains detailed information about your query:
- Sources used
- Cost information
- Other metadata
Access the main specific answer text with:
print(response.answer)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pqapi-7.0.5.tar.gz
.
File metadata
- Download URL: pqapi-7.0.5.tar.gz
- Upload date:
- Size: 1.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ba7c978817241178c1d6741aad39f65c17dda3389389f59ccb406305d6e3c4d |
|
MD5 | eba123a1ff77928f7e802b9cceef485d |
|
BLAKE2b-256 | c142d2829ccb1d4b405497fbc57ca6dcff20bbf21f18bfe382804e2d9a37e1ab |
File details
Details for the file pqapi-7.0.5-py3-none-any.whl
.
File metadata
- Download URL: pqapi-7.0.5-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad6a2110242e1f87e6cd25a89c47bb1b589db9d8253339de9cc1865dbd4220bf |
|
MD5 | 102ae837f176d017f7bfc3ee01585208 |
|
BLAKE2b-256 | 749da0c59e0c3bd0f58d51a206d2925a94dc3c9931cf3b4c3fdabb3bd181a466 |