Skip to content

Commit

Permalink
Add system instruction support (google-gemini#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard authored and G.Dev.Ssomsak committed Jun 21, 2024
1 parent d529c48 commit 0ff780b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Sources/GoogleAI/GenerateContentRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct GenerateContentRequest {
let safetySettings: [SafetySetting]?
let tools: [Tool]?
let toolConfig: ToolConfig?
let systemInstruction: ModelContent?
let isStreaming: Bool
let options: RequestOptions
}
Expand All @@ -35,6 +36,7 @@ extension GenerateContentRequest: Encodable {
case safetySettings
case tools
case toolConfig
case systemInstruction
}
}

Expand Down
9 changes: 8 additions & 1 deletion Tests/GoogleAITests/GoogleAITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,24 @@ final class GoogleGenerativeAITests: XCTestCase {
maxOutputTokens: 256,
stopSequences: ["..."])
let filters = [SafetySetting(harmCategory: .dangerousContent, threshold: .blockOnlyHigh)]
let systemInstruction = ModelContent(role: "system", parts: [.text("Talk like a pirate.")])

// Permutations without optional arguments.
let _ = GenerativeModel(name: "gemini-1.0-pro", apiKey: "API_KEY")
let _ = GenerativeModel(name: "gemini-1.0-pro", apiKey: "API_KEY", safetySettings: filters)
let _ = GenerativeModel(name: "gemini-1.0-pro", apiKey: "API_KEY", generationConfig: config)
let _ = GenerativeModel(
name: "gemini-1.0-pro",
apiKey: "API_KEY",
systemInstruction: systemInstruction
)

// All arguments passed.
let genAI = GenerativeModel(name: "gemini-1.0-pro",
apiKey: "API_KEY",
generationConfig: config, // Optional
safetySettings: filters // Optional
safetySettings: filters, // Optional
systemInstruction: systemInstruction // Optional
)
// Full Typed Usage
let pngData = Data() // ....
Expand Down

0 comments on commit 0ff780b

Please sign in to comment.