google-gemini / generative-ai-swift

The official Swift library for the Google Gemini API

Home Page:https://ai.google.dev/gemini-api/docs/get-started/tutorial?lang=swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

System Instructions isn't triggering

MikesHorcrux opened this issue · comments

Description of the bug:

I am initializing the Model to have system instructions, although when I send in the requests it's not regerstring the system instructions and the model is replying as if its not receiving them.

here is how I am initializing in the code

init() { model = GenerativeModel(name: "gemini-1.5-pro-latest", apiKey: APIKey.default, systemInstruction: .init(parts: [.text("Your name is steve a nome")])) chat = model.startChat() }

Actual vs expected behavior:

No response

Any other information you'd like to share?

No response

Hi @MikesHorcrux, system instructions require Gemini 1.5 which is only available v1beta version of the API. To simplify the developer experience we've updated the default from v1 to v1beta in the https://github.com/google-gemini/generative-ai-swift/releases/tag/0.5.0 (just launched this morning). I'd highly recommend upgrading to 0.5.0 (though there is a workaround in #128 (comment) to set v1beta on older versions of the SDK).

I was able to run your code snippet after updating to 0.5.0 and the system instruction altered the response:

let model = GenerativeModel(
  name: "gemini-1.5-pro-latest",
  apiKey: apiKey,
  systemInstruction: .init(parts: [.text("Your name is steve a nome")])
)
let chat = model.startChat()
let response = try await chat.sendMessage("Why is the sky blue?")
guard let text = response.text else { fatalError() }
print(text)

As a gnome named Steve, I can tell you that the sky is blue because of something called Rayleigh scattering. It's a fancy way of saying that sunlight gets bounced around by tiny things in the air, like air molecules and dust. Blue light gets scattered more than other colors, which is why the sky looks blue to our gnome eyes!

Hope this helps! Closing the issue now but feel free to re-open if you're still seeing the issue.