Query API Reference
This page documents the query API functionality of PromptSite.
promptsite.query.Query
Query module for PromptSite.
This module provides query functionality for retrieving and filtering prompts, versions, and runs from a PromptSite instance. It includes base Query class and specialized query classes for different types of data.
Classes:
Name | Description |
---|---|
Query |
Base query class providing common query functionality |
PromptQuery |
Query class for retrieving and filtering prompts |
VersionQuery |
Query class for retrieving and filtering versions |
RunQuery |
Query class for retrieving and filtering runs |
Example
ps = PromptSite()
Get all prompts as list of dicts
prompts = ps.prompts.all()
Get all prompts as DataFrame
prompts_df = ps.prompts.as_df()
Get specific columns from versions
versions_df = ps.versions.only(['version_id', 'content']).as_df()
Filter runs by prompt_id
runs_df = ps.runs.where(prompt_id='prompt1').as_df()
__init__(ps)
Initialize the query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ps
|
PromptSite
|
PromptSite instance |
required |
all()
Get all prompts.
as_df()
Get the results as a pandas DataFrame.
one()
Get the first item in the query.
only(columns)
Select only the specified columns.
where(**kwargs)
Filter the query.
promptsite.query.PromptQuery
Bases: Query
Query Class for prompts.
This class provides a query interface for retrieving and filtering prompts from a PromptSite instance. It allows for selecting specific columns, filtering by attributes, and retrieving the prompts.
__init__(ps)
Initialize the query.
all()
Get all prompts.
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of dictionaries containing prompt data |
where(prompt_id)
Filter the query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt_id
|
str
|
The ID of the prompt to filter by |
required |
Returns:
Name | Type | Description |
---|---|---|
PromptQuery |
PromptQuery
|
The filtered query |
promptsite.query.VersionQuery
Bases: Query
Query Class for versions.
This class provides a query interface for retrieving and filtering versions from a PromptSite instance. It allows for selecting specific columns, filtering by attributes, and retrieving the versions.
__init__(ps)
Initialize the query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ps
|
PromptSite
|
PromptSite instance |
required |
all()
Get all versions.
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of dictionaries for versions |
where(prompt_id, version_id=None)
Filter the query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt_id
|
str
|
The ID of the prompt to filter by |
required |
version_id
|
str
|
The ID of the version to filter by |
None
|
Returns:
Name | Type | Description |
---|---|---|
VersionQuery |
VersionQuery
|
The filtered query |
promptsite.query.RunQuery
Bases: Query
Query Class for runs.
This class provides a query interface for retrieving and filtering runs from a PromptSite instance. It allows for selecting specific columns, filtering by attributes, and retrieving the runs.
__init__(ps)
Initialize the query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ps
|
PromptSite
|
PromptSite instance |
required |
all()
Get all runs.
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of dictionaries for runs |
where(prompt_id, version_id=None, run_id=None)
Filter the query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt_id
|
str
|
The ID of the prompt to filter by |
required |
version_id
|
str
|
The ID of the version to filter by |
None
|
run_id
|
str
|
The ID of the run to filter by |
None
|
Returns:
Name | Type | Description |
---|---|---|
RunQuery |
RunQuery
|
The filtered query |