Text Generation with Google Gemini

Nov 14 2024 · Python 3.12, Google Gemini, JupyterLab, Visual Studio Code

Lesson 03: Text Generation with Google Gemini API

Demo: Using Parameters

Episode complete

Play next episode

Next

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Demo: Using Parameters

Now, you’ll experiment with the parameters. At the bottom of your Python script from the last demo, add a code cell and then add:

genai.get_model('models/gemini-1.5-pro')
generation_config = genai.types.GenerationConfig(
  candidate_count = 1,
  # stop_sequences = [';']
  # max_output_tokens = 32000
  # temperature = 0.0,
  # top_k = 4,
  # top_p = 1
)
response = model.generate_content(
  'Write a rap about doing the dishes',
  generation_config = generation_config
)
print(response.text)
stop_sequences = [',']
max_output_tokens = 25
model = genai.GenerativeModel('gemini-pro', generation_config =
  generation_config)
See forum comments
Cinema mode Download course materials from Github
Previous: Text Generation Parameters Next: Conclusion