Skip to content

Commit

Permalink
Update package
Browse files Browse the repository at this point in the history
  • Loading branch information
vmanot committed Dec 11, 2024
1 parent ea6cffd commit 0b73637
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 27 deletions.
15 changes: 12 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ let package = Package(
.library(
name: "Gemini",
targets: [
"Gemini"
"Gemini",
"GoogleGenerativeAI",
]
),
],
Expand All @@ -40,12 +41,20 @@ let package = Package(
dependencies: [
"AI"
],
path: "Sources"
path: "Sources/GoogleAI"
),
.target(
name: "GoogleGenerativeAI",
dependencies: [
"Gemini"
],
path: "Sources/GoogleGenerativeAI"
),
.testTarget(
name: "GeminiTests",
dependencies: [
"Gemini"
"Gemini",
"GoogleGenerativeAI",
],
path: "Tests",
resources: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//

@_spi(Internal) import LargeLanguageModels
import FoundationX
import Swallow
import SwiftUIX

Expand All @@ -17,18 +18,28 @@ extension ModelContent {

for component in messageContent.components {
switch component.payload {
case .string(let string):
parts.append(.text(string))
case .image(let image):
if case .url(let url) = image {
let (data, response) = try await URLSession.shared.data(from: url)
let mimeType = response.mimeType ?? "image/png"
parts.append(.data(mimetype: mimeType, data))
}
case .functionCall(_):
TODO.unimplemented
case .resultOfFunctionCall(_):
TODO.unimplemented
case .string(let string):
parts.append(.text(string))
case .image(let image):
switch image {
case .url(let url): do {
let (data, response) = try await URLSession.shared.data(from: url)
let mimeType: String = response.mimeType ?? "image/png"

parts.append(.data(mimetype: mimeType, data))
}
case .image(let image):
let data: Data = try image.jpegData.unwrap()
let mimeType: String = _MediaAssetFileType.jpeg.mimeType

parts.append(.data(mimetype: mimeType, data))
case .base64DataURL:
TODO.unimplemented
}
case .functionCall(_):
TODO.unimplemented
case .resultOfFunctionCall(_):
TODO.unimplemented
}
}

Expand Down
5 changes: 5 additions & 0 deletions Sources/GoogleGenerativeAI/module.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//
// Copyright (c) Preternatural AI, Inc.
//

@_exported import Gemini
1 change: 1 addition & 0 deletions Tests/GoogleAITests/ChatTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import Foundation
@testable import Gemini
@testable import GoogleGenerativeAI
import XCTest

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, *)
Expand Down
1 change: 1 addition & 0 deletions Tests/GoogleAITests/CodeExecutionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import XCTest

@testable import Gemini
@testable import GoogleGenerativeAI

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
Expand Down
1 change: 1 addition & 0 deletions Tests/GoogleAITests/GenerateContentRequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Foundation
import XCTest

@testable import Gemini
@testable import GoogleGenerativeAI

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
final class GenerateContentRequestTests: XCTestCase {
Expand Down
1 change: 1 addition & 0 deletions Tests/GoogleAITests/GenerateContentResponseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import Foundation
import XCTest

@testable import Gemini
@testable import GoogleGenerativeAI

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
Expand Down
2 changes: 1 addition & 1 deletion Tests/GoogleAITests/GenerationConfigTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import Foundation
import Gemini
import GoogleGenerativeAI
import XCTest

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
Expand Down
1 change: 1 addition & 0 deletions Tests/GoogleAITests/GenerativeModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

@testable import Gemini
@testable import GoogleGenerativeAI
import XCTest

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, *)
Expand Down
2 changes: 1 addition & 1 deletion Tests/GoogleAITests/GoogleAITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import Gemini
import GoogleGenerativeAI
import XCTest
#if canImport(AppKit)
import AppKit // For NSImage extensions.
Expand Down
2 changes: 1 addition & 1 deletion Tests/GoogleAITests/JSONValueTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
import XCTest

@testable import Gemini
@testable import GoogleGenerativeAI

final class JSONValueTests: XCTestCase {
let decoder = JSONDecoder()
Expand Down
2 changes: 1 addition & 1 deletion Tests/GoogleAITests/ModelContentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import Foundation
import Gemini
import GoogleGenerativeAI
import XCTest

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
Expand Down
2 changes: 1 addition & 1 deletion Tests/GoogleAITests/PartsRepresentableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import CoreGraphics
import CoreImage
import Gemini
import GoogleGenerativeAI
import XCTest
#if canImport(UIKit)
import UIKit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

import AI
import Gemini
import XCTest
import SwiftUIX
import XCTest

final class GoogleLLMRequestHandlingTestCase: XCTestCase {
let client: any LLMRequestHandling = Gemini.Client(apiKey: "AIzaSyB-HamvuejgTbWm6gRy1Bb_PnCclMWUloc")
final class PreternaturalAI_Tests: XCTestCase {
let client: any LLMRequestHandling = Gemini.Client(apiKey: "API_KEY")

func testAvailableModels() {
let models = client._availableModels
Expand Down Expand Up @@ -122,9 +122,17 @@ final class GoogleLLMRequestHandlingTestCase: XCTestCase {
Remember to ALWAYS respond in accordance to the testing rules.
"""

let parameters: AbstractLLM.ChatCompletionParameters = .init()
let parameters = AbstractLLM.ChatCompletionParameters()
let imageConfiguration = AppKitOrUIKitImage.SymbolConfiguration(
pointSize: 64
)
let image = AppKitOrUIKitImage(
_SwiftUIX_systemName: "arrow.up",
withConfiguration: imageConfiguration.applying(.init(hierarchicalColor: .blue))
)!

image.backgroundColor = AppKitOrUIKitColor.white

let image = AppKitOrUIKitImage(systemSymbolName: "arrow.right", accessibilityDescription: nil)!
let imageLiteral = try PromptLiteral(image: image)

let messagesWithSystemPrompt: [AbstractLLM.ChatMessage] = [
Expand All @@ -148,7 +156,7 @@ final class GoogleLLMRequestHandlingTestCase: XCTestCase {
let completion1: String = try await client.complete(
messagesWithSystemPrompt,
parameters: parameters,
model: Gemini.Model.gemini_1_5_flash,
model: Gemini.Model.gemini_2_0_flash_exp,
as: .string
)

Expand All @@ -157,7 +165,7 @@ final class GoogleLLMRequestHandlingTestCase: XCTestCase {
let completion2: String = try await client.complete(
messagesWithOutPrompt,
parameters: parameters,
model: Gemini.Model.gemini_1_5_flash,
model: Gemini.Model.gemini_2_0_flash_exp,
as: .string
)

Expand Down

0 comments on commit 0b73637

Please sign in to comment.