Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions Package.resolved

This file was deleted.

17 changes: 13 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.


import PackageDescription

let package = Package(
Expand All @@ -16,10 +17,10 @@ let package = Package(
targets: ["QuickBloxUIKit", "QuickBloxData", "QuickBloxDomain"]),
],
dependencies: [
.package(url: "https://github.com/QuickBlox/ios-quickblox-sdk", .upToNextMajor(from: "2.19.0")),
.package(url: "https://github.com/QuickBlox/ios-ai-answer-assistant.git", .upToNextMajor(from: "2.0.0")),
.package(url: "https://github.com/QuickBlox/ios-ai-translate.git", .upToNextMajor(from: "2.0.0")),
.package(url: "https://github.com/QuickBlox/ios-ai-rephrase.git", .upToNextMajor(from: "2.0.0"))
.package(url: "https://github.com/QuickBlox/ios-quickblox-sdk", .upToNextMajor(from: "2.21.0")),
.package(url: "https://github.com/QuickBlox/ios-ai-answer-assistant.git", .upToNextMajor(from: "2.1.0")),
.package(url: "https://github.com/QuickBlox/ios-ai-translate.git", .upToNextMajor(from: "2.1.0")),
.package(url: "https://github.com/QuickBlox/ios-ai-rephrase.git", .upToNextMajor(from: "2.1.0"))
],
targets: [
.target(
Expand Down Expand Up @@ -51,5 +52,13 @@ let package = Package(
"QuickBloxData",
"QuickBloxLog"],
resources: [.process("Resources")]),
.testTarget(
name: "QuickBloxUIKitIntegrationTests",
dependencies: ["QuickBloxUIKit",
"QuickBloxData",
"QuickBloxLog",
.product(name: "Quickblox",
package: "ios-quickblox-sdk")],
resources: [.process("Resources")]),
]
)
25 changes: 25 additions & 0 deletions Sources/QuickBloxData/DTO/AI/RemoteAnswerAssistMessageDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// RemoteAnswerAssistMessageDTO.swift
// QuickBloxUIKit
//
// Created by Injoit on 16.05.2024.
// Copyright © 2023 QuickBlox. All rights reserved.
//

import QuickBloxDomain
import Foundation

/// This is a DTO model for interactions with the Answer Assist Message models in remote storage.
public struct RemoteAnswerAssistMessageDTO {
var id = ""
var smartChatAssistantId = ""
var message = ""
var history: [RemoteAnswerAssistHistoryMessageDTO] = []
}

/// This is a DTO model for interactions with the Answer Assist History Message models in remote storage.
public struct RemoteAnswerAssistHistoryMessageDTO {
var id = ""
var role: AIMessageRole = .user
var message = ""
}
16 changes: 16 additions & 0 deletions Sources/QuickBloxData/DTO/AI/RemoteTranslateMessageDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// RemoteTranslateMessageDTO.swift
// QuickBloxUIKit
//
// Created by Injoit on 16.05.2024.
// Copyright © 2023 QuickBlox. All rights reserved.
//

import Foundation

public struct RemoteTranslateMessageDTO {
var id = ""
var smartChatAssistantId = ""
var message = ""
var languageCode = ""
}
5 changes: 5 additions & 0 deletions Sources/QuickBloxData/Exception/DataSourceException.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public enum DataSourceException: Error, Equatable {

/// Would be thrown when an operation is attempted on an record that does not exist in the data source.
case notFound(description:String = "")

/// Would be thrown when attempting to access and without authentication credentials to do so.
case unauthorised(description:String = "")
}

extension DataSourceException: LocalizedError {
Expand All @@ -32,6 +35,8 @@ extension DataSourceException: LocalizedError {
description = ("Already exist.", reason)
case .notFound(let reason):
description = ("Not found.", reason)
case .unauthorised(let reason):
description = ("Unauthorised.", reason)
}

return description.info + "" + description.reason
Expand Down
2 changes: 2 additions & 0 deletions Sources/QuickBloxData/Mapper/Error+RepositoryException.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ extension Error {
return RepositoryException.alreadyExist(description: info)
case .notFound(description: let info):
return RepositoryException.notFound(description: info)
case .unauthorised(description: let description):
return RepositoryException.unauthorised(description)
}
}

Expand Down
4 changes: 4 additions & 0 deletions Sources/QuickBloxData/RepositoriesFabric.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ public class RepositoriesFabric {
static public var permissions: PermissionsRepository {
PermissionsRepository(repo: Service.permissions)
}

static public var ai: AIRepository {
AIRepository(remote: Service.remote)
}
}
64 changes: 64 additions & 0 deletions Sources/QuickBloxData/Repository/AIRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// AIRepository.swift
// QuickBloxUIKit
//
// Created by Injoit on 16.05.2024.
// Copyright © 2023 QuickBlox. All rights reserved.
//

import Foundation
import QuickBloxDomain

/// This is a class that implements the ``AIRepositoryProtocol`` protocol and contains methods and properties that allow it to interact with the ``AnswerAssistMessage`` items.
public class AIRepository {
private let remote: RemoteDataSourceProtocol

public init(remote: RemoteDataSourceProtocol) {
self.remote = remote
}
}

