Skip to content

Commit

Permalink
Make system instruction accept variadic String... (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard committed May 1, 2024
1 parent dc00663 commit 16e68be
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 5 additions & 2 deletions Sources/GoogleAI/GenerativeModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public final class GenerativeModel {
safetySettings: [SafetySetting]? = nil,
tools: [Tool]? = nil,
toolConfig: ToolConfig? = nil,
systemInstruction: String,
systemInstruction: String...,
requestOptions: RequestOptions = RequestOptions()) {
self.init(
name: name,
Expand All @@ -73,7 +73,10 @@ public final class GenerativeModel {
safetySettings: safetySettings,
tools: tools,
toolConfig: toolConfig,
systemInstruction: ModelContent(role: "system", parts: systemInstruction),
systemInstruction: ModelContent(
role: "system",
parts: systemInstruction.map { ModelContent.Part.text($0) }
),
requestOptions: requestOptions,
urlSession: .shared
)
Expand Down
8 changes: 7 additions & 1 deletion Tests/GoogleAITests/GoogleAITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ final class GoogleGenerativeAITests: XCTestCase {
let _ = GenerativeModel(
name: "gemini-1.5-pro-latest",
apiKey: "API_KEY",
systemInstruction: "Talk like a pirate"
systemInstruction: "Talk like a pirate."
)

let _ = GenerativeModel(
name: "gemini-1.5-pro-latest",
apiKey: "API_KEY",
systemInstruction: "Talk like a pirate.", "Your name is Francis Drake."
)

// All arguments passed.
Expand Down

0 comments on commit 16e68be

Please sign in to comment.