|
| 1 | +import CodableWrappers |
| 2 | +import Foundation |
| 3 | + |
| 4 | +public struct RAGChatAgentConfiguration: Codable { |
| 5 | + public struct ModelConfiguration: Codable { |
| 6 | + public var maxTokens: Int |
| 7 | + public var minimumReplyTokens: Int |
| 8 | + public var temperature: Double |
| 9 | + public var systemPrompt: String |
| 10 | + |
| 11 | + public init( |
| 12 | + maxTokens: Int, |
| 13 | + minimumReplyTokens: Int, |
| 14 | + temperature: Double, |
| 15 | + systemPrompt: String |
| 16 | + ) { |
| 17 | + self.maxTokens = maxTokens |
| 18 | + self.minimumReplyTokens = minimumReplyTokens |
| 19 | + self.temperature = temperature |
| 20 | + self.systemPrompt = systemPrompt |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + public struct ConversationConfiguration: Codable { |
| 25 | + public var maxTurns: Int |
| 26 | + public var isConversationIsolated: Bool |
| 27 | + public var respondInLanguage: String |
| 28 | + |
| 29 | + public init(maxTurns: Int, isConversationIsolated: Bool, respondInLanguage: String) { |
| 30 | + self.maxTurns = maxTurns |
| 31 | + self.isConversationIsolated = isConversationIsolated |
| 32 | + self.respondInLanguage = respondInLanguage |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + public enum ServiceProvider: Codable { |
| 37 | + case chatModel(id: String) |
| 38 | + case extensionService(id: String) |
| 39 | + } |
| 40 | + |
| 41 | + public var id: String |
| 42 | + public var name: String |
| 43 | + public var serviceProvider: ServiceProvider |
| 44 | + @FallbackDecoding<EmptySet> |
| 45 | + public var capabilityIds: Set<String> |
| 46 | + |
| 47 | + public var modelConfiguration: ModelConfiguration |
| 48 | + public var conversationConfiguration: ConversationConfiguration |
| 49 | + var _otherConfigurations: Data |
| 50 | + |
| 51 | + public init<OtherConfiguration: Codable>( |
| 52 | + id: String, |
| 53 | + name: String, |
| 54 | + serviceProvider: ServiceProvider, |
| 55 | + capabilityIds: Set<String>, |
| 56 | + modelConfiguration: ModelConfiguration, |
| 57 | + conversationConfiguration: ConversationConfiguration, |
| 58 | + otherConfigurations: OtherConfiguration |
| 59 | + ) throws { |
| 60 | + self.id = id |
| 61 | + self.name = name |
| 62 | + self.serviceProvider = serviceProvider |
| 63 | + self.capabilityIds = capabilityIds |
| 64 | + self.modelConfiguration = modelConfiguration |
| 65 | + self.conversationConfiguration = conversationConfiguration |
| 66 | + _otherConfigurations = try JSONEncoder().encode(otherConfigurations) |
| 67 | + } |
| 68 | + |
| 69 | + public func otherConfigurations<Configuration: Codable>( |
| 70 | + as: Configuration.Type = Configuration.self |
| 71 | + ) throws -> Configuration { |
| 72 | + try JSONDecoder().decode(Configuration.self, from: _otherConfigurations) |
| 73 | + } |
| 74 | + |
| 75 | + public mutating func setOtherConfigurations<Configuration: Codable>( |
| 76 | + _ otherConfigurations: Configuration |
| 77 | + ) throws { |
| 78 | + _otherConfigurations = try JSONEncoder().encode(otherConfigurations) |
| 79 | + } |
| 80 | +} |
| 81 | + |
0 commit comments