chapter thirteen

13 System Prompts and Parameter Tuning

 

This chapter covers

  • What system prompts are and how they shape model behavior
  • Building personality presets for different use cases
  • How temperature and other parameters control response style
  • Creating reusable custom models with Ollama Modelfiles
  • Adding customization controls to your Streamlit chatbot

Your chatbot works. It answers questions and holds conversations. But right now it behaves like a generic assistant -- polite and helpful, but without any distinctive character. In this chapter, you will learn how to give your chatbot a personality, control how creative or predictable its responses are, and bundle all your customizations into reusable model configurations.

By the end, your chatbot will have a sidebar with personality presets, a temperature slider, and the ability to behave like anything from a strict coding mentor to a pirate tutor.

13.1 System Prompts Explained

When you chat with an LLM, every conversation is made up of messages. Each message has a role: either user (that is you) or assistant (that is the AI). But there is a third role that most people never see: system.

The system message is a special instruction sent before the conversation begins. It sets the rules, personality, and boundaries for the model. The model reads the system prompt first and follows those instructions in every response it generates (figure 13.1).

13.1.1 How System Prompts Work in the API

13.2 Personality Presets

13.2.1 Preset 1: The Professional Consultant

13.2.2 Preset 2: The Patient Study Buddy

13.2.3 Preset 3: The Pirate Tutor

13.2.4 Preset 4: The Strict Coding Mentor

13.2.5 Preset 5: The Concise Expert

13.3 Temperature and Creative Parameters

13.3.1 What Temperature Does

13.3.2 Side-by-Side Comparison

13.3.3 Other Important Parameters

13.3.4 Parameter Reference Table

13.4 Creating Custom Models with Ollama Modelfiles

13.4.1 The Modelfile Format

13.4.2 Key Modelfile Instructions

13.4.3 Building a Custom Model Step by Step

13.4.4 More Modelfile Examples

13.4.5 Managing Custom Models

13.5 Adding Customization Controls to the Streamlit UI

13.5.1 The Enhanced Chatbot

13.5.2 How the System Prompt Affects the Pipeline

13.6 Summary

13.7 Exercises