1import requests2
3API_URL = "http://localhost:11434/v1/chat/completions"4MODEL = "gemma3:1b"5
6def chat_with_gemma3(prompt: str, max_tokens: int = 80) -> str:7 payload = {8 "model": MODEL,9 "messages": [10 {"role": "system", "content": "You are a helpful assistant."},11 {"role": "user", "content": prompt}12 ],13 "max_tokens": max_tokens,14 "temperature": 0.715 }16 r = requests.post(API_URL, json=payload)17 r.raise_for_status()18 data = r.json()19 # The generated text is in choices[0].message.content20 return data["choices"][0]["message"]["content"]21
22if __name__ == "__main__":23 user_prompt = "What hardware specs are ideal for running Gemma3?"24 print("Gemma3 says:", chat_with_gemma3(user_prompt, max_tokens=100))
You've completed this chapter! 🎉