user60108
user60108

Reputation: 3452

Implementing System Prompts in Gemini Pro for Chatbot Creation

I am in the process of learning and developing a chatbot using Gemini Pro. My previous experience includes extensive use of the GPT API, where I became familiar with a concept of "system prompts". In the chat history of GPT, there are three types of messages: those entered by the user, the responses generated by the model, and a special type of message with the role of "system", which allows providing direct instructions to the model, such as "Behave like an expert assistant in...".

My question is: How can I implement a similar strategy with Gemini Pro? I have searched for relevant information online without success. Although I have noticed that some models in Vertex AI support a specific context, it seems that Gemini does not offer this functionality directly according to the official documentation https://cloud.google.com/vertex-ai/docs/generative-ai/chat/chat-prompts#gemini-1.0-pro.

What would be the best way to give behavioral instructions to Gemini while differentiating them from the user's text, to avoid hacking techniques in the prompt of a malicious user?

Upvotes: 5

Views: 5107

Answers (3)

Jami Bailey
Jami Bailey

Reputation: 31

Gemini 1.5 added support for system instructions. This is done via the generative_model system instructions option. Example and link to usage below. Just note that it is not at this time exactly equal to OpenAI's implementation of the system message but it is the closest thing to it.

model=genai.GenerativeModel(
  model_name="gemini-1.5-flash",
  system_instruction="You are a cat. Your name is Neko.")

https://ai.google.dev/gemini-api/docs/system-instructions?lang=python

Upvotes: 1

I'm facing the same problem. My solution was formatting the user message as follows:

"Your general instruction: <> Answer the user message: <>"

It works for me, but I'm not entirely comfortable with it. I'm really waiting for a final solution from Gemini.

Upvotes: 3

stippi
stippi

Reputation: 925

I also just started looking into Gemini with a similar background as yourself. I came up with the following:

  • I prepend the system message with the string "Hi. I'll explain how you should behave:\n" and add it with role "USER".
  • Then I add another message with role "MODEL" and the contents "Ok, let's start! Please continue in your native language."
  • Then I insert the first actual user message.

I have quite an extensive system message, and the above trick seems to work well.

Upvotes: 2

Related Questions