extension AIRepository: AIRepositoryProtocol {

public func answerAssist(message entity: AnswerAssistMessage) async throws -> String {
do {
return try await remote.answerAssist(message: RemoteAnswerAssistMessageDTO(entity))
} catch {
throw try error.repositoryException
}
}

public func translate(message entity: TranslateMessage) async throws -> String {
do {
return try await remote.translate(message: RemoteTranslateMessageDTO(entity))
} catch {
throw try error.repositoryException
}
}
}

private extension RemoteAnswerAssistMessageDTO {
init(_ value: AnswerAssistMessage) {
id = value.id
smartChatAssistantId = value.smartChatAssistantId
message = value.message
history = value.history.compactMap({ RemoteAnswerAssistHistoryMessageDTO($0) })
}
}

private extension RemoteAnswerAssistHistoryMessageDTO {
init(_ value: AnswerAssistHistoryMessage) {
id = value.id
role = value.role
message = value.message
}
}

private extension RemoteTranslateMessageDTO {
init(_ value: TranslateMessage) {
id = value.id
message = value.message
smartChatAssistantId = value.smartChatAssistantId
languageCode = value.languageCode
}
}
2 changes: 1 addition & 1 deletion Sources/QuickBloxData/Repository/UsersRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ extension UsersRepository: UsersRepositoryProtocol {

public func get(usersFromRemote fullName: String) async throws -> [User] {
do {
let pagination = Pagination(skip: 0, limit: 30)
let pagination = Pagination(skip: 0, limit: 100)
let withFullName = RemoteUsersDTO(name:fullName, pagination: pagination)
let data = try await remote.get(users: withFullName)
return data.users.map { User($0) }
Expand Down
66 changes: 66 additions & 0 deletions Sources/QuickBloxData/Source/Entity/AI/AnswerAssistMessage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// AnswerAssistMessage.swift
// QuickBloxUIKit
//
// Created by Injoit on 16.05.2024.
// Copyright © 2023 QuickBlox. All rights reserved.
//

import QuickBloxDomain
import Foundation

/// Contain methods and properties that describe an Answer Assist Message.
///
/// This is an active model that conforms to the ``AnswerAssistMessageEntity`` protocol.
public struct AnswerAssistMessage: AnswerAssistMessageEntity {
public typealias AnswerAssistHistoryMessageItem = AnswerAssistHistoryMessage
public var id: String = UUID().uuidString
public var smartChatAssistantId: String
public var message: String
public var history: [AnswerAssistHistoryMessage]

public init(message: String,
history: [AnswerAssistHistoryMessage],
smartChatAssistantId: String) {
self.smartChatAssistantId = smartChatAssistantId
self.message = message
self.history = history
}
}

public extension AnswerAssistMessage {
init<T: AnswerAssistMessageEntity>(_ value: T) {
self.init(message: value.message,
history: value.history.map({ AnswerAssistHistoryMessage($0) }),
smartChatAssistantId: value.smartChatAssistantId)
}
}

/// Contain methods and properties that describe an Answer Assist History Message.
///
/// This is an active model that conforms to the ``AnswerAssistHistoryMessageEntity`` protocol.
public struct AnswerAssistHistoryMessage: AnswerAssistHistoryMessageEntity {
public var id: String = UUID().uuidString
public var role: AIMessageRole
public var message: String

public init(role: AIMessageRole,
message: String) {
self.role = role
self.message = message
}
}

public extension AnswerAssistHistoryMessage {
init<T: AnswerAssistHistoryMessageEntity>(_ value: T) {
self.init(role: value.role,
message: value.message)
}
}

public extension AnswerAssistHistoryMessage {
init<T: MessageEntity>(_ value: T) {
self.init(role: value.isOwnedByCurrentUser ? .user : .assistant,
message: value.text)
}
}
38 changes: 38 additions & 0 deletions Sources/QuickBloxData/Source/Entity/AI/TranslateMessage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// TranslateMessage.swift
// QuickBloxUIKit
//
// Created by Injoit on 16.05.2024.
// Copyright © 2023 QuickBlox. All rights reserved.
//

import Quickblox
import QuickBloxDomain
import Foundation

/// Contain methods and properties that describe a Translate Message.
///
/// This is an active model that conforms to the ``TranslateMessageEntity`` protocol.
public struct TranslateMessage: TranslateMessageEntity {
public var id: String = UUID().uuidString
public var message: String
public var smartChatAssistantId: String
public var languageCode: String

public init(message: String,
smartChatAssistantId: String,
languageCode: String) {
self.message = message
self.smartChatAssistantId = smartChatAssistantId
self.languageCode = languageCode
}
}

public extension TranslateMessage {
init(message: String,
smartChatAssistantId: String) {
self.message = message
self.smartChatAssistantId = smartChatAssistantId
self.languageCode = QBAILanguage.english.rawValue
}
}
1 change: 1 addition & 0 deletions Sources/QuickBloxData/Source/Remote/API/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ struct API {
let users = APIUsers()
let messages = APIMessages()
let files = APIFiles()
let ai = APIAI()
}
Loading