https://github.com/cfn-softbio/vision

Virtual Scientific Companion for Synchrotron Beamlines

https://github.com/cfn-softbio/vision

Science Score: 49.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 4 DOI reference(s) in README
  • Academic publication links
    Links to: arxiv.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.8%) to scientific vocabulary
Last synced: 6 months ago · JSON representation

Repository

Virtual Scientific Companion for Synchrotron Beamlines

Basic Info
  • Host: GitHub
  • Owner: CFN-softbio
  • Language: Python
  • Default Branch: main
  • Size: 4.4 MB
Statistics
  • Stars: 3
  • Watchers: 6
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created about 1 year ago · Last pushed 9 months ago
Metadata Files
Readme

README.md

VISION: A Modular AI Assistant for Natural Human-Instrument Interaction at Scientific User Facilities

VISION (Virtual Scientific Companion) is an AI-driven assistant designed to streamline operations at synchrotron beamlines and scientific facilities through natural language interaction. Built on a modular architecture, VISION is an assembly of Cognitive Blocks (Cogs)—specialized AI components tailored for tasks like transcription, classification, code generation, data analysis, and scientific querying. These cogs operate in predefined workflows, enabling seamless communication between users and complex instrumentation.

Key workflows include natural language-controlled (audio, text, or both) beamline operations, where commands are classified, converted to executable code, and deployed for data acquisition or analysis; custom function addition, where custom functions defined by the user in natural language are dynamically integrated into the system; and a domain-specific chatbot, capable of answering scientific queries with precision.

Overview of the VISION architecture

Figure 1: Overview of the VISION architecture

NSLS-II GUI Deployment

Figure 2: VISION deployment at NSLS-II 11-BM CMS: GUI was launched at the beamline workstation, with backend processing performed on HAL. LLM-based cog results are displayed to prompt user confirmation, followed by execution on Bluesky or other software.

Paper

Please see our paper here - https://arxiv.org/abs/2412.18161

Directory Structure

Highlight of the most important files: 📁 VISION/ ├── 📁 backend/ │ ├── 📁 src/ │ │ └── 📁 hal_beam_com/ │ │ └── cog_manager.py (main entry-point for backend) │ └── 📁 tests/ (contains testing framework to generate evaluate LLMs on our datasets) └── 📁 frontend/ └── 📁 UI/ └── 📁 program/ └── executable.py (main entry-point for front-end)

Getting Started Guide

This guide includes I. Installation, II. Running the System, III. Configuration, and IV. Adding Functionality.

I. Installation

Python Requirements

Both frontend and backend require Python 3.12.7. Different versions might work but are mostly untested.

Frontend Installation

  1. Navigate to the frontend directory: bash cd frontend

  2. Create a virtual environment: bash python -m venv .venv

  3. Activate the virtual environment:

    • Windows: bash .\.venv\Scripts\Activate.ps1 # or .\.venv\Scripts\activate.bat
    • Linux/MacOS: bash source .venv/bin/activate
  4. Install required packages: bash pip install -r requirements.txt

  5. For beamline key insertion functionality (Linux only): bash sudo apt-get install xdotool

Backend Installation

  1. Navigate to the backend directory: bash cd backend

  2. Create a virtual environment: bash python -m venv .venv

  3. Activate the virtual environment:

    • Windows: bash .\.venv\Scripts\Activate.ps1 # or .\.venv\Scripts\activate.bat
    • Linux/MacOS: bash source .venv/bin/activate
  4. Install required packages: bash pip install -r requirements.txt

  5. Set up the Anthropic API Key:

    • Windows: cmd setx ANTHROPIC_API_KEY "your_secret_key_value" Restart your IDE for changes to take effect.
  • Linux/MacOS: bash echo 'export ANTHROPIC_API_KEY="your_secret_key_value"' >> ~/.bashrc source ~/.bashrc # or ~/.zshrc for zsh users
  1. Alternative Model Configuration: In this public repository, Claude's models are used by default. This is so one does not need a GPU to run large open-source models locally. If you prefer not to use Claude's Anthropic model, you can switch the model setup by changing the ACTIVE_CONFIG in ./backend/src/hal_beam_com/utils.py. Though, most models (except GPT-4o) will require having Ollama installed.

