TemplateImagenModelTests.swift 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2025 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 of 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. @testable import FirebaseAILogic
  15. import XCTest
  16. @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
  17. final class TemplateImagenModelTests: XCTestCase {
  18. var urlSession: URLSession!
  19. var model: TemplateImagenModel!
  20. override func setUp() {
  21. super.setUp()
  22. let configuration = URLSessionConfiguration.default
  23. configuration.protocolClasses = [MockURLProtocol.self]
  24. urlSession = URLSession(configuration: configuration)
  25. let firebaseInfo = GenerativeModelTestUtil.testFirebaseInfo()
  26. let generativeAIService = GenerativeAIService(
  27. firebaseInfo: firebaseInfo,
  28. urlSession: urlSession
  29. )
  30. let apiConfig = APIConfig(service: .googleAI(endpoint: .firebaseProxyProd), version: .v1beta)
  31. model = TemplateImagenModel(generativeAIService: generativeAIService, apiConfig: apiConfig)
  32. }
  33. func testGenerateImages() async throws {
  34. MockURLProtocol.requestHandler = try GenerativeModelTestUtil.httpRequestHandler(
  35. forResource: "unary-success-generate-images-base64",
  36. withExtension: "json",
  37. subdirectory: "mock-responses/vertexai",
  38. isTemplateRequest: true
  39. )
  40. let response = try await model.generateImages(
  41. templateID: "test-template",
  42. inputs: ["prompt": "a cat picture"]
  43. )
  44. XCTAssertEqual(response.images.count, 4)
  45. XCTAssertNotNil(response.images.first?.data)
  46. }
  47. }