|
| 1 | +# A simple RAG for VTK |
| 2 | + |
| 3 | +This project creates a database out of the existing Python examples of VTK and allows to ask questions related to VTK. |
| 4 | + |
| 5 | +## Set up |
| 6 | +1. By default it uses the OpenAI API. Make sure you get an API key and set |
| 7 | +your environmental variable appropriately. To use other an other model see |
| 8 | +[below](#supported-llm-models). |
| 9 | + |
| 10 | +2. Get the code of the vtk-examples. We will use this to generate our database. |
| 11 | + |
| 12 | +```bash |
| 13 | +git clone https://gitlab.kitware.com/vtk/vtk-examples |
| 14 | +``` |
| 15 | + |
| 16 | +3. Create a virtual environment and install the dependencies. |
| 17 | + |
| 18 | +```bash |
| 19 | +git clone https://gitlab.kitware.com/vtk/vtk-examples |
| 20 | +python -m venv env |
| 21 | +source env/bin/activate |
| 22 | +pip install -r requirements.txt |
| 23 | +``` |
| 24 | + |
| 25 | +4. Populate the database. This is required only once or if you want to experiment with a different embedding function. |
| 26 | +It will take some time depending on the hardware you are using. |
| 27 | + |
| 28 | +```bash |
| 29 | +python populate_db.py --dir ./vtk-examples/src/Python |
| 30 | +``` |
| 31 | + |
| 32 | +5. Now ask your question ! |
| 33 | + |
| 34 | +```bash |
| 35 | +$ python chat.py --database ./db/codesage-codesage-large-v2 |
| 36 | +User: How to read a vti file |
| 37 | + To read a VTK image data file (.vti), you can use the `vtkXMLImageDataReader` class. Here is a basic example: |
| 38 | + |
| 39 | +import vtk |
| 40 | + |
| 41 | +# Create a reader for your vti file |
| 42 | +reader = vtk.vtkXMLImageDataReader() |
| 43 | +reader.SetFileName('your_file.vti') |
| 44 | +reader.Update() |
| 45 | + |
| 46 | +# The output of reader.GetOutput() is your vtkImageData object |
| 47 | +image_data = reader.GetOutput() |
| 48 | + |
| 49 | +In this code, replace `'your_file.vti'` with the path to your .vti file. The |
| 50 | +`reader.Update()` call is necessary to actually perform the reading operation. |
| 51 | +After this, you can use `reader.GetOutput()` to get the `vtkImageData` object |
| 52 | +that was read from the file. |
| 53 | +
|
| 54 | +References: |
| 55 | +https://examples.vtk.org/site/Python/Medical/GenerateModelsFromLabels |
| 56 | +https://examples.vtk.org/site/Python/ImageData/WriteReadVtkImageData |
| 57 | +... |
| 58 | +``` |
| 59 | + |
| 60 | +### Supported LLM models |
| 61 | +`chat.py` uses by default "gpt-4" model to switch to a different one pass the name of the model via the `--model=<model name>` parameter. |
| 62 | +Currently supported models: |
| 63 | +- OpenAI models. See exact model names [here](https://platform.openai.com/docs/models#current-model-aliases). To use them you need an OpenAI API [key](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key). |
| 64 | +- Anthropic models. See exact names [here](https://docs.anthropic.com/en/docs/about-claude/models/all-models#model-names). To use them you need an Anthropic API [key](https://docs.anthropic.com/en/api/getting-started#accessing-the-api). |
| 65 | +- Models supported by the Ollama framework. To use these models make sure you have [ollama](https://github.com/ollama/ollama) installed and that it |
| 66 | + is running in another terminal (via `ollama serve`) and the you have already |
| 67 | + pulled the model you want to use (via `ollama pull <model-name>`). You can find available models [here](https://ollama.com/). |
0 commit comments