II. Running the System

Starting the Frontend

After installation, run the frontend with: bash cd frontend python ./UI/program/executable.py

Starting the Backend

After installation, run the backend with: bash cd backend python ./src/hal_beam_com/cog_manager.py

III. Configuration Options

Connection Between Frontend and Backend

VISION supports three methods for the communication between frontend and backend:

  1. Local Filesystem (Default)

    • The simplest option for local testing and development
    • This is the default setting in this public repository. No additional configuration required
    • Data is transferred through files in a shared filesystem
    • If the commands become desynced, you can clear the temp folder to resolve it
  2. SSH Connection

    • For connecting to a remote backend server
    • Requires SSH access to the backend machine
    • All communication goes through the server, credentials should be that of the server in both files
    • To enable, replace CustomS3.py with SSH<Backend|Frontend>CustomS3.py in both frontend and backend
    • Configure in both frontend and backend CustomS3.py files: python username = "your_username" endpoint = "backend_server_address" password = "your_password" # Or use SSH keys instead
  3. Minio S3

    • For scalable, production deployments
    • Requires a Minio S3 server
    • To enable, replace CustomS3.py with MinioCustomS3.py in both frontend and backend
    • Configure connection details in the MinioCustomS3.py files

Connection Between Frontend and Instruments

Currently, VISION uses keyboard injection for simple deployment; proper integration to the instrument control framework is recommended (work in progress).

  1. Keyboard Injection (xdotool)
    • Simulates keyboard inputs to control existing instrument interfaces
    • Requires xdotool on Linux (installed with sudo apt-get install xdotool)
    • Used by default in the executeCommand method in frontend/UI/program/executable.py

However, integration to the instrument control framework should be utilized, for example,

  1. Direct API Integration
    • For instruments with programmable interfaces
    • Configure custom command handlers in the backend
    • Requires specific knowledge of the instrument's API

IV. Adding/Extending Functionality

Adding Instrument/Command Support

To add support for new instruments or add new functions to the current instrument, you just need to create/modify JSON entries (in /backend/src/hal_beam_com/beamline_prompts /11BM/command_examples.json) that define their respective commands. For each instrument, a corresponding folder and json is needed, e.g. /11BM/command_examples.json, /12ID/command_examples.json.

  1. Define a new function in JSON format: json { "class": "Sample Measurement Commands", "title": "Snap (Measure Sample without Saving)", "function": "sam.snap(exposure_time)", "params": [ { "name": "exposure_time", "type": "int", "description": "seconds" } ], "notes": [ "This command measures the sample but does not save the data." ], "usage": [ { "input": "Measure sample for 5 seconds but don't save the data.", "code": "sam.snap(5)" } ], "example_inputs": [ "Measure sample 2 seconds, no save." ], "default": true, "cog": "Op" }

Only the title and function fields are required. If default is False, the functions will be put under "Miscellaneous Commands". However, using the fields offered allows for more specificity, which in turn can yield higher performance. The above JSON entry is formatted as the following in the prompt: `` - **Sample Measurement Commands:** - **Snap (Measure Sample without Saving):** sam.snap(exposure_time)`

    - Params:
        - exposure_time: int (seconds)

    - Notes:
        - This command measures the sample but does not save the data.

    - Usage:
        - "Measure sample for 5 seconds but don't save the data."
            - `sam.snap(5)`

    - Example phrases:
        - "Measure sample 2 seconds, no save."

```

  1. Using the dynamic function creation workflow:
    • You can also add functions through the natural language UI. This is for quick-adding functionality during online operation. Note that for deploying VISION to a new instrument, it is recommended to create/modify command_examples.json instead of using the UI.
    • Describe the function and its parameters in natural language, and then the system will generate the appropriate JSON and code implementations.
    • Cons: sophisticated format not supported, and requires access to a specific model (GPT-4o, used for JSON support)

Contact

Feel free to reach out to us for any questions or installation issues. Suggestions/feedback are also appreciated! Esther Tsai (etsai@bnl.gov)

Citation

