Create prompts to chat about code

This document shows you strategies for creating prompts that work with the supported model to have a chatbot conversation about code.

Use cases

Some common use cases for code chat are:

  • Debugging: Get help with debugging code that doesn't compile or that contains a bug.
  • Documentation: Get help with understanding code so you can document it accurately.
  • Learning: Get help with learning about code you're not very familiar with.

Supported models

The following models support code chat tasks:

  • Gemini 1.5 Flash (Preview)
  • Gemini 1.5 Pro (Preview)
  • Gemini 1.0 Pro

Example code chat prompt

You can use the code chat model to generate code. In the following example chat, the user requests a function that calculates the minimum of two numbers.

This is the user's first prompt:

Hi, how are you?
I'm doing great, thanks for asking! How can I help you today?

This is the user's second prompt that results in code generation for a function:

Please help write a function to calculate the min of two numbers.
def min_of_two_numbers(a, b):
 """Returns the minimum of two numbers."""

 if a < b:
   return a
   return b

What's next