Now that you understand the basics of prompts, instructions, context, and temperature, it's time to put that knowledge into practice. This section guides you through simple exercises using your local LLM. The goal is to get comfortable interacting with the model and observing how different inputs influence its responses.To follow along, you'll need your local LLM environment running, preferably using one of the tools discussed in the previous chapter, such as Ollama (via the command line) or LM Studio (using its graphical interface). For these initial exercises, a smaller model like phi3:mini or a 3B/7B parameter model in GGUF format is often sufficient and provides quicker responses.Exercise 1: Asking Simple QuestionsLet's start with the most straightforward interaction: asking questions.Open your interaction tool:If using Ollama: Open your terminal and start a chat session with a downloaded model, for example: ollama run phi3:mini (replace phi3:mini with your chosen model).If using LM Studio: Launch the application, load your chosen model in the "Chat" tab.Ask a factual question: Type a simple question and press Enter. Try these examples:What is the currency used in Japan?Who painted the Mona Lisa?What is 2 + 2?Observe the response: Look at the answer provided by the LLM. Is it accurate? Is it brief or detailed? Does it just answer the question, or does it add extra context? LLMs are trained on enormous amounts of text, so they often excel at retrieving factual information, although they can sometimes make mistakes (known as "hallucinations").Try variations: Ask the same question using slightly different wording. For instance:Currency in Japan?Tell me the currency of Japan.Leonardo da Vinci painted which famous portrait? Does the model give the same answer? Small changes in phrasing can sometimes lead to different responses or levels of detail.Exercise 2: Giving Simple InstructionsNow, let's move from asking questions to giving the LLM simple tasks to perform.Request text generation: Ask the model to create something simple.Write one sentence about a sunny day.Compose a two-line poem about a robot.Request text manipulation: Give the model some text and ask it to modify it.Summarize this paragraph in a single sentence: Artificial intelligence research has progressed significantly over the past decade, driven by advances in computing power, large datasets, and algorithmic innovations. Many applications are now common, from virtual assistants to recommendation systems.Rephrase this sentence: The meeting was postponed due to unforeseen circumstances.Request structured output: Ask for information in a specific format.List three types of fruit.Provide two advantages of running LLMs locally.Observe the results: Did the model follow your instructions accurately? For summarization or rephrasing, did it capture the main idea? For lists, was the formatting clear? This shows the model's ability to understand commands beyond simple questions.Exercise 3: Exploring the Context WindowThe context window acts like the LLM's short-term memory during a conversation. Let's see it in action.Start a fresh conversation: If your tool allows, clear the current chat history or start a new session. This ensures you begin with an empty context.Ollama CLI: You might need to exit (/bye) and restart the ollama run command.LM Studio: Use the "New Chat" button.Establish a fact: Provide a piece of information.My favorite animal is the otter. (Wait for the LLM's acknowledgment, often a simple "Okay" or similar).Test recall: Ask about the information you just provided.What is my favorite animal? The model should correctly recall "otter" because your previous message is still within its context window.Introduce unrelated topics: Have a short exchange about something different.Prompt 1: What's a common use for Python?Prompt 2: Tell me a joke.Test recall again: Ask about the original fact.What did I say my favorite animal was earlier? Depending on the length of the intervening conversation and the model's specific context window size, it might still remember, or it might have "forgotten" the information about the otter. This demonstrates that the context window has a limited size. Information from much earlier in a long conversation might fall out of this window and become unavailable to the model for generating subsequent responses.Exercise 4: Observing the Effect of TemperatureAs mentioned earlier, the $temperature$ setting controls the randomness of the LLM's output. Higher values lead to more varied and sometimes creative responses, while lower values produce more predictable and focused text. Note: This setting is easily accessible in tools like LM Studio but may not be directly adjustable during a chat session in the basic Ollama command line.Locate the Temperature setting: If using a tool like LM Studio, find the configuration panel (often on the right side of the chat interface). You should see a setting labeled "Temperature," usually represented as a slider or a number input field (typically ranging from $0$ to $1$ or higher).Set Temperature Low: Adjust the temperature to a low value, such as $0.2$.Generate Text: Use a simple creative prompt and run it a couple of times.Prompt: Write a sentence describing a magical forest.Run this prompt 2-3 times. Observe that the outputs are likely quite similar, perhaps only varying slightly in word choice.Set Temperature High: Increase the temperature significantly, for example, to $0.9$ or $1.0$.Generate Text Again: Use the exact same prompt as before.Prompt: Write a sentence describing a magical forest.Run this prompt 2-3 times. Notice that the generated sentences are likely much more different from each other compared to the low-temperature examples. They might be more imaginative but could also potentially be less coherent or focused.{"data": [{"x": [0.1, 0.2, 0.5, 0.8, 1.0, 1.2], "y": [1, 2, 4, 7, 9, 10], "mode": "lines+markers", "type": "scatter", "name": "Randomness/Diversity", "marker": {"color": "#228be6"}, "line": {"color": "#228be6"}}], "layout": {"title": "Effect of Temperature on Output Diversity", "xaxis": {"title": "Temperature Setting"}, "yaxis": {"title": "Relative Output Diversity/Randomness", "range": [0, 11]}, "margin": {"l": 60, "r": 20, "t": 40, "b": 40}}}Relationship between the temperature setting and the diversity or randomness observed in the LLM's generated text. Lower temperatures result in less randomness, while higher temperatures increase it.This exercise helps illustrate how you can influence the LLM's output style. For tasks requiring factual accuracy or consistency, a lower temperature is generally preferred. For creative writing or brainstorming, a higher temperature might yield more interesting results.These exercises provide a starting point for interacting with your local LLM. Don't hesitate to experiment further! Try different kinds of questions, instructions, and models. The more you practice, the better you'll become at formulating prompts that elicit the responses you need.