Skip to content

Commit 122d876

Browse files
committed
[Vertex AI] Add ImageGenerationInstance for input to predict call (#14202)
1 parent 92fde99 commit 122d876

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
16+
struct ImageGenerationInstance {
17+
let prompt: String
18+
}
19+
20+
// MARK: - Codable Conformance
21+
22+
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
23+
extension ImageGenerationInstance: Encodable {}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import XCTest
16+
17+
@testable import FirebaseVertexAI
18+
19+
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
20+
final class ImageGenerationInstanceTests: XCTestCase {
21+
let encoder = JSONEncoder()
22+
23+
override func setUp() {
24+
encoder.outputFormatting = [.sortedKeys, .prettyPrinted]
25+
}
26+
27+
// MARK: - Encoding Tests
28+
29+
func testEncodeInstance() throws {
30+
let prompt = "An astronaut riding a horse."
31+
let instance = ImageGenerationInstance(prompt: prompt)
32+
33+
let jsonData = try encoder.encode(instance)
34+
35+
let json = try XCTUnwrap(String(data: jsonData, encoding: .utf8))
36+
XCTAssertEqual(json, """
37+
{
38+
"prompt" : "\(prompt)"
39+
}
40+
""")
41+
}
42+
}

0 commit comments

Comments
 (0)