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

Feature to support "system_instruction"

mobilinked opened this issue · comments

Description of the feature request:

I'm currently utilizing 'gemini-1.5-pro-latest', and I'm aiming to implement the system instructions as outlined on https://ai.google.dev/docs/system_instructions. However, I've encountered difficulties in locating the section where I can configure the parameters, and I've also been unable to find any corresponding code within the library.

What problem are you trying to solve with this feature?

"system_instruction" is useful for our logic

Any other information you'd like to share?

No response

And:

I am employing the code below to achieve my objectives, assuming that system instruction support is available. It appears to be functioning as expected:

let systemInstruction = try Self.systemInstruction(from: file, for: language)
let history = [
     ModelContent(role: "model", parts: systemInstruction)
]

Hi @mobilinked, support for system instructions just got added in the https://github.com/google/generative-ai-swift/releases/tag/0.4.11 yesterday. Please update to that version if you haven't.

The example in #129 might be helpful. Based on your snippet above, it should be something like:

let systemInstruction = try Self.systemInstruction(from: file, for: language)
let model = GenerativeModel(
  name: "gemini-1.5-pro-latest",
  apiKey: APIKey.default,
  systemInstruction: ModelContent(role: "system", parts: systemInstruction),
  requestOptions: RequestOptions(apiVersion: "v1beta")
)

Thank you much. It works.