Skip to content

Feat/custom data files#47

Open
jlee-kitware wants to merge 6 commits into
feat/sample-datafrom
feat/custom-data-files
Open

Feat/custom data files#47
jlee-kitware wants to merge 6 commits into
feat/sample-datafrom
feat/custom-data-files

Conversation

@jlee-kitware

Copy link
Copy Markdown
Collaborator

Stacked on #46. Review that one first; the diff here is only the six commits on top.

#46 added a resolver that turns a bare filename in generated code (cow.g) into a real
local path by fetching it from the VTK data store. That only works for files VTK already
knows about. This adds the other half: your own files.

Upload a mesh, and the model is told it exists, writes reader.SetFileName('mymesh.vtu'),
and the resolver rewrites that literal to the local path at execution time. Same mechanism
as sample data, different source. Uploads take precedence over sample data of the same
name, and they work with no sample-data root configured, since they do not need one.

What is here

  • data/uploads.py: stores uploaded bytes under a sanitized basename in the local cache,
    with add/list/path/remove/clear. Content is coerced to bytes, since trame delivers it in
    a few different shapes.
  • Resolver integration: stage_code, referenced, and artifacts consult uploads first,
    then fall back to the sample-data index.
  • A conditional user_data prompt component lists the uploaded filenames and tells the
    model to load them by bare name with an appropriate reader. It is only added when files
    have been uploaded, so prompts are unchanged otherwise.
  • UI: an "Add data" chip in the Generated Code header, next to the resolved-file chips it
    relates to. Referenced-file chips now distinguish an uploaded file ("Uploaded") from
    fetched sample data ("Fetched").
  • A new Data settings tab collecting everything data-related: the sample-data location
    field (moved out of Config, which is now purely model/prompt config), uploaded files with
    remove actions, and the sample data fetched to the local cache with a Clear cache action.

Testing

Upload, reference-in-code, staging, and removal are all exercised; explicit paths are never
rewritten. Verified in the browser that the upload picker opens and an uploaded file stages
into the generated code correctly.

Complement the sample-data resolver with a store for the user's own files. New
data/uploads.py writes uploaded bytes to a local cache under a sanitized
basename and looks them up by name (add/list/path/remove/clear). The resolver's
stage_code, referenced, and artifacts now consult uploads first and fall back to
the sample-data index, so an uploaded file is used verbatim and takes precedence
over sample data of the same name. Staging also works with no sample-data root
configured, since uploads do not need one.
Add a conditional user_data prompt component that lists the user's uploaded
filenames and instructs the model to load them by bare name with an appropriate
reader. assemble_vtk_prompt gains an uploaded_files argument (mirroring the
mcp_active/context_snippets pattern); client.py passes the current uploads. The
component and its token cost are included only when files have been uploaded.
Add a file input above the prompt for uploading custom data files, plus a chip
strip of currently uploaded files each with a remove action. New change handler
stores uploaded bytes via the uploads registry and refreshes state; a trigger
removes a file by name. The referenced-data chips now distinguish an uploaded
file (info color, upload icon, "Uploaded") from fetched sample data. add_upload
coerces whatever content type trame delivers to bytes.
Put the upload affordance next to the resolved-file chips it relates to: a
small "Add data" chip in the Generated Code title triggers a hidden file input,
replacing the separate file field above the prompt. Behavior is unchanged; the
existing data_uploads change handler still stores the bytes.
Gather everything data-related in one place: a new Data tab holds the sample-data
location field (moved out of Config), the uploaded files with remove actions, and
the sample datasets fetched to the local cache with a Clear cache action. New
resolver helpers list and clear the cache; the lists refresh when the dialog
opens. Config is now purely model/prompt configuration.
trame evaluates click expressions as Vue template expressions, where window is
in scope but document is not, so bare document.querySelector was undefined. Go
through window.document to open the hidden file input.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant