Skip to content

Commit

Permalink
added / tested installation instructions, reran almost all notebooks,…
Browse files Browse the repository at this point in the history
… restructured TOC a bit
  • Loading branch information
haesleinhuepf committed Jul 18, 2024
1 parent 447277f commit 73e64e3
Show file tree
Hide file tree
Showing 57 changed files with 1,735 additions and 3,470 deletions.
Binary file added docs/00_setup/install_mini-conda.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/00_setup/install_mini-conda2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions docs/00_setup/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Setting up your computer

This chapter provides instructions for setting up your computer.

## Computer hardware

To execute the notebooks in this collection, it is highly recommended to use a computer with a CUDA compatible NVidia Graphics card with at least 4GB of memory.

## Setting up Python and Conda environments

When working with Python, we will make use of many plugins and software libraries which need to be organized.
One way of doing this, is by managing *Conda* environments.
A conda environment can be seen as a virtual desktop, or virtual computer, accessible via the terminal.
If you install some software into one Conda environment, it may not be accessible from another environment.
If a Conda environment breaks, e.g. incompatible software was installed, you can just make a new one and start over.

See also
* [Managing Scientific Python environments using Conda, Mamba and friends](https://focalplane.biologists.com/2022/12/08/managing-scientific-python-environments-using-conda-mamba-and-friends/)
* [Scientific Data Analysis with Python](https://youtu.be/MOEPe9TGBK0)
* [Getting started with Mambaforge and Python](https://biapol.github.io/blog/mara_lampert/getting_started_with_mambaforge_and_python/readme.html)

## Install Mini-conda
Download and install mamba/conda. We recommend the distribution [mini-conda](https://docs.anaconda.com/miniconda/). If you already have an old Anaconda installation you haven't touched for a while, it is highly recommended to uninstall it and install mini-conda instead.

For ease-of-use, it is recommended to install it for your use only and to add Conda to the PATH variable during installation.

![img.png](install_mini-conda.png)

![img.png](install_mini-conda2.png)

## Setting up a conda environment

You can create a conda environment using this command from the terminal:

```
conda create --name genai2 python=3.11 jupyterlab pytorch torchvision torchaudio pytorch-cuda=11.8 cudatoolkit=11.8 huggingface_hub diffusers transformers accelerate anthropic openai langchain stackview voila pandas torchmetrics scikit-learn seaborn -c pytorch -c nvidia -c conda-forge
```

Activate the environment:
```
conda activate genai2
```

Install some additional packaged via pip:
```
pip install python-pptx bia-bob blablado llama-index
```

## Installing ollama

To make use of the ollama-based models, please install [ollama](https://ollama.com/download). The notebooks in this folder were tested with ollama version 0.1.39

Furthermore, consider downloading these models:

[llava 1.6](https://ollama.com/library/llava), [mistral:v0.3](https://ollama.com/library/mistral:v0.3) and
[gemma](https://ollama.com/library/gemma)
```
ollama run llava
ollama run mistral:v0.3
ollama run gemma
```

Note: You can print out which models you have downloaded like this:
```
ollama list
```

## Setting up API keys

If you plan to use the commercial language models, you need to register at their websites and acquire so called API keys. You do not need to get these keys for all exercises, but for some they might be useful.
* [OpenAI (gpt)](https://openai.com/blog/openai-api)
* [Anthropic (claude)](https://www.anthropic.com/api)

If you are German academic, you may also be eligible to acquire a free API key from Helmholtz.AI for the blablador infrastructure:
* (blablador[https://sdlaml.pages.jsc.fz-juelich.de/ai/guides/blablador_api_access/]

You can then save these keys in the environment variables of your computer as explained [on this page](https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety).


69 changes: 23 additions & 46 deletions docs/10_prompting_basics/01_prompting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"id": "9ee67a8d-c234-4427-91c9-a0dc7033657e",
"metadata": {},
"source": [
"# Prompting chatGPT\n",
"In this notebook we will send basic prompts to chatGPT and receive answers. We will write a small `prompt` helper function that makes it more accessible."
"# Prompting basics\n",
"In this notebook we will send basic prompts to large language model (LLM) and receive answers. To skip technical implementation details for this first step, we just import a `prompt_...` function for now that allows us to access an LLM."
]
},
{
Expand All @@ -16,61 +16,36 @@
"metadata": {},
"outputs": [],
"source": [
"from openai import OpenAI\n",
"\n",
"from IPython.core.magic import register_line_cell_magic\n",
"from IPython.display import display, Markdown"
"from prompting_utilities import prompt_chatgpt"
]
},
{
"cell_type": "markdown",
"id": "33f1bf93-26e8-4d10-bd57-6ade5afdcd7f",
"id": "2ec5dae8-adb0-449e-a370-a216d10f4690",
"metadata": {},
"source": [
"A basic prompt requires to define the model we will be using as well as the role we have and the content/message we would like to be responded to. To make it more convenient we write a little helper function that allows us to retrieve the response to a message directly."
"We can then send English prompts to the LLM by writing `%%prompt_chatgpt` at the beginning of each cell."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "f9406734-ba7a-4deb-8bb1-90b33c460d87",
"metadata": {},
"outputs": [],
"source": [
"@register_line_cell_magic\n",
"def prompt(line:str, cell:str, model=\"gpt-3.5-turbo\"):\n",
" \"\"\"A prompt helper function that sends a message to openAI\n",
" and prints out the text response.\n",
" \"\"\"\n",
" message = line + \"\\n\" + cell\n",
" client = OpenAI()\n",
" response = client.chat.completions.create(\n",
" model=model,\n",
" messages=[{\"role\": \"user\", \"content\": message}]\n",
" )\n",
" text = response.choices[0].message.content\n",
" display(Markdown(text))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "43c6f1dc-fb3c-463f-a144-90b017031600",
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"The countries in Central Europe are:\n",
"Central Europe is often considered to include the following countries:\n",
"\n",
"1. Austria\n",
"2. Czech Republic\n",
"3. Germany (some parts are considered part of Central Europe)\n",
"4. Hungary\n",
"1. Germany\n",
"2. Austria\n",
"3. Czech Republic\n",
"4. Slovakia\n",
"5. Poland\n",
"6. Slovakia\n",
"7. Slovenia (sometimes considered part of Central Europe)\n",
"8. Switzerland (some parts are considered part of Central Europe)"
"6. Hungary\n",
"7. Slovenia\n",
"8. Switzerland (sometimes included)"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
Expand All @@ -81,20 +56,20 @@
}
],
"source": [
"%%prompt\n",
"%%prompt_chatgpt\n",
"Which countries are in central Europe?"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"id": "ed9c0e13-2f2b-421b-8230-425507372969",
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"Switzerland is located in central Europe, so there are no parts of Switzerland that are not part of central Europe."
"Switzerland is located in central Europe, so it does not have any parts that are not considered part of central Europe."
],
"text/plain": [
"<IPython.core.display.Markdown object>"
Expand All @@ -105,7 +80,7 @@
}
],
"source": [
"%%prompt\n",
"%%prompt_chatgpt\n",
"Which parts of Switzerland are not central Europe?"
]
},
Expand All @@ -120,14 +95,16 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"id": "8269c2a0-0a68-452d-9c20-1cabdaf66e1d",
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"The parts of Switzerland that are not considered central Europe are its overseas territories or colonies, as Switzerland does not have any. However, geographically speaking, Switzerland entirely lies within Central Europe."
"The parts of Switzerland that are not considered part of central Europe are: \n",
"- The Jura region in the western part of Switzerland is considered part of western Europe \n",
"- The Ticino region in the southern part of Switzerland is considered part of southern Europe."
],
"text/plain": [
"<IPython.core.display.Markdown object>"
Expand All @@ -138,7 +115,7 @@
}
],
"source": [
"%%prompt\n",
"%%prompt_chatgpt\n",
"Which parts of Switzerland are not central Europe?"
]
},
Expand Down Expand Up @@ -167,7 +144,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 73e64e3

Please sign in to comment.