bibtex @article{Mathur_2025, doi = {10.1088/2632-2153/add9e4}, url = {https://dx.doi.org/10.1088/2632-2153/add9e4}, year = {2025}, month = {jun}, publisher = {IOP Publishing}, volume = {6}, number = {2}, pages = {025051}, author = {Mathur, Shray and der Vleuten, Noah van and Yager, Kevin G and Tsai, Esther H R}, title = {VISION: a modular AI assistant for natural human-instrument interaction at scientific user facilities}, journal = {Machine Learning: Science and Technology}, }

Owner

  • Name: CFN-softbio
  • Login: CFN-softbio
  • Kind: organization

GitHub Events

Total
  • Watch event: 3
  • Member event: 3
  • Push event: 19
  • Create event: 1
Last Year
  • Watch event: 3
  • Member event: 3
  • Push event: 19
  • Create event: 1

Dependencies

frontend/requirements.txt pypi
backend/requirements.txt pypi
  • Deprecated ==1.2.15
  • Jinja2 ==3.1.5
  • Levenshtein ==0.26.1
  • MarkupSafe ==3.0.2
  • PyMuPDF ==1.25.1
  • PyYAML ==6.0.2
  • Pygments ==2.18.0
  • Pympler ==1.1
  • RapidFuzz ==3.11.0
  • SQLAlchemy ==2.0.36
  • accelerate ==1.2.1
  • aiohappyeyeballs ==2.4.4
  • aiohttp ==3.11.11
  • aiosignal ==1.3.2
  • annotated-types ==0.7.0
  • anthropic ==0.42.0
  • anyio ==4.7.0
  • argon2-cffi ==23.1.0
  • argon2-cffi-bindings ==21.2.0
  • async-timeout ==5.0.1
  • attrs ==24.3.0
  • certifi ==2024.12.14
  • cffi ==1.17.1
  • charset-normalizer ==3.4.1
  • click ==8.1.8
  • codebleu ==0.7.0
  • colorama ==0.4.6
  • colorlog ==6.9.0
  • coredis ==4.18.0
  • dataclasses-json ==0.6.7
  • datasets ==3.2.0
  • dill ==0.3.8
  • distro ==1.9.0
  • docstring_parser ==0.16
  • evaluate ==0.4.3
  • fhaviary ==0.14.0
  • filelock ==3.16.1
  • frozenlist ==1.5.0
  • fsspec ==2024.9.0
  • greenlet ==3.1.1
  • h11 ==0.14.0
  • html2text ==2024.2.26
  • httpcore ==1.0.7
  • httpx ==0.27.2
  • httpx-sse ==0.4.0
  • huggingface-hub ==0.27.0
  • idna ==3.10
  • importlib_metadata ==8.5.0
  • jiter ==0.8.2
  • joblib ==1.4.2
  • jsonpatch ==1.33
  • jsonpointer ==3.0.0
  • jsonschema ==4.23.0
  • jsonschema-specifications ==2024.10.1
  • langchain ==0.3.13
  • langchain-community ==0.3.13
  • langchain-core ==0.3.28
  • langchain-huggingface ==0.1.2
  • langchain-openai ==0.2.14
  • langchain-text-splitters ==0.3.4
  • langsmith ==0.2.7
  • latexcodec ==3.0.0
  • limits ==3.14.1
  • litellm ==1.56.6
  • markdown-it-py ==3.0.0
  • marshmallow ==3.23.2
  • mdurl ==0.1.2
  • minio ==7.2.13
  • mpmath ==1.3.0
  • multidict ==6.1.0
  • multiprocess ==0.70.16
  • mypy-extensions ==1.0.0
  • networkx ==3.4.2
  • numpy ==1.26.4
  • openai ==1.58.1
  • orjson ==3.10.13
  • packaging ==24.2
  • pandas ==2.2.3
  • paper-qa ==5.8.0
  • peft ==0.14.0
  • pillow ==11.1.0
  • propcache ==0.2.1
  • psutil ==6.1.1
  • pyarrow ==18.1.0
  • pybtex ==0.24.0
  • pycparser ==2.22
  • pycryptodome ==3.21.0
  • pydantic ==2.10.4
  • pydantic-settings ==2.7.1
  • pydantic_core ==2.27.2
  • python-dateutil ==2.9.0.post0
  • python-dotenv ==1.0.1
  • pytz ==2024.2
  • pyzmq ==26.2.0
  • referencing ==0.35.1
  • regex ==2024.11.6
  • requests ==2.32.3
  • requests-mock ==1.12.1
  • requests-toolbelt ==1.0.0
  • rich ==13.9.4
  • rpds-py ==0.22.3
  • safetensors ==0.4.5
  • scikit-learn ==1.6.0
  • scipy ==1.14.1
  • semantic-router ==0.0.72
  • sentence-transformers ==3.3.1
  • setuptools ==75.6.0
  • six ==1.17.0
  • sniffio ==1.3.1
  • sympy ==1.13.1
  • tantivy ==0.22.0
  • tenacity ==9.0.0
  • threadpoolctl ==3.5.0
  • tiktoken ==0.8.0
  • tokenizers ==0.21.0
  • torch ==2.5.1
  • tqdm ==4.67.1
  • transformers ==4.47.1
  • tree-sitter ==0.22.3
  • tree-sitter-python ==0.21.0
  • typing-inspect ==0.9.0
  • typing_extensions ==4.12.2
  • tzdata ==2024.2
  • urllib3 ==2.3.0
  • wrapt ==1.17.0
  • xxhash ==3.5.0
  • yarl ==1.18.3
  • zipp ==3.21.0
frontend/UI/program/environment.yml conda
  • _libgcc_mutex 0.1
  • _openmp_mutex 4.5
  • alsa-lib 1.2.12
  • anaconda-client 1.12.3
  • asttokens 2.4.1
  • attr 2.5.1
  • attrs 23.2.0
  • backcall 0.2.0
  • bottleneck 1.4.0
  • brotli 1.1.0
  • brotli-bin 1.1.0
  • brotli-python 1.1.0
  • bzip2 1.0.8
  • ca-certificates 2024.7.4
  • cairo 1.18.0
  • certifi 2024.7.4
  • cffi 1.16.0
  • charset-normalizer 3.3.2
  • colorama 0.4.6
  • conda-package-handling 2.3.0
  • conda-package-streaming 0.10.0
  • contourpy 1.2.1
  • cycler 0.12.1
  • dbus 1.13.6
  • decorator 5.1.1
  • defusedxml 0.7.1
  • exceptiongroup 1.2.2
  • executing 2.0.1
  • expat 2.6.2
  • font-ttf-dejavu-sans-mono 2.37
  • font-ttf-inconsolata 3.000
  • font-ttf-source-code-pro 2.038
  • font-ttf-ubuntu 0.83
  • fontconfig 2.14.2
  • fonts-conda-ecosystem 1
  • fonts-conda-forge 1
  • fonttools 4.53.1
  • freetype 2.12.1
  • gettext 0.22.5
  • gettext-tools 0.22.5
  • glib 2.80.3
  • glib-tools 2.80.3
  • graphite2 1.3.13
  • gst-plugins-base 1.24.5
  • gstreamer 1.24.5
  • h2 4.1.0
  • harfbuzz 9.0.0
  • hpack 4.0.0
  • hyperframe 6.0.1
  • icu 73.2
  • idna 3.7
  • importlib-resources 6.4.0
  • importlib_resources 6.4.0
  • ipython 8.15.0
  • jedi 0.19.1
  • jsonschema 4.23.0
  • jsonschema-specifications 2023.12.1
  • jupyter_core 5.7.2
  • keyutils 1.6.1
  • kiwisolver 1.4.5
  • krb5 1.21.3
  • lame 3.100
  • lcms2 2.16
  • ld_impl_linux-64 2.40
  • lerc 4.0.0
  • libasprintf 0.22.5
  • libasprintf-devel 0.22.5
  • libblas 3.9.0
  • libbrotlicommon 1.1.0
  • libbrotlidec 1.1.0
  • libbrotlienc 1.1.0
  • libcap 2.69
  • libcblas 3.9.0
  • libclang-cpp15 15.0.7
  • libclang13 18.1.8
  • libcups 2.3.3
  • libdeflate 1.20
  • libedit 3.1.20191231
  • libevent 2.1.12
  • libexpat 2.6.2
  • libffi 3.4.2
  • libflac 1.4.3
  • libgcc-ng 14.1.0
  • libgcrypt 1.11.0
  • libgettextpo 0.22.5
  • libgettextpo-devel 0.22.5
  • libgfortran-ng 14.1.0
  • libgfortran5 14.1.0
  • libglib 2.80.3
  • libgomp 14.1.0
  • libgpg-error 1.50
  • libiconv 1.17
  • libjpeg-turbo 3.0.0
  • liblapack 3.9.0
  • libllvm15 15.0.7
  • libllvm18 18.1.8
  • libnsl 2.0.1
  • libogg 1.3.5
  • libopenblas 0.3.27
  • libopus 1.3.1
  • libpng 1.6.43
  • libpq 16.3
  • libsndfile 1.2.2
  • libsqlite 3.46.0
  • libstdcxx-ng 14.1.0
  • libsystemd0 255
  • libtiff 4.6.0
  • libuuid 2.38.1
  • libvorbis 1.3.7
  • libwebp-base 1.4.0
  • libxcb 1.16
  • libxcrypt 4.4.36
  • libxkbcommon 1.7.0
  • libxml2 2.12.7
  • libzlib 1.3.1
  • lz4-c 1.9.4
  • matplotlib 3.9.1
  • matplotlib-base 3.9.1
  • matplotlib-inline 0.1.7
  • mpg123 1.32.6
  • munkres 1.1.4
  • mysql-common 8.3.0
  • mysql-libs 8.3.0
  • nbformat 5.10.4
  • ncurses 6.5
  • nomkl 1.0
  • nspr 4.35
  • nss 3.102
  • numexpr 2.10.0
  • numpy 1.26.4
  • openjpeg 2.5.2
  • openssl 3.3.1
  • packaging 24.1
  • pandas 2.1.1
  • parso 0.8.4
  • pcre2 10.44
  • pexpect 4.9.0
  • pickleshare 0.7.5
  • pillow 10.4.0
  • pip 24.0
  • pixman 0.43.2
  • pkgutil-resolve-name 1.3.10
  • platformdirs 4.2.2
  • ply 3.11
  • portaudio 19.6.0
  • prompt-toolkit 3.0.47
  • pthread-stubs 0.4
  • ptyprocess 0.7.0
  • pulseaudio-client 17.0
  • pure_eval 0.2.3
  • pycparser 2.22
  • pygments 2.18.0
  • pyparsing 3.1.2
  • pyqt 5.15.10
  • pyqt5-sip 12.13.0
  • pysocks 1.7.1
  • python 3.9.19
  • python-dateutil 2.9.0
  • python-fastjsonschema 2.20.0
  • python-sounddevice 0.4.7
  • python-tzdata 2024.1
  • python_abi 3.9
  • pytz 2024.1
  • pyyaml 6.0.1
  • qhull 2020.2
  • qt-main 5.15.8
  • readline 8.2
  • referencing 0.35.1
  • requests 2.32.3
  • requests-toolbelt 1.0.0
  • rpds-py 0.19.1
  • setuptools 71.0.4
  • sip 6.7.12
  • six 1.16.0
  • stack_data 0.6.2
  • tk 8.6.13
  • tomli 2.0.1
  • tornado 6.4.1
  • tqdm 4.66.4
  • traitlets 5.14.3
  • typing_extensions 4.12.2
  • tzdata 2024a
  • unicodedata2 15.1.0
  • urllib3 2.2.2
  • wcwidth 0.2.13
  • wheel 0.43.0
  • xcb-util 0.4.1
  • xcb-util-image 0.4.0
  • xcb-util-keysyms 0.4.1
  • xcb-util-renderutil 0.3.10
  • xcb-util-wm 0.4.2
  • xkeyboard-config 2.42
  • xorg-kbproto 1.0.7
  • xorg-libice 1.1.1
  • xorg-libsm 1.2.4
  • xorg-libx11 1.8.9
  • xorg-libxau 1.0.11
  • xorg-libxdmcp 1.1.3
  • xorg-libxext 1.3.4
  • xorg-libxrender 0.9.11
  • xorg-renderproto 0.11.1
  • xorg-xextproto 7.3.0
  • xorg-xf86vidmodeproto 2.3.1
  • xorg-xproto 7.0.31
  • xz 5.2.6
  • yaml 0.2.5
  • zipp 3.19.2
  • zlib 1.3.1
  • zstandard 0.23.0
  • zstd 1.5.6