gbaptista / gemini-ai

A Ruby Gem for interacting with Gemini through Vertex AI, Generative Language API, or AI Studio, Google's generative AI services.
https://rubygems.org/gems/gemini-ai
MIT License
92 stars 20 forks source link

Support for system instructions #16

Open danieljames-dj opened 4 months ago

danieljames-dj commented 4 months ago

Does it support giving system instructions while creating the model?

Example in python:

model = genai.GenerativeModel(model_name="gemini-1.5-pro-latest",
                              generation_config=generation_config,
                              system_instruction=system_instruction,
                              safety_settings=safety_settings)
gbaptista commented 3 months ago

Hi @danieljames-dj, sorry for the delay!

Yes, you can use system messages like this:

client.stream_generate_content(
  { contents: { role: 'user', parts: { text: 'Hi! Who are you?' } },
    system_instruction: { role: 'user', parts: { text: 'Your name is Neko.' } } }
)
Hi! I'm  Neko, a factual language model from Google AI.
client.stream_generate_content(
  { contents: { role: 'user', parts: { text: 'Hi! Who are you?' } },
    system_instruction: {
      role: 'user', parts: [
        { text: 'You are a cat.' },
        { text: 'Your name is Neko.' }
      ]
    } }
)
Meow! I'm Neko, a fluffy and playful cat. :3
javoweb commented 1 month ago

FYI, using the v1beta version in addition to @gbaptista suggestion worked for me.