Skip to content

Commit

Permalink
Update lab 1 and 2 to granite 3.1
Browse files Browse the repository at this point in the history
Signed-off-by: BJ Hargrave <[email protected]>
  • Loading branch information
bjhargrave committed Jan 10, 2025
1 parent 43d9ad9 commit 2685a1b
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 177 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Run `pre-commit install` to activate pre-commit hooks
repos:
- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
rev: 0.8.1
hooks:
- id: nbstripout
args: [
Expand Down
2 changes: 1 addition & 1 deletion docs/lab-1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ logo: images/ibm-blue-background.png

[Text summarization](https://www.ibm.com/topics/text-summarization) condenses one or more texts into shorter summaries for enhanced information extraction.

The goal of this lab is to show how you can use [IBM Granite Code](https://www.ibm.com/granite/docs/models/code/) models in order to apply long document summarization techniques to a work of literature.
The goal of this lab is to show how you can use [IBM Granite](https://www.ibm.com/granite/docs/models/granite/) models in order to apply long document summarization techniques to a work of literature.

## Prerequisites

Expand Down
4 changes: 2 additions & 2 deletions docs/pre-work/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ Running Ollama locally on your computer requires the following steps:
1. In another terminal window, pull down the Granite models you will want to use in the workshop. Larger models take more memory to run but can give better results.
```shell
ollama pull granite3-dense:2b
ollama pull granite3-dense:8b
ollama pull granite3.1-dense:2b
ollama pull granite3.1-dense:8b
```
For [Lab 4: Generating Bash Code with Granite Code](../lab-4/README.md), you will also need at least one of the following Granite Code models.
Expand Down
18 changes: 12 additions & 6 deletions notebooks/RAG_with_Langchain.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"metadata": {},
"outputs": [],
"source": [
"! pip install \"git+https://github.com/ibm-granite-community/utils.git\" \"langchain_community<0.3.0\" \"langchain-huggingface\" \"langchain_ollama\" \"langchain-milvus\" \"replicate\" \"wget\""
"! pip install \"git+https://github.com/ibm-granite-community/utils.git\" langchain_community langchain_huggingface langchain_ollama langchain-milvus replicate wget"
]
},
{
Expand Down Expand Up @@ -133,7 +133,7 @@
"outputs": [],
"source": [
"from langchain_huggingface import HuggingFaceEmbeddings\n",
"embeddings_model = HuggingFaceEmbeddings(model_name=\"all-MiniLM-L6-v2\")"
"embeddings_model = HuggingFaceEmbeddings(model_name=\"ibm-granite/granite-embedding-30m-english\")"
]
},
{
Expand Down Expand Up @@ -193,10 +193,14 @@
"\n",
"try: # Look for a locally accessible Ollama server for the model\n",
" response = requests.get(os.getenv(\"OLLAMA_HOST\", \"http://127.0.0.1:11434\"))\n",
" model = OllamaLLM(model=\"granite3-dense:8b\")\n",
" model = OllamaLLM(\n",
" model=\"granite3.1-dense:8b\",\n",
" )\n",
"except Exception: # Use Replicate for the model\n",
" model = Replicate(model=\"ibm-granite/granite-3.0-8b-instruct\",\n",
" replicate_api_token=get_env_var(\"REPLICATE_API_TOKEN\"))\n"
" model = Replicate(\n",
" model=\"ibm-granite/granite-3.1-8b-instruct\",\n",
" replicate_api_token=get_env_var(\"REPLICATE_API_TOKEN\")\n",
" )\n"
]
},
{
Expand Down Expand Up @@ -328,7 +332,9 @@
"source": [
"query = \"What did the president say about Ketanji Brown Jackson\"\n",
"docs = vector_db.similarity_search(query)\n",
"print(docs[0].page_content)"
"print(f\"{len(docs)} documents returned\")\n",
"for i, d in enumerate(docs):\n",
" print(f\"Document {i+1}\\n{d.page_content}\\n\")"
]
},
{
Expand Down
Loading

0 comments on commit 2685a1b

Please sign in to comment.