Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg-py/src/querychat/_querychat.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(

self.greeting = greeting.read_text() if isinstance(greeting, Path) else greeting

prompt = get_system_prompt(
prompt = assemble_system_prompt(
self._data_source,
data_description=data_description,
extra_instructions=extra_instructions,
Expand Down Expand Up @@ -682,7 +682,7 @@ def as_querychat_client(client: str | chatlas.Chat | None) -> chatlas.Chat:
return chatlas.ChatAuto(provider_model=client)


def get_system_prompt(
def assemble_system_prompt(
data_source: DataSource,
*,
data_description: Optional[str | Path] = None,
Expand Down
20 changes: 3 additions & 17 deletions pkg-r/NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
# Generated by roxygen2: do not edit by hand

S3method(as_querychat_data_source,DBIConnection)
S3method(as_querychat_data_source,data.frame)
S3method(cleanup_source,dbi_source)
S3method(create_system_prompt,querychat_data_source)
S3method(execute_query,dbi_source)
S3method(get_db_type,data_frame_source)
S3method(get_db_type,dbi_source)
S3method(get_db_type,default)
S3method(get_schema,dbi_source)
S3method(test_query,dbi_source)
export(DBISource)
export(DataFrameSource)
export(DataSource)
export(QueryChat)
export(as_querychat_data_source)
export(cleanup_source)
export(create_system_prompt)
export(execute_query)
export(get_db_type)
export(get_schema)
export(querychat)
export(querychat_app)
export(querychat_data_source)
Expand All @@ -25,7 +12,6 @@ export(querychat_init)
export(querychat_server)
export(querychat_sidebar)
export(querychat_ui)
export(test_query)
importFrom(R6,R6Class)
importFrom(bslib,sidebar)
importFrom(lifecycle,deprecated)
Expand Down
27 changes: 22 additions & 5 deletions pkg-r/R/QueryChat.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ QueryChat <- R6::R6Class(
}
self$greeting <- greeting

prompt <- create_system_prompt(
prompt <- assemble_system_prompt(
private$.data_source,
data_description = data_description,
categorical_threshold = categorical_threshold,
Expand Down Expand Up @@ -522,7 +522,10 @@ QueryChat <- R6::R6Class(
#'
#' @return Invisibly returns `NULL`. Resources are cleaned up internally.
cleanup = function() {
cleanup_source(private$.data_source)
if (!is.null(private$.data_source)) {
private$.data_source$cleanup()
}
invisible(NULL)
}
),
active = list(
Expand Down Expand Up @@ -686,8 +689,22 @@ querychat_app <- function(

normalize_data_source <- function(data_source, table_name) {
if (is_data_source(data_source)) {
data_source
} else {
as_querychat_data_source(data_source, table_name)
return(data_source)
}

if (is.data.frame(data_source)) {
return(DataFrameSource$new(data_source, table_name))
}

if (inherits(data_source, "DBIConnection")) {
return(DBISource$new(data_source, table_name))
}

cli::cli_abort(
paste0(
"`data_source` must be a DataSource, data.frame, or DBIConnection. ",
"Got: ",
class(data_source)[1]
)
)
}
Loading