edgarodriguez commited on
Commit
dfc66e1
·
verified ·
1 Parent(s): f05b382

Upload 2 files

Browse files
Files changed (2) hide show
  1. Dockerfile +8 -4
  2. assistant.R +11 -6
Dockerfile CHANGED
@@ -27,13 +27,17 @@ ENV OLLAMA_MODELS=/app/.ollama \
27
  DEPTH_EMBED_MODEL=${EMBED_MODEL} \
28
  DEPTH_RAG_PARQUET=/app/rag_chunks.parquet
29
 
30
- # R packages. Adds ellmer (chat + tool calling), shinychat (streaming chat UI)
31
- # and arrow (read the embeddings Parquet) on top of the map's deps.
 
 
 
32
  RUN install2.r --error --skipinstalled --ncpus 4 \
33
  shiny bslib DBI duckdb dplyr jsonlite htmltools glue writexl ggplot2 stringr httr2 \
34
- ellmer shinychat arrow \
35
  && R -e "install.packages('mapgl', repos = c('https://walkerke.r-universe.dev', 'https://cloud.r-project.org'))" \
36
- && R -e "library(mapgl); library(duckdb); library(sf); library(shiny); library(httr2); library(ellmer); library(shinychat)"
 
37
 
38
  # Ollama runtime.
39
  RUN curl -fsSL https://ollama.com/install.sh | sh
 
27
  DEPTH_EMBED_MODEL=${EMBED_MODEL} \
28
  DEPTH_RAG_PARQUET=/app/rag_chunks.parquet
29
 
30
+ # R packages. The base image pins a dated CRAN snapshot whose ellmer/shinychat
31
+ # are too old -- that ellmer lacked the `params` argument, so the assistant failed
32
+ # with "unused argument (params = ...)". Install the stable map deps from the
33
+ # snapshot, but pull ellmer + shinychat from the latest CRAN so their chat/tool
34
+ # API matches the app code. The version banner lands in the build log.
35
  RUN install2.r --error --skipinstalled --ncpus 4 \
36
  shiny bslib DBI duckdb dplyr jsonlite htmltools glue writexl ggplot2 stringr httr2 \
37
+ arrow \
38
  && R -e "install.packages('mapgl', repos = c('https://walkerke.r-universe.dev', 'https://cloud.r-project.org'))" \
39
+ && R -e "install.packages(c('ellmer', 'shinychat'), repos = 'https://cloud.r-project.org')" \
40
+ && R -e "library(mapgl); library(duckdb); library(sf); library(shiny); library(httr2); library(ellmer); library(shinychat); cat('[build] ellmer', as.character(packageVersion('ellmer')), '| shinychat', as.character(packageVersion('shinychat')), '\n')"
41
 
42
  # Ollama runtime.
43
  RUN curl -fsSL https://ollama.com/install.sh | sh
assistant.R CHANGED
@@ -290,13 +290,18 @@ assistant_top_municipalities <- function(con, state, indicator, n = 5) {
290
  # NULL if construction fails (e.g. Ollama dropped). Tools close over `con` and
291
  # the live `state` snapshot env.
292
  make_assistant <- function(con, state, cfg = assistant_config()) {
 
 
 
 
 
 
 
 
 
 
293
  chat <- tryCatch(
294
- ellmer::chat_ollama(
295
- model = cfg$chat_model,
296
- base_url = cfg$host,
297
- system_prompt = assistant_system_prompt(assistant_indicator_catalog_txt()),
298
- params = ellmer::params(temperature = 0.2)
299
- ),
300
  error = function(e) { message("[assist] chat_ollama: ", conditionMessage(e)); NULL }
301
  )
302
  if (is.null(chat)) return(NULL)
 
290
  # NULL if construction fails (e.g. Ollama dropped). Tools close over `con` and
291
  # the live `state` snapshot env.
292
  make_assistant <- function(con, state, cfg = assistant_config()) {
293
+ chat_args <- list(
294
+ model = cfg$chat_model,
295
+ base_url = cfg$host,
296
+ system_prompt = assistant_system_prompt(assistant_indicator_catalog_txt())
297
+ )
298
+ # `params` was added in newer ellmer; older versions error with
299
+ # "unused argument (params = ...)". Only pass it when supported.
300
+ if ("params" %in% names(formals(ellmer::chat_ollama))) {
301
+ chat_args$params <- ellmer::params(temperature = 0.2)
302
+ }
303
  chat <- tryCatch(
304
+ do.call(ellmer::chat_ollama, chat_args),
 
 
 
 
 
305
  error = function(e) { message("[assist] chat_ollama: ", conditionMessage(e)); NULL }
306
  )
307
  if (is.null(chat)) return(NULL)