Skip to content

Commit 8069d9b

Browse files
authored
Merge pull request #29 from IBM/jjasghar/mellea
updated with mellea and removed continue.dev
2 parents ff9654a + 3b93a57 commit 8069d9b

File tree

4 files changed

+364
-331
lines changed

4 files changed

+364
-331
lines changed

docs/lab-5/README.md

Lines changed: 82 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,117 @@
11
---
2-
title: Building a Local AI Assistant
3-
description: Build a Granite coding assistant
2+
title: Using AnythingLLM for a local RAG
3+
description: Learn how to build a simple local RAG
44
logo: images/ibm-blue-background.png
55
---
66

7-
Do you use LLMs in an enterprise-setting? There are usually three main barriers to adopting its use in an enterprise setting:
7+
## Configuration and Sanity Check
88

9-
- **Data Privacy:** Corporate privacy regulations that prohibit sending internal code or data to third party services.
10-
- **Generated Material Licensing:** Many models, even those with permissive usage licenses, don't disclose their training data and may produce output that is derived from material with licensing restrictions.
11-
- **Cost:** Many tools are paid solutions that require investment. For larger organizations, this would often include paid support and maintenance contracts which can be extremely costly and slow to
9+
Open up AnyThingLLM, and you should see something like the following:
10+
![default screen](../images/anythingllm_open_screen.png)
1211

13-
In this lab, we'll use a collection of open-source components to run a feature-rich developer code assistant in Visual Studio Code. Previously, we used `granite3.1-dense`, for general use cases like summarization, question-answering, and classification. Now, we'll try IBM's [Granite Code](https://github.com/ibm-granite/granite-code-models), which are geared towards code generation tasks.
12+
If you see this that means AnythingLLM is installed correctly, and we can continue configuration, if not, please find a workshop TA or
13+
raise your hand we'll be there to help you ASAP.
1414

