Skip to content

Commit a7044b6

Browse files
andrewheardG.Dev.Ssomsak
authored andcommitted
Add function calling sample (google-gemini#127)
1 parent a167571 commit a7044b6

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

Examples/GenerativeAISample/FunctionCallingSample/Screens/FunctionCallingScreen.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ struct FunctionCallingScreen: View {
6565
}
6666
}
6767
})
68-
.onTapGesture {
69-
focusedField = nil
70-
}
7168
}
7269
InputField("Message...", text: $userPrompt) {
7370
Image(systemName: viewModel.busy ? "stop.circle.fill" : "arrow.up.circle.fill")

Examples/GenerativeAISample/FunctionCallingSample/ViewModels/FunctionCallingViewModel.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class FunctionCallingViewModel: ObservableObject {
3939

4040
init() {
4141
model = GenerativeModel(
42-
name: "gemini-1.5-flash-latest",
42+
name: "gemini-1.0-pro",
4343
apiKey: APIKey.default,
4444
tools: [Tool(functionDeclarations: [
4545
FunctionDeclaration(
@@ -61,7 +61,8 @@ class FunctionCallingViewModel: ObservableObject {
6161
],
6262
requiredParameters: ["currency_from", "currency_to"]
6363
),
64-
])]
64+
])],
65+
requestOptions: RequestOptions(apiVersion: "v1beta")
6566
)
6667
chat = model.startChat()
6768
}
@@ -157,7 +158,7 @@ class FunctionCallingViewModel: ObservableObject {
157158
case let .functionCall(functionCall):
158159
messages.insert(functionCall.chatMessage(), at: messages.count - 1)
159160
functionCalls.append(functionCall)
160-
case .data, .fileData, .functionResponse:
161+
case .data, .functionResponse:
161162
fatalError("Unsupported response content.")
162163
}
163164
}

0 commit comments

Comments
 (0)