15-
This lab is a rendition of this [blogpost](https://developer.ibm.com/tutorials/awb-local-ai-copilot-ibm-granite-code-ollama-continue/).
15+
Next as a sanity check, run the following command to confirm you have the [granite3.1-dense](https://ollama.com/library/granite3.1-dense)
16+
model downloaded in `ollama`. This may take a bit, but we should have a way to copy it directly on your laptop.
1617

17-
!!! note
18-
The following labs assume some programming experience/knowledge. If you don't have any, don't fret! Raise your hand and ask a TA for help! They'll be more than happy to.
18+
```bash
19+
ollama pull granite3.1-dense:8b
20+
```
1921

20-
## Download the Model
22+
If you didn't know, the supported languages with `granite3.1-dense` now include:
2123

22-
[Granite Code](https://github.com/ibm-granite/granite-code-models) was produced by IBM Research, with the goal of building an LLM that has only seen code which used enterprise-friendly licenses. According to section 2 of the , the IBM Granite Code models meticulously curated their training data for licenses, and to make sure that all text did not contain any hate, abuse, or profanity. You can read more about how they were built in its [paper](https://arxiv.org/pdf/2405.04324).
24+
- English, German, Spanish, French, Japanese, Portuguese, Arabic, Czech, Italian, Korean, Dutch, Chinese (Simplified)
2325

24-
Many open LLMs available today license the model itself for derivative work, but because they bring in large amounts of training data without discriminating by license, most companies can't use the output of those models since it potentially presents intellectual property concerns.
26+
And the Capabilities also include:
2527

26-
Granite Code comes in a wide range of sizes to fit your workstation's available resources. Generally, the bigger the model, the better the results, with a tradeoff: model responses will be slower, and it will take up more resources on your machine. In this lab, we'll try the 8b option for code generation. You could also use the `20b` version, if the wifi connection speed allows for it.
28+
- Summarization
29+
- Text classification
30+
- Text extraction
31+
- Question-answering
32+
- Retrieval Augmented Generation (RAG)
33+
- Code related tasks
34+
- Function-calling tasks
35+
- Multilingual dialog use cases
36+
- Long-context tasks including long document/meeting summarization, long document QA, etc.
2737

28-
Open up a terminal, and run the following command:
38+
Next click on the `wrench` icon, and open up the settings. For now we are going to configure the global settings for `ollama`
39+
but you may want to change it in the future.
2940

30-
```bash
31-
ollama pull granite-code:8b
32-
```
41+
![wrench icon](../images/anythingllm_wrench_icon.png)
3342

34-
## Set up Continue in VS Code
43+
Click on the "LLM" section, and select **Ollama** as the LLM Provider. Also select the `granite3.1-dense:8b` model. (You should be able to
44+
see all the models you have access to through `ollama` there.)
3545

36-
Assuming you've already [installed `continue`](/docs/pre-work/README.md#installing-continue), you'll need to configure it.
46+
![llm configuration](../images/anythingllm_llm_config.png)
3747

38-
Open the extension in the sidebar and find the Local Assistant's gear icon.
48+
Click the "Back to workspaces" button where the wrench was. And Click "New Workspace."
3949

40-
To open this config.yaml, you need to open the assistant's dropdown in the top-right portion of the chat input. On that dropdown beside the "Local Assistant" option, select the cog icon. It will open the local config.yaml.
50+
![new workspace](../images/anythingllm_new_workspace.png)
4151

42-
![](/docs/images/continue.png)
52+
Name it something like "learning llm" or the name of the event we are right now, something so you know it's somewhere you are learning
53+
how to use this LLM.
4354

44-
*The config.json can usually be found in `~/.continue/config.yaml`*
55+
![naming new workspace](../images/anythingllm_naming_workspace.png)
4556

46-
You can add a section for each model you want to use in this file. For this lab, we'll register the Granite Code model we downloaded earlier. Replace the line `"models": []` with the following:
57+
Now we can test our connections _through_ AnythingLLM! I like the "Who is Batman?" question, as a sanity check on connections and that
58+
it knows _something_.
4759

48-
```json
49-
"models": [
50-
{
51-
"title": "Granite Code 8b",
52-
"provider": "ollama",
53-
"model": "granite-code:8b"
54-
}
55-
],
56-
```
60+
![who is batman](../images/anythingllm_who_is_batman.png)
5761

58-
For inline code suggestions, it's generally recommended that you use smaller models since tab completion runs constantly as you type. This will reduce load on the machine. In the section that starts with `"tabAutocompleteModel"`, replace the whole section with the following:
62+
Now you may notice that the answer is slighty different then the screen shot above. That's expected and nothing to worry about. If
63+
you have more questions about it raise your hand and one of the helpers would love to talk you about it.
5964

60-
```json
61-
"tabAutocompleteModel": {
62-
"title": "Granite Code 8b",
63-
"provider": "ollama",
64-
"model": "granite-code:8b"
65-
},
66-
```
65+
Congratulations! You have AnythingLLM running now, configured to work with `granite3.1-dense` and `ollama`!
66+
67+
## Creating your own local RAG
68+
69+
Now that you have everything set up, lets build our own RAG. You need a document, of some sort to questions to answer against
70+
it. Lets start with something fun. As of right now, our Granite model doesn't know about the US Federal Budget in 2024, so lets
71+
ask it a question about it to verify.
6772

68-
## Sanity Check
73+
Create a new workspace, and call it whatever you want:
6974

70-
Now that you have everything configured in VSCode, let's make sure that it works. Ensure that `ollama` is running in the background either as a status bar item or in the terminal using `ollama serve`.
75+
![new budget workspace](../images/new_budget_workspace.png)
7176

72-
Open the Continue exension and test your local assistant.
77+
Now you have a new workspace, ask it a question like:
7378

74-
```text
75-
What language is popular for backend development?
7679
```
80+
What was the US federal budget for 2024?
81+
```
82+
83+
You should come back with something like the following, it may be different, but the gist is there.
84+
85+
![doesnt know the budget](../images/doent_know.png)
86+
87+
Not great right? Well now we need to give it a way to look up this data, luckly, we have a backed up
88+
copy of the budget pdf [here](https://github.com/user-attachments/files/18510560/budget_fy2024.pdf).
89+
Go ahead and save it to your local machine, and be ready to grab it.
90+
91+
Now spin up a **New Workspace**, (yes, please a new workspace, it seems that sometimes AnythingLLM has
92+
issues with adding things, so a clean environment is always easier to teach in) and call it
93+
something else.
94+
95+
![budget workspace](../images/budget_workspace.png)
96+
97+
Click on the "upload a document" to get the pdf added.
98+
99+
Next we need to add it to the workspace.
100+
101+
![adding pdf](../images/adding_pdf.png)
102+
103+
Next click the upload or drag and drop and put the pdf in there, and then the arrow to move it to the
104+
workspace. Click Save and Embed.
105+
106+
You have now added the pdf to the workspace.
77107

78-
Additionally, if you open a file for editing you should see possible tab completions to the right of your cursor (it may take a few seconds to show up).
108+
Now when the chat comes back up ask the same question, and you should see some new answers!
79109

80-
## Conclusion
110+
![success pdf](../images/success.png)
81111

82-
With your AI coding assistant now set up, move on to [Lab 6](https://ibm.github.io/opensource-ai-workshop/lab-6/) and actually use it!
112+
It won't be exactly what we are looking for, but it's enough to now see that the Granite model can
113+
leverage the local RAG and in turn can _look things up_ for you. You'll need some prompt engineering
114+
to get exactly what you want but this is just the start of leveraging the AI!
83115

84116
<script data-goatcounter="https://tracker.asgharlabs.io/count"
85117
async src="//tracker.asgharlabs.io/count.js"></script>

docs/lab-6/README.md

Lines changed: 62 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,98 @@
11
---
2-
title: Coding with an AI Assistant
3-
description: Write code using Continue and Granite
2+
title: Using Open-WebUI for a local RAG
3+
description: Learn how to build a simple local RAG
44
logo: images/ibm-blue-background.png
55
---
66

7-
## Setup
7+
## Retrieval-Augmented Generation overview
8+
The LLMs we're using for these labs have been trained on billions of parameters, but they haven't been trained on everything, and the smaller models have less general knowledge to work with.
9+
For example, even the latest models are trained with aged data, and they couldn't know about current events or the unique data your use-case might need.
810

9-
First, get comfortable with Continue. For example, if you prefer that your local assistant have its own slice of the window, you can drag it to the right sidebar.
11+
RAG allows the user to supplement the LLM's data with up-to-date information from external sources, like databases and documents.
1012

11-
![](https://docs.continue.dev/assets/images/move-to-right-sidebar-b2d315296198e41046fc174d8178f30a.gif)
13+
In this lab we're going to use one of the smallest IBM Granite models and show that it's answer is not complete. Then we'll add a small RAG document and allow it render a much better answer
14+
utilizing both it's internal data combined with the RAG data you give it.
1215

13-
You can also take a look at the [Continue documentation](https://docs.continue.dev/chat/how-to-use-it), or at least have it open in case you want to refer to it.
16+
## Configuration and Sanity Check
1417

15-
Now that our local AI co-pilot is up and running, let’s put it to work. The following examples will focus on `python`, but the same approach applies to other languages like `go`, `javascript`, or `rust`.
18+
Open up [Open-WebUI](http://localhost:8080/), and you should see something like the following:
19+
![default screen](../images/openwebui_open_screen.png)
1620

17-
A key part of learning to use this technology effectively is exploring the boundaries of what it can and can’t do.
21+
If you see this that means Open-WebUI is installed correctly, and we can continue configuration, if not, please find a workshop TA or
22+
raise your hand we'll be there to help you ASAP.
1823

19-
As you work through this lab, keep in mind: this assistant is here to support your workflow — not to do the work for you!
20-
21-
!!! tip
22-
If you lose the Continue pane in VSCode, you can re-enable it in VSCode by clicking at the top of the screen under "View --> Appearance --> Secondary Side Bar" and then the Continue window will be visible again.
23-
24-
## Writing a `main.py`
25-
26-
Clear the Continue window using `cmd+l` so we can start with a clean slate and create a new file called `main.py` in a new directory.
27-
28-
![clear](../images/clearscreen.png)
29-
30-
With your `main.py` open, use the `cmd+i` to open up the `Generate Code` command palette. You should see some information about what file and line will be edited. Give it the following prompt:
24+
Next as a sanity check, run the following command to confirm you have the [granite3.3:2b](https://ollama.com/library/granite3.3:2b)
25+
model downloaded in `ollama`. This may take a bit, but we should have a way to copy it directly on your laptop.
3126

27+
```bash
28+
ollama pull granite3.3:2b
3229
```
33-
Write the code for conway's game of life using pygame
34-
```
35-
36-
!!! note
37-
[What is Conway's Game of Life?](https://en.wikipedia.org/wiki/Conway's_Game_of_Life)
38-
39-
After a few moments, the model should start writing code in the file, it might look something like:
40-
![gameoflife_v1](../images/gameoflife_v1.png)
4130

42-
## AI-Generated Code
31+
If you didn't know, the supported languages with `granite3.3:2b` now include:
4332

44-
You can try to run it... *but would it work?* Do you see any potential errors in this code? If the code you generated worked, then consider yourself lucky! You can see below that this instance of generated code doesn't provide any output.
33+
- English, German, Spanish, French, Japanese, Portuguese, Arabic, Czech, Italian, Korean, Dutch, Chinese (Simplified)
4534

46-
![](../images/nowork.png)
35+
And the Capabilities also include:
4736

48-
This is an important lesson for using _any_ AI co-pilot code assistants. While they can provide a lot of helpful code towards what you need, it often won't get you across the finish line.
37+
- Thinking
38+
- Summarization
39+
- Text classification
40+
- Text extraction
41+
- Question-answering
42+
- Retrieval Augmented Generation (RAG)
43+
- Code related tasks
44+
- Function-calling tasks
45+
- Multilingual dialog use cases
46+
- Fill-in-the-middle
47+
- Long-context tasks including long document/meeting summarization, long document QA, etc.
4948

50-
## Cleaning up the AI-Generated Code
5149

52-
At this point, you can practice debugging or refactoring code with the AI co-pilot. Maybe it's a missing indent or the functions could be better organized for your understanding.
50+
Next click on the down arrow at the top and select the "granite3.3:2b" if it's not already selected.
5351

54-
!!! note
55-
You can try using the built-in autocomplete and code assistant functions to generate any missing code.
56-
In the example generated code, a "main" entry point to the script is missing. In this case, using `cmd+I` again and trying the prompt: "write a main function for my game that plays ten rounds of Conway's
57-
game of life using the `board()` function." might help. What happens?
52+
![model selection](../images/openwebui_model_selection.png)
5853

59-
It's hard to read the generated code in the example case, making it difficult to understand the logic. To clean it up, I'll define a `main` function so the entry point exists. There's also a `tkinter` section in the generated code, I decided to put the main game loop there:
60-
61-
```python
62-
if __name__ == '__main__':
63-
root = tkinter.Tk()
64-
game_of_life(tkinter.Canvas(root))
65-
root.mainloop()
54+
Click on the "New Chat" icon to clear the context. Then, ask the model for:
55+
```bash
56+
List all the past and current CEOs of the IBM corporation in order of their term as CEO
6657
```
58+
For example:
59+
![Small LLM CEO list](../images/small_llm_ceo_list.png)
6760

68-
In this generated code, there are also missing imports:
61+
At first glance, the list looks pretty good. But if you know your IBM CEOs, you'll notice that it misses a few of them, and sometimes adds new names that weren't ever IBM CEOs!
62+
(Note: the larger granite3.3:8b does a much better job on the IBM CEOs, you can try it later)
63+
But we can provide the small LLM with a RAG document that supplements the model's missing informaiton with a correct list, so it will generate a better answer.
6964

70-
```python
71-
import tkinter
72-
import time
73-
```
65+
Click on the "New Chat" icon to clear the context. Then download a small text file with the correct list of IBM CEOs to your Downloads folder:
7466

75-
It looks like the code is improving:
67+
[IBM.txt](../resources/IBM.txt)
7668

77-
![tk nothing](../images/tk_nothing.png)
69+
Right click on the IBM.txt URL and select "Save Link As" and save it as IBM in your Downloads folder.
7870

79-
## Explaining the Code
71+
In your Open-WebUI browser, click on the "+" under the "send a message" prompt and then select "Upload files"
8072

81-
To debug further, use Granite-Code to explain what the different functions do. Simply highlight one of them, use `cmd+L` to add it to the context window of your assistant and write a prompt similar to:
73+
Select the IBM.txt file that you just downloaded in your Downloads folder and press Open.
8274

83-
```text
84-
what does this function do?
85-
```
86-
87-
![explain code](../images/explain_code.png)
88-
89-
Asking for an explanation of portions of code can be very helpful with understanding logic that isn't clear right away. The model might even catch or highlight problems in the code if your prompt encourages it to.
90-
91-
## Creating Tests
92-
93-
One of the most effective ways to streamline your workflow as a developer is by writing tests for your code. Tests act as a safety net, helping you catch unintended changes. Tests can be time-consuming to write, and Granite Code can help generate them for you.
75+
![RAG Doc Added](../images/rag_doc_added.png)
9476

95-
Assuming you still have a function you wanted explained above in the context-window for your local assistant, you can use the prompt:
96-
97-
```text
98-
write a pytest test for this function
77+
Now ask it our question about the CEOs of IBM:
78+
```bash
79+
List all the past and current CEOs of the IBM corporation in order of their term as CEO
9980
```
81+
The answer should now be correct. (For example, always before it forgets John Akers)
10082

101-
The model generated a great framework for a test here:
102-
![lazy pytest](../images/pytest_test.png)
103-
104-
Notice that the test only spans what is provided in the context, so it isn't integrated into my project yet. But, the code provides a good start. I'll need to create a new test file and integrate `pytest` into my project to use it.
83+
![CEO list with RAG](../images/ceo_list_with_rag.png)
10584

106-
## Adding Comments
85+
We can also find and download information to pdf from Wikipedia:
86+
For example: [History of IBM](https://en.wikipedia.org/wiki/History_of_IBM)
10787

108-
Continue also provides the ability to automatically add comments to code. Try it out!
88+
On the right of the Wikipedia page, click on "Tools" and click on "Download as PDF"
10989

110-
![comment_code](../images/comment_code.png)
90+
Then use this History_of_IBM.pdf as a RAG by clicking on the + and select "History_of_IBM.pdf" as a file from your Downloads folder.
11191

112-
## Conclusion
113-
114-
This lab was all about using our local, open-source AI co-pilot to write complex code in Python. By combining Continue and Granite-Code, we were able to generate code, explain functions, write tests, and add comments to our code!
92+
Next, use the Open-WebUI to ask more questions about IBM, or have it summarize the document itself. For example:
93+
```bash
94+
Write a short 300 word summary of the History_of_IBM.pdf
95+
```
96+
![Summary of IBM History](../images/History_of_IBM_summary.png)
11597

116-
<script data-goatcounter="https://tracker.asgharlabs.io/count"
117-
async src="//tracker.asgharlabs.io/count.js"></script>
98+
Congratulations, you've completed the Open-WebUI RAG example.

0 commit comments

Comments
 (0)